当前位置: 首页>>代码示例>>Java>>正文


Java CompilationInfo.getDocument方法代码示例

本文整理汇总了Java中org.netbeans.api.java.source.CompilationInfo.getDocument方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationInfo.getDocument方法的具体用法?Java CompilationInfo.getDocument怎么用?Java CompilationInfo.getDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.netbeans.api.java.source.CompilationInfo的用法示例。


在下文中一共展示了CompilationInfo.getDocument方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCodeStyle

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:DiffContext.java

示例2: getCodeStyle

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:GeneratorUtils.java

示例3: isMethodHeaderInsideGuardedBlock

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
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;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:Utilities.java

示例4: run

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:JavaSemanticTokenList.java

示例5: isInGuarded

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:HintsInvoker.java

示例6: resolveContext

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:JavadocCompletionQuery.java

示例7: errorHint

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
@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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:JavadocHint.java

示例8: computeMethod

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
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;
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:48,代码来源:CreateElementUtilities.java

示例9: computeMethod

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
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;
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:53,代码来源:CreateElementUtilities.java


注:本文中的org.netbeans.api.java.source.CompilationInfo.getDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。