protected final CsmProject getProject() { CsmFile file = this.getContainingFile(); assert file != null; return file != null ? file.getProject() : null; }
@Override public String toString() { return "NameResolveCacheKey{" + "name=" + fullName + // NOI18N ", origOffset=" + origOffset + // NOI18N ", startFile=" + startFile.getAbsolutePath() + // NOI18N ", file=" + file.getAbsolutePath() + // NOI18N ", interestedKind=" + interestedKind + // NOI18N ", hashCode=" + hashCode + '}';// NOI18N }
private OffsetsObjects getFileOffsets(){ synchronized(lock) { if (offsets == null) { offsets = new OffsetsObjects(new ArrayList<Offsets>(), new ArrayList<Offsets>()); for(CsmOffsetableDeclaration declaration : csmFile.getDeclarations()){ offsets.fileDeclarationsOffsets.add(new Offsets(declaration)); } for(CsmInclude declaration : csmFile.getIncludes()){ offsets.fileObjectOffsets.add(new Offsets(declaration)); } for(CsmMacro declaration : csmFile.getMacros()){ offsets.fileObjectOffsets.add(new Offsets(declaration)); } Collections.sort(offsets.fileObjectOffsets); Collections.sort(offsets.fileDeclarationsOffsets); } return offsets; } }
@Override public String getShortDescription() { if (object.isValid()) { return object.getAbsolutePath().toString(); } return super.getShortDescription(); }
@Override public String getLanguage() { return Utils.getLanguage(file.getFileType(), file.getAbsolutePath().toString()); }
@Override public int compare(CsmFile o1, CsmFile o2) { CsmProject prj1 = o1.getProject(); CsmProject prj2 = o2.getProject(); if (prj1 == null || prj2 == null || prj1.equals(prj2)) { return CharSequences.comparator().compare(o1.getName(), o2.getName()); } else { return CharSequences.comparator().compare(prj1.getName(), prj2.getName()); } } });
@Override public String getIncludeDirective(CsmFile currentFile, CsmObject item) { if (CsmKindUtilities.isOffsetable(item)) { CsmFile file = ((CsmOffsetable) item).getContainingFile(); if (file != null) { if (file.equals(currentFile) || file.isHeaderFile()) { return getIncludeDirectiveByFile(currentFile, item).replace('\\', '/'); // NOI18N; } else if (file.isSourceFile() && CsmKindUtilities.isGlobalVariable(item)) { Collection<CsmOffsetableDeclaration> decls = file.getProject().findDeclarations(((CsmVariable) item).getUniqueName() + " (EXTERN)"); // NOI18N if (!decls.isEmpty()) { return getIncludeDirectiveByFile(currentFile, decls.iterator().next()).replace('\\', '/'); // NOI18N; } } } else { System.err.println("can not find for item " + item); // NOI18N; } } else if (!CsmKindUtilities.isNamespace(item)) { System.err.println("not yet handled object " + item); // NOI18N; } return ""; // NOI18N }
private Map<String,List<FileObject>> search(CsmOffsetable ppDirective){ CsmProject prj = ppDirective.getContainingFile().getProject(); HashSet<FileObject> set = new HashSet<FileObject>(); for (Iterator<CsmFile> it = prj.getSourceFiles().iterator(); it.hasNext();){ CsmFile file = it.next(); FileObject fo = file.getFileObject(); if (fo != null && fo.isValid()) { FileObject aParent = fo.getParent(); FileObject fo = file.getFileObject(); if (fo != null && fo.isValid()) { FileObject aParent = fo.getParent();
public static FileObject getFileObject(CsmFile csmFile) { return (csmFile == null) ? null : csmFile.getFileObject(); // FileObject fo = null; // if (csmFile != null) { // // try { // try { // fo = CndFileUtils.toFileObject(csmFile.getAbsolutePath()); // if (fo == null /*paranoia*/ || !fo.isValid()) { // File file = new File(csmFile.getAbsolutePath().toString()); // XXX:FileObject conversion // fo = CndFileUtils.toFileObject(file.getCanonicalFile()); // } // } catch (IOException e) { // fo = CndFileUtils.toFileObject(CndFileUtils.normalizeAbsolutePath(csmFile.getAbsolutePath().toString())); // } // } catch (IllegalArgumentException ex) { // ex.printStackTrace(System.err); // } // } // return fo; }
private void removeFunctionDeclaration(final CsmOffsetableDeclaration decl) { CsmFunction fun = (CsmFunction)decl; CsmFile file = fun.getContainingFile(); if (file != null && file.isValid()){ CsmOffsetableDeclaration other = (CsmOffsetableDeclaration) file.getProject().findDeclaration(fun.getUniqueName()); if (other != null) { PersistentKey otherKey = PersistentKey.createKey(other); if (!myKeys.containsKey(otherKey)) { myKeys.put(otherKey,getSortedName(other)); myChanges.remove(otherKey); return; } } } CsmFunctionDefinition def = fun.getDefinition(); if (def != null && def != decl){ file = fun.getContainingFile(); if (file != null && file.isValid() && file.getProject().findDeclaration(def.getUniqueName()) != null){ PersistentKey defKey = PersistentKey.createKey(def); if (!myKeys.containsKey(defKey)) { myKeys.put(defKey,getSortedName(def)); myChanges.remove(defKey); } } } }
@Override public Collection<CsmReference> getIncludes(CsmFile referencedFile) { CsmProject project = referencedFile.getProject(); if (project instanceof ProjectBase) { List<CsmReference> res = new ArrayList<>(); for (CsmFile file : getReferences((ProjectBase)project, referencedFile)){ for (CsmInclude include : file.getIncludes()){ if (referencedFile.equals(include.getIncludeFile())){ res.add(CsmReferenceSupport.createObjectReference(include.getIncludeFile(), include)); } } } return res; } return Collections.<CsmReference>emptyList(); }
@Override public Iterator<CsmOffsetableDeclaration> getDeclarations(CsmFile file, CsmFilter filter) { if (file instanceof FileImpl){ return analyzeFileFilter((FileImpl)file,filter); } return file.getDeclarations().iterator(); }
private Map<String, Set<SourceFileInfo>> initStaticFunctions(CsmProject project){ Map<String, Set<SourceFileInfo>> res = new HashMap<String, Set<SourceFileInfo>>(); for(CsmFile file : project.getAllFiles()){ for(CsmOffsetableDeclaration decl : file.getDeclarations()) { if (CsmKindUtilities.isFileLocalFunction(decl)) { CsmFunction func = (CsmFunction) decl; String name = func.getQualifiedName().toString(); Set<SourceFileInfo> set = res.get(name); if (set == null) { set = new HashSet<SourceFileInfo>(); res.put(name, set); } set.add(new SourceFileInfo(file.getAbsolutePath().toString(), func.getStartPosition().getOffset())); } } } return res; } }
private String getLocalIncludeDerectiveByHeaderFilePath(FSPath path, CsmObject item) { CsmFile incFile = ((CsmOffsetable) item).getContainingFile(); if(incFile.isHeaderFile()) { String incFilePath = incFile.getAbsolutePath().toString(); StringBuilder includeDirective = new StringBuilder("#include "); // NOI18N includeDirective.append("\""); // NOI18N String projectPath = path.getPath(); if (!incFilePath.startsWith(projectPath)) { projectPath = ""; // NOI18N } includeDirective.append(CndPathUtilities.toRelativePath(projectPath, incFilePath)); if (!projectPath.equals("")) // NOI18N { includeDirective.append("\""); // NOI18N return includeDirective.toString(); } } return ""; }
for (CsmFile file : sourceFiles) { if (printList) { printOut.printf("\t%s\n", file.getAbsolutePath()); // NOI18N FileObject fo = file.getFileObject(); if (fo != null && fo.isValid()) { totalSize += fo.getSize(); printOut.printf("\t%s\n", file.getAbsolutePath()); // NOI18N FileObject fo = file.getFileObject(); if (fo != null && fo.isValid()) { totalSize += fo.getSize();
@Override public Iterator<CsmInclude> getIncludes(CsmFile file, CsmFilter filter) { if (file instanceof FileImpl){ return ((FileImpl)file).getIncludes(filter); } return file.getIncludes().iterator(); }
private static CsmInclude findFirstLevelInclude(CsmFile startFile, CsmFile searchFile) { assert startFile != null : "start file must be not null"; assert searchFile != null : "search file must be not null"; for (CsmInclude incl : startFile.getIncludes()) { CsmFile included = incl.getIncludeFile(); if (searchFile.equals(included)) { return incl; } else if (included != null && included.getDeclarations().isEmpty()) { // this is a fake include only file return findFirstLevelInclude(included, searchFile); } } return null; }
private CsmFunction getFunction() { if (!project.isValid()) { return null; } CsmFunction root = (CsmFunction) project.findDeclaration(functionUin); if (root != null) { return root; } CsmFile file = fileUid.getObject(); if (!file.isValid()) { return null; } for (CsmDeclaration d : file.getDeclarations()) { root = findFunction(d); if (root != null){ return root; } } return null; }
final CsmFile csmFile = CsmUtilities.getCsmFile(doc, false, false); long start = System.currentTimeMillis(); if (csmFile != null && csmFile.isParsed()) { if (LOG.isLoggable(Level.FINER)) { LOG.log(Level.FINER, "Semantic Highlighting update() have started for file {0}", csmFile.getAbsolutePath()); LOG.log(Level.FINER, "Semantic Highlighting update() done in {0}ms for file {1}", new Object[]{System.currentTimeMillis() - start, csmFile.getAbsolutePath()});