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


Java JCDiagnostic类代码示例

本文整理汇总了Java中com.sun.tools.javac.util.JCDiagnostic的典型用法代码示例。如果您正苦于以下问题:Java JCDiagnostic类的具体用法?Java JCDiagnostic怎么用?Java JCDiagnostic使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JCDiagnostic类属于com.sun.tools.javac.util包,在下文中一共展示了JCDiagnostic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNestedDiagnostics

import com.sun.tools.javac.util.JCDiagnostic; //导入依赖的package包/类
private static void getNestedDiagnostics(Diagnostic<?> d, List<Diagnostic> diags) {
    JCDiagnostic jcd = getJCDiagnostic(d);
    if (jcd == null) {
        return;
    }
    Object[] args = jcd.getArgs();
    if (args == null || args.length == 0) {
        return;
    }
    for (Object o : args) {
        if (o instanceof Diagnostic) {
            diags.add((Diagnostic)o);
            getNestedDiagnostics((Diagnostic)o, diags);
            break;
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:Hacks.java

示例2: unrecoverableError

import com.sun.tools.javac.util.JCDiagnostic; //导入依赖的package包/类
/** Return whether or not an unrecoverable error has occurred. */
boolean unrecoverableError() {
    if (messager.errorRaised())
        return true;

    for (JCDiagnostic d: log.deferredDiagnostics) {
        switch (d.getKind()) {
            case WARNING:
                if (werror)
                    return true;
                break;

            case ERROR:
                if (fatalErrors || !d.isFlagSet(RECOVERABLE))
                    return true;
                break;
        }
    }

    return false;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:22,代码来源:JavacProcessingEnvironment.java

示例3: unrecoverableError

import com.sun.tools.javac.util.JCDiagnostic; //导入依赖的package包/类
/** Return whether or not an unrecoverable error has occurred. */
boolean unrecoverableError() {
    if (messager.errorRaised())
        return true;

    for (JCDiagnostic d: deferredDiagnosticHandler.getDiagnostics()) {
        switch (d.getKind()) {
            case WARNING:
                if (werror)
                    return true;
                break;

            case ERROR:
                if (fatalErrors || !d.isFlagSet(RECOVERABLE))
                    return true;
                break;
        }
    }

    return false;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:JavacProcessingEnvironment.java

示例4: process

import com.sun.tools.javac.util.JCDiagnostic; //导入依赖的package包/类
@Override
void process(Diagnostic<? extends JavaFileObject> diagnostic) {
    Element siteSym = getSiteSym(diagnostic);
    if (siteSym.getSimpleName().length() != 0 &&
            ((Symbol)siteSym).outermostClass().getAnnotation(TraceResolve.class) == null) {
        return;
    }
    int candidateIdx = 0;
    for (JCDiagnostic d : subDiagnostics(diagnostic)) {
        boolean isMostSpecific = candidateIdx++ == mostSpecific(diagnostic);
        VerboseCandidateSubdiagProcessor subProc =
                new VerboseCandidateSubdiagProcessor(isMostSpecific, phase(diagnostic), success(diagnostic));
        if (subProc.matches(d)) {
            subProc.process(d);
        } else {
            throw new AssertionError("Bad subdiagnostic: " + d.getCode());
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:ResolveHarness.java

示例5: testInvalidConstantType

import com.sun.tools.javac.util.JCDiagnostic; //导入依赖的package包/类
/** Tests that a field of the given integral type with a constant string value is rejected. */
private static void testInvalidConstantType(String type) throws Exception {
    // create a class file with field that has an invalid CONSTANT_String ConstantValue
    File lib = writeFile(classesdir, "Lib.java", String.format(
            "class Lib { static final String A = \"hello\"; static final %s CONST = %s; }",
            type, type.equals("boolean") ? "false" : "0"));
    compile("-d", classesdir.getPath(), lib.getPath());
    File libClass = new File(classesdir, "Lib.class");
    swapConstantValues(libClass);

    BadClassFile badClassFile = loadBadClass("Lib");

    JCDiagnostic diagnostic = (JCDiagnostic) badClassFile.getDiagnostic().getArgs()[1];
    assertEquals("compiler.misc.bad.constant.value", diagnostic.getCode());
    assertEquals(3, diagnostic.getArgs().length);
    assertEquals("hello", diagnostic.getArgs()[0]);
    assertEquals("CONST", diagnostic.getArgs()[1].toString());
    assertEquals("Integer", diagnostic.getArgs()[2]);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:BadConstantValue.java

示例6: position

import com.sun.tools.javac.util.JCDiagnostic; //导入依赖的package包/类
private static Range position(javax.tools.Diagnostic<? extends JavaFileObject> error) {
    if (error instanceof ClientCodeWrapper.DiagnosticSourceUnwrapper)
        error = ((ClientCodeWrapper.DiagnosticSourceUnwrapper) error).d;

    JCDiagnostic diagnostic = (JCDiagnostic) error;
    DiagnosticSource source = diagnostic.getDiagnosticSource();
    long start = error.getStartPosition(), end = error.getEndPosition();

    if (end == start) end = start + 1;

    return new Range(
            new Position(
                    source.getLineNumber((int) start) - 1,
                    source.getColumnNumber((int) start, true) - 1),
            new Position(
                    source.getLineNumber((int) end) - 1,
                    source.getColumnNumber((int) end, true) - 1));
}
 
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:19,代码来源:Lints.java

示例7: report

import com.sun.tools.javac.util.JCDiagnostic; //导入依赖的package包/类
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
    try {
        if (diagnostic.getKind() == Diagnostic.Kind.ERROR &&
                diagnostic.getCode().equals("compiler.err.ref.ambiguous")) {
            ambiguityFound = true;
        } else if (diagnostic.getKind() == Diagnostic.Kind.NOTE &&
                diagnostic.getCode()
                .equals("compiler.note.verbose.resolve.multi")) {
            ClientCodeWrapper.DiagnosticSourceUnwrapper dsu =
                (ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic;
            JCDiagnostic.MultilineDiagnostic mdiag =
                (JCDiagnostic.MultilineDiagnostic)dsu.d;
            int mostSpecificIndex = (Integer)mdiag.getArgs()[2];
            mostSpecificSig =
                ((JCDiagnostic)mdiag.getSubdiagnostics()
                    .get(mostSpecificIndex)).getArgs()[1].toString();
        }
    } catch (RuntimeException t) {
        t.printStackTrace();
        throw t;
    }
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:23,代码来源:StructuralMostSpecificTest.java

示例8: test

import com.sun.tools.javac.util.JCDiagnostic; //导入依赖的package包/类
private static void test(String classname, String expected) throws Exception {
    File classfile = new File(System.getProperty("test.classes", "."), classname + ".class");
    ClassFile cf = ClassFile.read(classfile);

    cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion,
             Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags,
            cf.this_class, cf.super_class, cf.interfaces, cf.fields,
            cf.methods, cf.attributes);

    new ClassWriter().write(cf, classfile);

    JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null);

    try {
        Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname);

        clazz.complete();
    } catch (BadClassFile f) {
        JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1];
        assertEquals(expected, embeddedDiag.getCode());
        assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]);
        assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]);
    }
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:26,代码来源:BadClassfile.java

示例9: MemberEnter

import com.sun.tools.javac.util.JCDiagnostic; //导入依赖的package包/类
protected MemberEnter(Context context) {
    context.put(memberEnterKey, this);
    names = Names.instance(context);
    enter = Enter.instance(context);
    log = Log.instance(context);
    chk = Check.instance(context);
    attr = Attr.instance(context);
    syms = Symtab.instance(context);
    make = TreeMaker.instance(context);
    reader = ClassReader.instance(context);
    todo = Todo.instance(context);
    annotate = Annotate.instance(context);
    types = Types.instance(context);
    diags = JCDiagnostic.Factory.instance(context);
    target = Target.instance(context);
    deferredLintHandler = DeferredLintHandler.instance(context);
    Options options = Options.instance(context);
    skipAnnotations = options.isSet("skipAnnotations");
}
 
开发者ID:sebastianoe,项目名称:s4j,代码行数:20,代码来源:MemberEnter.java

示例10: importAll

import com.sun.tools.javac.util.JCDiagnostic; //导入依赖的package包/类
/** Import all classes of a class or package on demand.
 *  @param pos           Position to be used for error reporting.
 *  @param tsym          The class or package the members of which are imported.
 *  @param toScope   The (import) scope in which imported classes
 *               are entered.
 */
private void importAll(int pos,
                       final TypeSymbol tsym,
                       Env<AttrContext> env) {
    // Check that packages imported from exist (JLS ???).
    if (tsym.kind == PCK && tsym.members().elems == null && !tsym.exists()) {
        // If we can't find java.lang, exit immediately.
        if (((PackageSymbol)tsym).fullname.equals(names.java_lang)) {
            JCDiagnostic msg = diags.fragment("fatal.err.no.java.lang");
            throw new FatalError(msg);
        } else {
            log.error(DiagnosticFlag.RESOLVE_ERROR, pos, "doesnt.exist", tsym);
        }
    }
    env.toplevel.starImportScope.importAll(tsym.members());
}
 
开发者ID:sebastianoe,项目名称:s4j,代码行数:22,代码来源:MemberEnter.java

示例11: isSyntaxError

import com.sun.tools.javac.util.JCDiagnostic; //导入依赖的package包/类
public static boolean isSyntaxError(Diagnostic<?> d) {
    JCDiagnostic jcd = getJCDiagnostic(d);
    if (jcd == null) {
        return false;
    }
    return jcd.isFlagSet(DiagnosticFlag.SYNTAX);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:Hacks.java

示例12: getJCDiagnostic

import com.sun.tools.javac.util.JCDiagnostic; //导入依赖的package包/类
private static JCDiagnostic getJCDiagnostic(Diagnostic<?> d) {
    if (d instanceof JCDiagnostic) {
        return ((JCDiagnostic)d);
    } else if (d instanceof RichDiagnostic && ((RichDiagnostic) d).getDelegate() instanceof JCDiagnostic) {
        return (JCDiagnostic)((RichDiagnostic)d).getDelegate();
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:Hacks.java

示例13: getDiagnosticParam

import com.sun.tools.javac.util.JCDiagnostic; //导入依赖的package包/类
/**
 * Extracts diagnostic params from a diagnostic. Gets under hood of Javac
 * Diagnostic objects and extracts parameters which are otherwise just used
 * to produce a message. <b>Keep in mind that the positions and types of parameters
 * may change in each nbjavac update!</b>
 * @param d diagnostic
 * @param index parameter index to extract
 * @return parameter value, null if index is out of range
 */
public static Object getDiagnosticParam(Diagnostic<?> d, int index) {
    JCDiagnostic jcd = getJCDiagnostic(d);
    if (jcd == null) {
        return null;
    }
    Object[] args = jcd.getArgs();
    if (args == null || args.length <= index) {
        return null;
    }
    return args[index];
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:Hacks.java

示例14: wrap

import com.sun.tools.javac.util.JCDiagnostic; //导入依赖的package包/类
public static Diagnostic wrap(Diagnostic d, DiagnosticFormatter<JCDiagnostic> df) {
    if (d instanceof JCDiagnostic) {
        return new RichDiagnostic((JCDiagnostic) d, df);
    } else {
        return d;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:CompilationInfoImpl.java

示例15: doParse

import com.sun.tools.javac.util.JCDiagnostic; //导入依赖的package包/类
private static <T extends Tree> T doParse(JavacTaskImpl task, String text, SourcePositions[] sourcePositions, int offset, Function<Parser, T> actualParse) {
    if (text == null || (sourcePositions != null && sourcePositions.length != 1))
        throw new IllegalArgumentException();
    //use a working init order:
    com.sun.tools.javac.main.JavaCompiler.instance(task.getContext());
    com.sun.tools.javac.tree.TreeMaker jcMaker = com.sun.tools.javac.tree.TreeMaker.instance(task.getContext());
    int oldPos = jcMaker.pos;
    
    try {
        //from org/netbeans/modules/java/hints/spiimpl/Utilities.java:
        Context context = task.getContext();
        JavaCompiler compiler = JavaCompiler.instance(context);
        JavaFileObject prev = compiler.log.useSource(new DummyJFO());
        Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(compiler.log) {
            @Override
            public void report(JCDiagnostic diag) {
                //ignore:
            }            
        };
        try {
            CharBuffer buf = CharBuffer.wrap((text+"\u0000").toCharArray(), 0, text.length());
            ParserFactory factory = ParserFactory.instance(context);
            Parser parser = factory.newParser(buf, false, true, false, false);
            if (parser instanceof JavacParser) {
                if (sourcePositions != null)
                    sourcePositions[0] = new ParserSourcePositions((JavacParser)parser, offset);
                return actualParse.apply(parser);
            }
            return null;
        } finally {
            compiler.log.useSource(prev);
            compiler.log.popDiagnosticHandler(discardHandler);
        }
    } finally {
        jcMaker.pos = oldPos;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:TreeUtilities.java


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