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


Java CompilationInfo.getDiagnostics方法代码示例

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


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

示例1: getDiagnostic

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
/**
 * Returns the diagnostics entry
 * @param compilationInfo
 * @param start
 * @param codes
 * @return 
 */
private Diagnostic getDiagnostic(CompilationInfo compilationInfo, long start, Set<String> errorCodes) {
    Diagnostic result = null;
    for (Diagnostic d : compilationInfo.getDiagnostics()) {
        if (start != d.getStartPosition()) {
            continue;
        }
        if (!errorCodes.contains(d.getCode())) {
            continue;
        }
        result=d;
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:RemoveInvalidModifier.java

示例2: ensureCompilable

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
private void ensureCompilable(FileObject file) throws IOException, AssertionError, IllegalArgumentException {
    CompilationInfo info = parse(file);

    assertNotNull(info);

    for (Diagnostic d : info.getDiagnostics()) {
        if (d.getKind() == Diagnostic.Kind.ERROR)
            throw new AssertionError(d.getLineNumber() + ":" + d.getColumnNumber() + " " + d.getMessage(null));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:HintTest.java

示例3: BiAnalyser

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
/** Creates Bean Info analyser which contains all patterns from PatternAnalyser
*/
BiAnalyser ( PatternAnalyser pa, CompilationInfo javac ) throws GenerateBeanException {
    int index;
    
    this.isBeanBroken = false;
    
    for (Diagnostic d : javac.getDiagnostics()) {
        isBeanBroken |= d.getKind() == Diagnostic.Kind.ERROR;
    }

    // Try to find and analyse existing bean info
    bis = new BeanInfoSource( pa.getFileObject() );
    olderVersion = (bis.isNbBeanInfo() && bis.getMethodsSection() == null);
    superClassVersion = (bis.isNbSuperclass() || !bis.exists());
    
    TypeElement classElement = pa.getClassElementHandle().resolve(javac);
    this.classfqn = classElement.getQualifiedName().toString();
    
    // Fill Descriptor list (only in case we have new templates)
    descriptor = new ArrayList<BiFeature.Descriptor>();
    descriptor.add(new BiFeature.Descriptor(classElement, this));

    // Fill methods list (only in case we have new templates)
    methods = new  ArrayList<BiFeature.Method>();
    if (!olderVersion) {
        for (ExecutableElement method : BeanUtils.methodsIn(classElement, javac)) {
            methods.add(new BiFeature.Method(method, pa, javac, this));
        }
    }

    // Fill properties list
    List<PropertyPattern> propertyPatterns = pa.getPropertyPatterns();
    properties = new  ArrayList<BiFeature.Property>(propertyPatterns.size());
    for (PropertyPattern pp : propertyPatterns) {
        properties.add(new BiFeature.Property(pp, javac, this));
        removeMethods(methods, pp.getGetterMethod(), pp.getSetterMethod());
    }

    // Fill indexed properties list
    List<IdxPropertyPattern> idxPropertyPatterns = pa.getIdxPropertyPatterns();
    idxProperties = new  ArrayList<BiFeature.IdxProperty>(idxPropertyPatterns.size());
    for (IdxPropertyPattern ipp : idxPropertyPatterns) {
        TypeMirror type = ipp.getType().resolve(javac);
        TypeMirror idxtype = ipp.getIndexedType().resolve(javac);
        if (type.getKind() != TypeKind.ARRAY || !javac.getTypes().isSameType(((ArrayType) type).getComponentType(), idxtype)) {
            continue;
        }

        idxProperties.add(new BiFeature.IdxProperty(ipp, javac, this));
        removeMethods(methods, ipp.getGetterMethod(), ipp.getSetterMethod(), ipp.getIndexedGetterMethod(), ipp.getIndexedSetterMethod());
    }

    // Fill event sets list
    List<EventSetPattern> eventSetPatterns = pa.getEventSetPatterns();
    eventSets = new  ArrayList<BiFeature.EventSet>(eventSetPatterns.size());
    for (EventSetPattern esp : eventSetPatterns) {
        eventSets.add(new BiFeature.EventSet(esp, javac, this));
        removeMethods(methods, esp.getAddListenerMethod(), esp.getRemoveListenerMethod());
    }

    Collections.sort(methods);

    try {
        isUpdateMode = false;
        analyzeBeanInfoSource();
    } finally {
        isUpdateMode = true;
    }

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:72,代码来源:BiAnalyser.java

示例4: check

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
@TriggerTreeKind({Tree.Kind.CLASS, Tree.Kind.INTERFACE})
public static ErrorDescription check(HintContext context) {
    TreePath tp = context.getPath();
    ClassTree cls = (ClassTree) tp.getLeaf();
    CompilationInfo info = context.getInfo();
    SourcePositions sourcePositions = info.getTrees().getSourcePositions();
    long startPos = sourcePositions.getStartPosition(tp.getCompilationUnit(), cls);
    if (startPos > Integer.MAX_VALUE) {
        return null;
    }
    int[] bodySpan = info.getTreeUtilities().findBodySpan(cls);
    if (bodySpan == null || bodySpan[0] <= startPos) {
        return null;
    }
    int caret = context.getCaretLocation();
    if (startPos < 0 || caret < 0 || caret < startPos || caret >= bodySpan[0]) {
        return null;
    }

    // #222487
    // If there is a compile-time error on the class, then don't offer to
    // create a subclass.
    List<Diagnostic> errors = info.getDiagnostics();
    if (!errors.isEmpty()) {
        for (Diagnostic d : errors) {
            if (d.getKind() != Diagnostic.Kind.ERROR) {
                continue;
            }
            // Check that the error's start position is within the class header
            // Note: d.getEndPosition() is not used because, for example,
            // a "compiler.err.does.not.override.abstract" error ends at
            // the end of the class tree.
            if (startPos <= d.getStartPosition() && d.getStartPosition() <= bodySpan[0]) {
                return null;
            }
        }
    }

    TypeElement typeElement = (TypeElement) info.getTrees().getElement(tp);
    
    if (typeElement == null || typeElement.getModifiers().contains(Modifier.FINAL)) return null;

    Element outer = typeElement.getEnclosingElement();
    // do not offer the hint for non-static inner classes. Permit for classes nested into itnerface - no enclosing instance
    if (outer != null && outer.getKind() != ElementKind.PACKAGE && outer.getKind() != ElementKind.INTERFACE) {
        if (outer.getKind() != ElementKind.CLASS && outer.getKind() != ElementKind.ENUM) {
            return null;
        }
        if (!typeElement.getModifiers().contains(Modifier.STATIC)) {
            return null;
        }
    }

    
    ClassPath cp = info.getClasspathInfo().getClassPath(PathKind.SOURCE);
    FileObject root = cp.findOwnerRoot(info.getFileObject());
    if (root == null) { //File not part of any project
        return null;
    }

    PackageElement packageElement = (PackageElement) info.getElementUtilities().outermostTypeElement(typeElement).getEnclosingElement();
    CreateSubclassFix fix = new CreateSubclassFix(info, root, packageElement.getQualifiedName().toString(), typeElement.getSimpleName().toString() + "Impl", typeElement); //NOI18N
    return ErrorDescriptionFactory.forTree(context, context.getPath(), NbBundle.getMessage(CreateSubclass.class, typeElement.getKind() == ElementKind.CLASS
            ? typeElement.getModifiers().contains(Modifier.ABSTRACT) ? "ERR_ImplementAbstractClass" : "ERR_CreateSubclass" : "ERR_ImplementInterface"), fix); //NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:66,代码来源:CreateSubclass.java


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