private long countLines(CsmFile fileImpl, boolean allowResolvedIncludes) { if (fileImpl == null) { return -1; } if (!allowResolvedIncludes && hasNonEmptyIncludes(fileImpl)) { //! fileImpl.getIncludes().isEmpty() ) { return -1; } CharSequence text = fileImpl.getText(); long cnt = 0; for (int pos = 0; pos < text.length(); pos++) { if (text.charAt(pos) == '\n') { cnt++; } } return cnt; }
protected Collection<CsmErrorInfo> toErrorInfo(Collection<CsmParserProvider.ParserError> errors, CsmFile file) { Collection<CsmErrorInfo> result = new ArrayList<>(); if (!errors.isEmpty()){ CharSequence text = file.getText(); CsmParserProvider.ParserError prev = null; ContextCache prevLine = new ContextCache(); for (CsmParserProvider.ParserError e : errors) { // Fix for IZ#143082: some syntax errors are reported twice. // We assume that equal recognition exceptions are next to each other. if (!equal(prev, e)) { result.add(toErrorInfo(e, text, prevLine)); } prev = e; } } return result; }
@Override public CharSequence getText() { CsmFile containingFile = getContainingFile(); if (containingFile != null) { return containingFile.getText(getStartOffset(), getEndOffset()); } else { return ""; // NOI18N } }
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; }
Position endPosition = offsetable.getEndPosition(); if (startPosition.getOffset() >= 0 && endPosition.getOffset() >= 0 && startPosition.getOffset() <= endPosition.getOffset() && offsetable.getContainingFile() != null && endPosition.getOffset() < offsetable.getContainingFile().getText().length()) { line = " [" + startPosition.getLine() + ":" + startPosition.getColumn() + "-" + // NOI18N endPosition.getLine() + ":" + endPosition.getColumn() + "]"; // NOI18N
return; TokenHierarchy<?> h = TokenHierarchy.create(containingFile.getText(), CppTokenId.languageHeader()); TokenSequence<CppTokenId> ts = h.tokenSequence(CppTokenId.languageHeader());