Java Code Examples for org.netbeans.api.java.source.CompilationInfo#getDocument()
The following examples show how to use
org.netbeans.api.java.source.CompilationInfo#getDocument() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DiffContext.java From netbeans with Apache License 2.0 | 6 votes |
public static final CodeStyle getCodeStyle(CompilationInfo info) { if (info != null) { try { Document doc = info.getDocument(); if (doc != null) { CodeStyle cs = (CodeStyle)doc.getProperty(CodeStyle.class); return cs != null ? cs : CodeStyle.getDefault(doc); } } catch (IOException ioe) { // ignore } FileObject file = info.getFileObject(); if (file != null) { return CodeStyle.getDefault(file); } } return CodeStyle.getDefault((Document)null); }
Example 2
Source File: GeneratorUtils.java From netbeans with Apache License 2.0 | 6 votes |
private static CodeStyle getCodeStyle(CompilationInfo info) { if (info != null) { try { Document doc = info.getDocument(); if (doc != null) { CodeStyle cs = (CodeStyle)doc.getProperty(CodeStyle.class); return cs != null ? cs : CodeStyle.getDefault(doc); } } catch (IOException ioe) { // ignore } FileObject file = info.getFileObject(); if (file != null) { return CodeStyle.getDefault(file); } } return CodeStyle.getDefault((Document)null); }
Example 3
Source File: Utilities.java From netbeans with Apache License 2.0 | 6 votes |
public static boolean isMethodHeaderInsideGuardedBlock(CompilationInfo info, MethodTree method) { try { Document doc = info.getDocument(); if (doc instanceof GuardedDocument) { GuardedDocument bdoc = (GuardedDocument) doc; int methodStart = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), method); int methodEnd = (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), method); return (bdoc.getGuardedBlockChain().compareBlock(methodStart, methodEnd) & MarkBlock.OVERLAP) != 0; } return false; } catch (IOException ex) { Exceptions.printStackTrace(ex); return false; } }
Example 4
Source File: JavaSemanticTokenList.java From netbeans with Apache License 2.0 | 6 votes |
public void run(CompilationInfo parameter) throws Exception { JavaSemanticTokenList l = get(parameter.getFileObject()); if (l == null) { return ; } Document doc = parameter.getDocument(); if (doc == null) { return ; } ScannerImpl si = new ScannerImpl(doc, parameter); List<Position[]> pos = new ArrayList<Position[]>(); si.scan(parameter.getCompilationUnit(), pos); l.set(pos, parameter.getDocument()); }
Example 5
Source File: GeneratorUtils.java From netbeans with Apache License 2.0 | 6 votes |
private static CodeStyle getCodeStyle(CompilationInfo info) { if (info != null) { try { Document doc = info.getDocument(); if (doc != null) { CodeStyle cs = (CodeStyle)doc.getProperty(CodeStyle.class); return cs != null ? cs : CodeStyle.getDefault(doc); } } catch (IOException ioe) { // ignore } FileObject file = info.getFileObject(); if (file != null) { return CodeStyle.getDefault(file); } } return CodeStyle.getDefault((Document)null); }
Example 6
Source File: HintsInvoker.java From netbeans with Apache License 2.0 | 5 votes |
static boolean isInGuarded(CompilationInfo info, TreePath tree) { if (info == null) { return false; } try { Document doc = info.getDocument(); if (doc instanceof GuardedDocument) { final int start = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), tree.getLeaf()); final int end = (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), tree.getLeaf()); final GuardedDocument gdoc = (GuardedDocument) doc; final boolean[] ret = { false }; gdoc.render(new Runnable() { @Override public void run() { // MarkBlockChain should only be accessed under doc's readlock to guarantee a stability of the offsets. MarkBlockChain guardedBlockChain = gdoc.getGuardedBlockChain(); if (guardedBlockChain.compareBlock(start, end) == MarkBlock.INNER) { ret[0] = true; } } }); return ret[0]; } } catch (IOException ex) { Exceptions.printStackTrace(ex); } return false; }
Example 7
Source File: JavadocCompletionQuery.java From netbeans with Apache License 2.0 | 5 votes |
private boolean resolveContext(CompilationInfo javac, JavadocContext jdctx) throws IOException { jdctx.doc = javac.getDocument(); // find class context: class, method, ... DocTrees trees = javac.getDocTrees(); TreePath javadocFor = JavadocCompletionUtils.findJavadoc(javac, this.caretOffset); if (javadocFor == null) { return false; } jdctx.javadocFor = javadocFor; DocCommentTree docCommentTree = trees.getDocCommentTree(javadocFor); if (docCommentTree == null) { return false; } jdctx.comment = docCommentTree; Element elm = trees.getElement(javadocFor); if (elm == null) { return false; } jdctx.handle = ElementHandle.create(elm); jdctx.commentFor = elm; jdctx.jdts = JavadocCompletionUtils.findJavadocTokenSequence(javac, this.caretOffset); if (jdctx.jdts == null) { return false; } jdctx.positions = (DocSourcePositions) trees.getSourcePositions(); return jdctx.positions != null; }
Example 8
Source File: JavadocHint.java From netbeans with Apache License 2.0 | 5 votes |
@Hint(id = "error-in-javadoc", category = "JavaDoc", description = "#DESC_ERROR_IN_JAVADOC_HINT", displayName = "#DN_ERROR_IN_JAVADOC_HINT", hintKind = Hint.Kind.INSPECTION, severity = Severity.WARNING, customizerProvider = JavadocHint.CustomizerProviderImplError.class) @TriggerTreeKind({Kind.METHOD, Kind.ANNOTATION_TYPE, Kind.CLASS, Kind.ENUM, Kind.INTERFACE, Kind.VARIABLE}) public static List<ErrorDescription> errorHint(final HintContext ctx) { Preferences pref = ctx.getPreferences(); boolean correctJavadocForNonPublic = pref.getBoolean(AVAILABILITY_KEY + false, false); CompilationInfo javac = ctx.getInfo(); Boolean publiclyAccessible = AccessibilityQuery.isPubliclyAccessible(javac.getFileObject().getParent()); boolean isPubliclyA11e = publiclyAccessible == null ? true : publiclyAccessible; if (!isPubliclyA11e && !correctJavadocForNonPublic) { return null; } if (javac.getElements().getTypeElement("java.lang.Object") == null) { // NOI18N // broken java platform return Collections.<ErrorDescription>emptyList(); } TreePath path = ctx.getPath(); { Document doc = null; try { doc = javac.getDocument(); } catch (IOException e) { Exceptions.printStackTrace(e); } if (doc != null && isGuarded(path.getLeaf(), javac, doc)) { return null; } } Access access = Access.resolve(pref.get(SCOPE_KEY, SCOPE_DEFAULT)); Analyzer a = new Analyzer(javac, path, access, ctx); return a.analyze(); }
Example 9
Source File: CreateElementUtilities.java From netbeans with Apache License 2.0 | 4 votes |
private static List<? extends TypeMirror> computeMethod(Set<ElementKind> types, CompilationInfo info, TreePath parent, TypeMirror[] typeParameterBound, Tree error, int offset) { //class or field: //check the error is in the body: //#92419: check for abstract method/method without body: MethodTree mt = (MethodTree) parent.getLeaf(); if (mt.getReturnType() == error) { types.add(ElementKind.CLASS); types.add(ElementKind.INTERFACE); types.add(ElementKind.ENUM); } List<? extends ExpressionTree> throwList = mt.getThrows(); if (throwList != null && !throwList.isEmpty()) { for (ExpressionTree t : throwList) { if (t == error) { types.add(ElementKind.CLASS); typeParameterBound[0] = info.getElements().getTypeElement("java.lang.Exception").asType(); break; } } } if (mt.getBody() == null) { return null; } try { Document doc = info.getDocument(); if (doc != null) {//XXX int bodyStart = findBodyStart(parent.getLeaf(), info.getCompilationUnit(), info.getTrees().getSourcePositions(), doc); int bodyEnd = (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), parent.getLeaf()); types.add(ElementKind.PARAMETER); types.add(ElementKind.LOCAL_VARIABLE); types.add(ElementKind.FIELD); if (bodyStart <= offset && offset <= bodyEnd) return Collections.singletonList(info.getElements().getTypeElement("java.lang.Object").asType()); } } catch (IOException ex) { Logger.getLogger("global").log(Level.INFO, ex.getMessage(), ex); } return null; }
Example 10
Source File: CreateElementUtilities.java From netbeans with Apache License 2.0 | 4 votes |
private static List<? extends TypeMirror> computeMethod(Set<ElementKind> types, CompilationInfo info, TreePath parent, TypeMirror[] typeParameterBound, Tree error, int offset) { //class or field: //check the error is in the body: //#92419: check for abstract method/method without body: MethodTree mt = (MethodTree) parent.getLeaf(); if (mt.getReturnType() == error) { types.add(ElementKind.CLASS); types.add(ElementKind.INTERFACE); types.add(ElementKind.ENUM); } List<? extends ExpressionTree> throwList = mt.getThrows(); if (throwList != null && !throwList.isEmpty()) { for (ExpressionTree t : throwList) { if (t == error) { types.add(ElementKind.CLASS); TypeElement tel = info.getElements().getTypeElement("java.lang.Exception"); if (tel == null) { return null; } typeParameterBound[0] = tel.asType(); break; } } } if (mt.getBody() == null) { return null; } try { Document doc = info.getDocument(); if (doc != null) {//XXX int bodyStart = Utilities.findBodyStart(info, parent.getLeaf(), info.getCompilationUnit(), info.getTrees().getSourcePositions(), doc); int bodyEnd = (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), parent.getLeaf()); types.add(ElementKind.PARAMETER); types.add(ElementKind.LOCAL_VARIABLE); types.add(ElementKind.FIELD); if (bodyStart <= offset && offset <= bodyEnd) { return typeMirrorCollection(info, "java.lang.Object"); } } } catch (IOException ex) { Logger.getLogger("global").log(Level.INFO, ex.getMessage(), ex); } return null; }