@Override @Nullable public String getShortClassName() { final SourcePosition pos = getSourcePosition(); if (pos != null) { if (pos.getFile() instanceof JspFile) { return getClassName(); } } return super.getShortClassName(); }
@Nullable public Document getDocument() { final RangeHighlighter highlighter = getHighlighter(); if (highlighter != null) { return highlighter.getDocument(); } final SourcePosition position = getSourcePosition(); if (position != null) { final PsiFile file = position.getFile(); return PsiDocumentManager.getInstance(getProject()).getDocument(file); } return null; }
public int compare(Declaration d1, Declaration d2) { if (equals(d1, d2)) return 0; SourcePosition p1 = d1.getPosition(); SourcePosition p2 = d2.getPosition(); if (p1 == null && p2 != null) return 1; else if (p1 != null && p2 == null) return -1; else if (p1 == null && p2 == null) return compareEqualPosition(d1, d2); else { assert p1 != null && p2 != null; int fileComp = p1.file().compareTo(p2.file()); if (fileComp == 0) { long diff = (long) p1.line() - (long) p2.line(); if (diff == 0) { diff = Long.signum((long) p1.column() - (long) p2.column()); if (diff != 0) return (int) diff; else { // declarations may be two // compiler-generated members with the // same source position return compareEqualPosition(d1, d2); } } else return (diff < 0) ? -1 : 1; } else return fileComp; } }
/** * Get the column number within the line of source referred to by this diagnostic. * * @return the column number within the line of source referred to by this diagnostic */ @DefinedBy(Api.COMPILER) public long getColumnNumber() { if (sourcePosition == null) { sourcePosition = new SourcePosition(); } return sourcePosition.getColumnNumber(); }
public CommentBlock[] parse(File file) throws IOException { Vector<CommentBlock> comments = new Vector<CommentBlock>(); boolean inComment = false; BufferedReader in = null; String line = null; StringBuffer buffer = null; int lineNum = 1; SourcePosition pos = new SourcePosition(file.getAbsolutePath(), 0); try { in = new BufferedReader(new FileReader(file.getAbsolutePath())); while ((line = in.readLine()) != null) { line = line.trim(); // Detect doc comment start if (line.startsWith("/**") && !inComment) { inComment = true; buffer = new StringBuffer(); pos.setLineNumber(lineNum); } // Process inside comment if (inComment) { if (buffer.length() > 0) buffer.append('\n'); buffer.append(line); } // Detect doc comment end if (inComment && line.endsWith("*/")) { comments.add(new CommentBlock(buffer.toString(), pos)); inComment = false; } lineNum++; } } finally { if (in != null) in.close(); } // Add tags CommentBlock commentsArray[] = new CommentBlock[comments.size()]; comments.toArray(commentsArray); return commentsArray; }
public boolean canMoveTo(@Nullable final SourcePosition position) { if (position == null || !position.getFile().isValid()) { return false; } final PsiFile psiFile = position.getFile(); final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(psiFile); if (document == null) { return false; } final int spOffset = position.getOffset(); if (spOffset < 0) { return false; } final BreakpointManager breakpointManager = DebuggerManagerEx.getInstanceEx(getProject()).getBreakpointManager(); return breakpointManager.findBreakpoint(document, spOffset, getCategory()) == null; }
@Override public void reload() { ApplicationManager.getApplication().assertReadAccessAllowed(); XSourcePosition position = myXBreakpoint.getSourcePosition(); PsiFile psiFile = getPsiFile(); if (position != null && psiFile != null) { mySourcePosition = SourcePosition.createFromLine(psiFile, position.getLine()); reload(psiFile); } else { mySourcePosition = null; } }
@Override public void reload() { ApplicationManager.getApplication().assertReadAccessAllowed(); final XSourcePosition position = myXBreakpoint.getSourcePosition(); try { final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(position.getFile()); mySourcePosition = SourcePosition.createFromOffset(psiFile, position.getOffset()); } catch (Exception e) { mySourcePosition = null; } reload(BreakpointManager.getPsiFile(myXBreakpoint, myProject)); }
/** * Print warning message, increment warning count. Part of DocErrorReporter. * * @param pos the position where the error occurs * @param msg message to print */ public void printWarning(SourcePosition pos, String msg) { if (diagListener != null) { report(DiagnosticType.WARNING, pos, msg); return; } if (nwarnings < MaxWarnings) { String prefix = (pos == null) ? programName : pos.toString(); warnWriter.println(prefix + ": " + getText("javadoc.warning") + " - " + msg); warnWriter.flush(); nwarnings++; } }
public boolean moveTo(@NotNull SourcePosition position) { if (!canMoveTo(position)) { return false; } final PsiFile psiFile = position.getFile(); final PsiFile oldFile = getSourcePosition().getFile(); final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(psiFile); final Document oldDocument = PsiDocumentManager.getInstance(getProject()).getDocument(oldFile); if (document == null || oldDocument == null) { return false; } final RangeHighlighter newHighlighter = createHighlighter(myProject, document, position.getLine()); if (newHighlighter == null) { return false; } final RangeHighlighter oldHighlighter = myHighlighter; myHighlighter = newHighlighter; reload(); if (!isValid()) { myHighlighter.dispose(); myHighlighter = oldHighlighter; reload(); return false; } if (oldHighlighter != null) { oldHighlighter.dispose(); } DebuggerManagerEx.getInstanceEx(getProject()) .getBreakpointManager() .fireBreakpointChanged(this); updateUI(); return true; }
/** * Convert the given Class to an HTML. * * @param cd the class to convert. * @param outputdir the name of the directory to output to. */ public void convertClass(ClassDoc cd, DocPath outputdir) { if (cd == null) { return; } try { SourcePosition sp = cd.position(); if (sp == null) return; Reader r; // temp hack until we can update SourcePosition API. if (sp instanceof SourcePositionImpl) { FileObject fo = ((SourcePositionImpl) sp).fileObject(); if (fo == null) return; r = fo.openReader(true); } else { File file = sp.file(); if (file == null) return; r = new FileReader(file); } int lineno = 1; String line; relativePath = DocPaths.SOURCE_OUTPUT.resolve(DocPath.forPackage(cd)).invert(); Content body = getHeader(); Content pre = new HtmlTree(HtmlTag.PRE); try (LineNumberReader reader = new LineNumberReader(r)) { while ((line = reader.readLine()) != null) { addLineNo(pre, lineno); addLine(pre, line, lineno); lineno++; } } addBlankLines(pre); Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre); body.addContent((configuration.allowTag(HtmlTag.MAIN)) ? HtmlTree.MAIN(div) : div); writeToFile(body, outputdir.resolve(DocPath.forClass(cd))); } catch (IOException e) { e.printStackTrace(); } }
/** * Print error message, increment error count. Part of DocErrorReporter. * * @param pos the position where the error occurs * @param msg message to print */ public void printError(SourcePosition pos, String msg) { if (diagListener != null) { report(DiagnosticType.ERROR, pos, msg); return; } if (nerrors < MaxErrors) { String prefix = (pos == null) ? programName : pos.toString(); errWriter.println(prefix + ": " + getText("javadoc.error") + " - " + msg); errWriter.flush(); prompt(); nerrors++; } }
/** Adds a name declaration to the current marker. */ public void markName(String name, StaticSourceFile file, int lineno, int charno) { if (currentMarker != null) { // Record the name as both a SourcePosition<String> and a // SourcePosition<Node>. The <String> form is deprecated, // because <Node> is more consistent with how other name // references are handled (see #markTypeNode) // // TODO(nicksantos): Remove all uses of the Name position // and replace them with the NameNode position. JSDocInfo.TrimmedStringPosition position = new JSDocInfo.TrimmedStringPosition(); position.setItem(name); position.setPositionInformation(lineno, charno, lineno, charno + name.length()); currentMarker.setName(position); SourcePosition<Node> nodePos = new JSDocInfo.NamePosition(); Node node = Node.newString(Token.NAME, name, lineno, charno); node.setLength(name.length()); node.setStaticSourceFile(file); nodePos.setItem(node); nodePos.setPositionInformation(lineno, charno, lineno, charno + name.length()); currentMarker.setNameNode(nodePos); } }
/** This is a simple format: sql: <the sql> error | warn: <the message> */ private void logError(String sql, SourcePosition sp, String message, boolean error) { if (error) { globalCounters.increment(GlobalCounters.ERRORS); } else { globalCounters.increment(GlobalCounters.WARNINGS); } try { final String type = error ? "error" : "warn"; final String line = "(line=" + sp.getPosition() + ")"; errorLog.write("---- " + type + " " + line + " ---------------"); errorLog.newLine(); errorLog.write("msg: " + message); errorLog.newLine(); errorLog.write("sql: " + sql); errorLog.newLine(); } catch (final Throwable ct) { logger.error("Unable to write error log record", ct); } }
public int getLineIndex() { final SourcePosition sourcePosition = getSourcePosition(); return sourcePosition != null ? sourcePosition.getLine() : -1; }
@Override public void onNotice(String sql, SourcePosition sp, String message) { logger.warn(message + " [" + sp.getLineInfo().toString() + "]: " + sql); }