@Override public boolean hasDeclarations(CsmFile file) { if (file instanceof FileImpl) { return ((FileImpl)file).hasDeclarations(); } return file.getDeclarations().isEmpty(); }
@Override public Iterator<CsmOffsetableDeclaration> getDeclarations(CsmFile file, CsmFilter filter) { if (file instanceof FileImpl){ return analyzeFileFilter((FileImpl)file,filter); } return file.getDeclarations().iterator(); }
public static CsmScope findInnerFileScope(CsmFile file, int offset) { CsmScope innerScope = null; for (Iterator<CsmOffsetableDeclaration> it = file.getDeclarations().iterator(); it.hasNext();) { CsmOffsetableDeclaration decl = it.next(); if (CsmKindUtilities.isScope(decl) && isInObject(decl, offset)) { innerScope = findInnerScope((CsmScope)decl, offset); innerScope = innerScope != null ? innerScope : (CsmScope)decl; break; } } return innerScope; }
private static CsmOffsetableDeclaration findInnerFileDeclaration(CsmFile file, int offset) { CsmOffsetableDeclaration innerDecl = null; for (CsmOffsetableDeclaration decl : file.getDeclarations()) { if (isInObject(decl, offset)) { innerDecl = findInnerDeclaration(decl, offset); innerDecl = innerDecl != null ? innerDecl : decl; break; } } return innerDecl; }
/*package*/ void computeAnnotations(Collection<BaseAnnotation> toAdd) { if (canceled.get()) { return; } CsmCacheManager.enter(); try { computeAnnotations(csmFile.getDeclarations(), toAdd); } finally { CsmCacheManager.leave(); } }
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 void getFunction(List<CsmObject> list, CsmFile file, int position) { if (file != null) { for(CsmOffsetableDeclaration decl : file.getDeclarations()) { if (decl.getStartOffset() <= position && position <= decl.getEndOffset()) { list.add(decl); getInternalDeclaration(list, decl, position); return; } } } }
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; } }
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 static List<KindAndSignature> createFileSignature(CsmFile csmFile) { Collection<FileElement> fileElements = new TreeSet<>(PAIR_COMPARATOR); for (CsmInclude element : csmFile.getIncludes()) { // TODO: what about system vs user, shouldn't it be part of Utils.getCsmIncludeKindKey? CharAndCharSequence cs = new CharAndCharSequence(element.getIncludeName(), Utils.getCsmIncludeKindKey()); FileElement fe = new FileElement(element.getStartOffset(), cs); fileElements.add(fe); } for (CsmMacro element : csmFile.getMacros()) { MacroCharSequence cs = new MacroCharSequence(element.getName(), element.getBody(), Utils.getCsmDeclarationKindkey(CsmDeclaration.Kind.MACRO)); FileElement fe = new FileElement(element.getStartOffset(), cs); fileElements.add(fe); } for (CsmOffsetableDeclaration element : csmFile.getDeclarations()) { addDeclarationAndNested(fileElements, element); } ArrayList<KindAndSignature> out = new ArrayList<>(fileElements.size()); for (FileElement fe : fileElements) { out.add(fe.signature); } out.trimToSize(); return out; }
private static long analyzeFile(final CsmFile file, final StatisticsParameters params, final XRefResultSet<XRefEntry> bag, final PrintWriter out, final OutputWriter printErr, final AtomicBoolean canceled) { long time = System.currentTimeMillis(); if (params.analyzeSmartAlgorith) { // for smart algorithm visit functions visitDeclarations(file.getDeclarations(), params, bag, out, printErr, canceled); } else if (params.reportIndex) { // otherwise visit active code in whole file CsmFileReferences.getDefault().accept(file, null, new LWReportIndexVisitor(bag, printErr, canceled, params.reportIndex), params.interestedReferences); } else { // otherwise visit active code in whole file CsmFileReferences.getDefault().accept(file, null, new LWCheckReferenceVisitor(bag, printErr, canceled, params.reportUnresolved), params.interestedReferences); } time = System.currentTimeMillis() - time; // get line num CharSequence text = file.getText(); int lineCount = 1; for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '\n') { lineCount++; } } bag.incrementLineCounter(lineCount); if (params.printFileStatistic) { out.println(file.getAbsolutePath() + " has " + lineCount + " lines; took " + time + "ms"); // NOI18N } return time; }
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; }
public CsmOffsetableDeclaration getFunction(CsmFile file, int position) { if (file != null) { CsmOffsetableDeclaration best = null; for(CsmOffsetableDeclaration decl : file.getDeclarations()) { if (decl.getStartOffset() <= position && position <= decl.getEndOffset()) { return getInternalDeclaration(decl, position); } else if (decl.getStartOffset() > position - GAP) { if (best == null || best.getStartOffset() > decl.getStartOffset()){ best = decl; } } } return best; } return null; }
CsmFile csmFile = CsmUtilities.getCsmFile(doc, true, false); if (csmFile != null) { CsmClass cls = visitDeclarations(csmFile.getDeclarations(), caretOffset); if (cls != null) { Set<CsmMethod> virtual = new HashSet<CsmMethod>();
if (csmFile != null) { Set<CsmClass> classes = new HashSet<CsmClass>(); visitDeclarations(classes, csmFile.getDeclarations(), caretOffset); if (isApplicable) { visitClasses(classes, bestInterface.getDeclarations(), caretOffset);
return; StatementResult res = findExpressionStatement(file.getDeclarations(), selectionStart, selectionEnd, doc, canceled); if (res == null) { return;