Java Code Examples for com.sun.tools.javac.util.Assert#check()

The following examples show how to use com.sun.tools.javac.util.Assert#check() . 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: TestNonInherited.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnv) {
    if (!roundEnv.processingOver()) {
        boolean hasRun = false;
        for (Element element : roundEnv.getRootElements())
            for (TypeElement te : typesIn(element.getEnclosedElements()))
                if (te.getQualifiedName().contentEquals("TestNonInherited.T2")) {
                    hasRun = true;
                    Foo[] foos = te.getAnnotationsByType(Foo.class);
                    System.out.println("  " + te);
                    System.out.println("  " + Arrays.asList(foos));
                    Assert.check(foos.length == 0, "Should not find any instance of @Foo");
                }
        if (!hasRun)
            throw new RuntimeException("The annotation processor could not find the declaration of T2, test broken!");
    }
    return true;
}
 
Example 2
Source File: InlinedFinallyConfuseDebuggersTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
void checkClassFile(final File cfile, String methodToFind) throws Exception {
    ClassFile classFile = ClassFile.read(cfile);
    boolean methodFound = false;
    for (Method method : classFile.methods) {
        if (method.getName(classFile.constant_pool).equals(methodToFind)) {
            methodFound = true;
            Code_attribute code = (Code_attribute) method.attributes.get("Code");
            LineNumberTable_attribute lnt =
                    (LineNumberTable_attribute) code.attributes.get("LineNumberTable");
            Assert.check(lnt.line_number_table_length == expectedLNT.length,
                    "The LineNumberTable found has a length different to the expected one");
            int i = 0;
            for (LineNumberTable_attribute.Entry entry: lnt.line_number_table) {
                Assert.check(entry.line_number == expectedLNT[i][0] &&
                        entry.start_pc == expectedLNT[i][1],
                        "LNT entry at pos " + i + " differ from expected." +
                        "Found " + entry.line_number + ":" + entry.start_pc +
                        ". Expected " + expectedLNT[i][0] + ":" + expectedLNT[i][1]);
                i++;
            }
        }
    }
    Assert.check(methodFound, "The seek method was not found");
}
 
Example 3
Source File: DebugPointerAtBadPositionTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
void checkClassFile(final File cfile, String methodToFind) throws Exception {
    ClassFile classFile = ClassFile.read(cfile);
    boolean methodFound = false;
    for (Method method : classFile.methods) {
        if (method.getName(classFile.constant_pool).equals(methodToFind)) {
            methodFound = true;
            Code_attribute code = (Code_attribute) method.attributes.get("Code");
            LineNumberTable_attribute lnt =
                    (LineNumberTable_attribute) code.attributes.get("LineNumberTable");
            Assert.check(lnt.line_number_table_length == expectedLNT.length,
                    foundLNTLengthDifferentThanExpMsg);
            int i = 0;
            for (LineNumberTable_attribute.Entry entry: lnt.line_number_table) {
                Assert.check(entry.line_number == expectedLNT[i][0] &&
                        entry.start_pc == expectedLNT[i][1],
                        "LNT entry at pos " + i + " differ from expected." +
                        "Found " + entry.line_number + ":" + entry.start_pc +
                        ". Expected " + expectedLNT[i][0] + ":" + expectedLNT[i][1]);
                i++;
            }
        }
    }
    Assert.check(methodFound, seekMethodNotFoundMsg);
}
 
Example 4
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void visitMethodDef(JCMethodDecl tree) {
    if (tree.body == null) return;
    Lint lintPrev = lint;

    lint = lint.augment(tree.sym);

    Assert.check(pendingExits.isEmpty());

    try {
        alive = true;
        scanStat(tree.body);

        if (alive && !tree.sym.type.getReturnType().hasTag(VOID))
            log.error(TreeInfo.diagEndPos(tree.body), Errors.MissingRetStmt);

        List<PendingExit> exits = pendingExits.toList();
        pendingExits = new ListBuffer<>();
        while (exits.nonEmpty()) {
            PendingExit exit = exits.head;
            exits = exits.tail;
            Assert.check(exit.tree.hasTag(RETURN));
        }
    } finally {
        lint = lintPrev;
    }
}
 
Example 5
Source File: DebugPointerAtBadPositionTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
void checkClassFile(final File cfile, String methodToFind) throws Exception {
    ClassFile classFile = ClassFile.read(cfile);
    boolean methodFound = false;
    for (Method method : classFile.methods) {
        if (method.getName(classFile.constant_pool).equals(methodToFind)) {
            methodFound = true;
            Code_attribute code = (Code_attribute) method.attributes.get("Code");
            LineNumberTable_attribute lnt =
                    (LineNumberTable_attribute) code.attributes.get("LineNumberTable");
            Assert.check(lnt.line_number_table_length == expectedLNT.length,
                    foundLNTLengthDifferentThanExpMsg);
            int i = 0;
            for (LineNumberTable_attribute.Entry entry: lnt.line_number_table) {
                Assert.check(entry.line_number == expectedLNT[i][0] &&
                        entry.start_pc == expectedLNT[i][1],
                        "LNT entry at pos " + i + " differ from expected." +
                        "Found " + entry.line_number + ":" + entry.start_pc +
                        ". Expected " + expectedLNT[i][0] + ":" + expectedLNT[i][1]);
                i++;
            }
        }
    }
    Assert.check(methodFound, seekMethodNotFoundMsg);
}
 
Example 6
Source File: T7116676.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void testThroughFormatterFormat() throws IOException {
    final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    DiagnosticChecker dc = new DiagnosticChecker("compiler.err.prob.found.req");
    JavacTask ct = (JavacTask)tool.getTask(null, null, dc, null, null, Arrays.asList(new JavaSource()));
    ct.analyze();
    DiagnosticFormatter<JCDiagnostic> formatter =
            Log.instance(((JavacTaskImpl) ct).getContext()).getDiagnosticFormatter();
    String msg = formatter.formatMessage(dc.diag, Locale.getDefault());
    //no redundant package qualifiers
    Assert.check(msg.indexOf("java.") == -1, msg);
}
 
Example 7
Source File: Pool.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check consistency of reference kind and symbol (see JVMS 4.4.8)
 */
@SuppressWarnings("fallthrough")
private void checkConsistent() {
    boolean staticOk = false;
    int expectedKind = -1;
    Filter<Name> nameFilter = nonInitFilter;
    boolean interfaceOwner = false;
    switch (refKind) {
        case ClassFile.REF_getStatic:
        case ClassFile.REF_putStatic:
            staticOk = true;
        case ClassFile.REF_getField:
        case ClassFile.REF_putField:
            expectedKind = Kinds.VAR;
            break;
        case ClassFile.REF_newInvokeSpecial:
            nameFilter = initFilter;
            expectedKind = Kinds.MTH;
            break;
        case ClassFile.REF_invokeInterface:
            interfaceOwner = true;
            expectedKind = Kinds.MTH;
            break;
        case ClassFile.REF_invokeStatic:
            interfaceOwner = true;
            staticOk = true;
        case ClassFile.REF_invokeVirtual:
            expectedKind = Kinds.MTH;
            break;
        case ClassFile.REF_invokeSpecial:
            interfaceOwner = true;
            expectedKind = Kinds.MTH;
            break;
    }
    Assert.check(!refSym.isStatic() || staticOk);
    Assert.check(refSym.kind == expectedKind);
    Assert.check(nameFilter.accepts(refSym.name));
    Assert.check(!refSym.owner.isInterface() || interfaceOwner);
}
 
Example 8
Source File: T8068517.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void runTest(String aJava, String bJava) throws Exception {
    File testClasses = new File(System.getProperty("test.classes"));
    File target1 = new File(testClasses, "T8068517s" + testN++);
    doCompile(target1, aJava, bJava);
    File target2 = new File(testClasses, "T8068517s" + testN++);
    doCompile(target2, bJava, aJava);

    Assert.check(Arrays.equals(Files.readAllBytes(new File(target1, "B.class").toPath()),
                               Files.readAllBytes(new File(target2, "B.class").toPath())));
}
 
Example 9
Source File: Profiles.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void excludeType(int profile, String typeName) {
//            System.err.println("exclude type " + typeName);
            int sep = typeName.lastIndexOf("/");
            String packageName = typeName.substring(0, sep);
            String simpleName = typeName.substring(sep + 1);

            Package p = getPackage(packageName);
            Assert.check(!p.excludedTypes.containsKey(simpleName));
            p.excludedTypes.put(simpleName, profile);
        }
 
Example 10
Source File: SymbolMetadata.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void setDeclarationAttributes(List<Attribute.Compound> a) {
    Assert.check(pendingCompletion() || !isStarted());
    if (a == null) {
        throw new NullPointerException();
    }
    attributes = a;
}
 
Example 11
Source File: Profiles.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void includeType(int profile, String typeName) {
//            System.err.println("include type " + typeName);
            int sep = typeName.lastIndexOf("/");
            String packageName = typeName.substring(0, sep);
            String simpleName = typeName.substring(sep + 1);

            Package p = getPackage(packageName);
            Assert.check(!p.includedTypes.containsKey(simpleName));
            p.includedTypes.put(simpleName, profile);
        }
 
Example 12
Source File: Pool.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check consistency of reference kind and symbol (see JVMS 4.4.8)
 */
@SuppressWarnings("fallthrough")
private void checkConsistent() {
    boolean staticOk = false;
    int expectedKind = -1;
    Filter<Name> nameFilter = nonInitFilter;
    boolean interfaceOwner = false;
    switch (refKind) {
        case ClassFile.REF_getStatic:
        case ClassFile.REF_putStatic:
            staticOk = true;
        case ClassFile.REF_getField:
        case ClassFile.REF_putField:
            expectedKind = Kinds.VAR;
            break;
        case ClassFile.REF_newInvokeSpecial:
            nameFilter = initFilter;
            expectedKind = Kinds.MTH;
            break;
        case ClassFile.REF_invokeInterface:
            interfaceOwner = true;
            expectedKind = Kinds.MTH;
            break;
        case ClassFile.REF_invokeStatic:
            interfaceOwner = true;
            staticOk = true;
        case ClassFile.REF_invokeVirtual:
            expectedKind = Kinds.MTH;
            break;
        case ClassFile.REF_invokeSpecial:
            interfaceOwner = true;
            expectedKind = Kinds.MTH;
            break;
    }
    Assert.check(!refSym.isStatic() || staticOk);
    Assert.check(refSym.kind == expectedKind);
    Assert.check(nameFilter.accepts(refSym.name));
    Assert.check(!refSym.owner.isInterface() || interfaceOwner);
}
 
Example 13
Source File: T7116676.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void testThroughFormatterFormat() throws IOException {
    final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    DiagnosticChecker dc = new DiagnosticChecker("compiler.err.prob.found.req");
    JavacTask ct = (JavacTask)tool.getTask(null, null, dc, null, null, Arrays.asList(new JavaSource()));
    ct.analyze();
    DiagnosticFormatter<JCDiagnostic> formatter =
            Log.instance(((JavacTaskImpl) ct).getContext()).getDiagnosticFormatter();
    String msg = formatter.formatMessage(dc.diag, Locale.getDefault());
    //no redundant package qualifiers
    Assert.check(msg.indexOf("java.") == -1, msg);
}
 
Example 14
Source File: EmptyUTF8ForInnerClassNameTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void checkClassFile(final Path path) throws Exception {
    ClassFile classFile = ClassFile.read(
            new BufferedInputStream(Files.newInputStream(path)));
    for (CPInfo cpInfo : classFile.constant_pool.entries()) {
        if (cpInfo.getTag() == CONSTANT_Utf8) {
            CONSTANT_Utf8_info utf8Info = (CONSTANT_Utf8_info)cpInfo;
            Assert.check(utf8Info.value.length() > 0,
                    "UTF8 with length 0 found at class " + classFile.getName());
        }
    }
}
 
Example 15
Source File: ParameterNamesAreNotCopiedToAnonymousInitTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void checkClassFile(final File cfile, int numberOfParams) throws Exception {
    ClassFile classFile = ClassFile.read(cfile);
    boolean methodFound = false;
    for (Method method : classFile.methods) {
        if (method.getName(classFile.constant_pool).equals("<init>")) {
            methodFound = true;
        }
    }
    Assert.check(methodFound, seekMethodNotFoundMsg);
}
 
Example 16
Source File: EmptyUTF8ForInnerClassNameTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void checkClassFile(final Path path) throws Exception {
    ClassFile classFile = ClassFile.read(
            new BufferedInputStream(Files.newInputStream(path)));
    for (CPInfo cpInfo : classFile.constant_pool.entries()) {
        if (cpInfo.getTag() == CONSTANT_Utf8) {
            CONSTANT_Utf8_info utf8Info = (CONSTANT_Utf8_info)cpInfo;
            Assert.check(utf8Info.value.length() > 0,
                    "UTF8 with length 0 found at class " + classFile.getName());
        }
    }
}
 
Example 17
Source File: SymbolMetadata.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void setDeclarationAttributesWithCompletion(final Annotate.AnnotateRepeatedContext<Attribute.Compound> ctx) {
    Assert.check(pendingCompletion() || (!isStarted() && sym.kind == PCK));
    this.setDeclarationAttributes(getAttributesForCompletion(ctx));
}
 
Example 18
Source File: StandardDocFileFactory.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/** Create a StandardDocFile for a given location and relative path. */
private StandardDocFile(Location location, DocPath path) {
    super(configuration, location, path);
    Assert.check(location == DocumentationTool.Location.DOCUMENTATION_OUTPUT);
    this.file = newFile(getDestDir(), path.getPath());
}
 
Example 19
Source File: DCTree.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
DCLink(Kind kind, DCReference ref, List<DCTree> label) {
    Assert.check(kind == Kind.LINK || kind == Kind.LINK_PLAIN);
    this.kind = kind;
    this.ref = ref;
    this.label = label;
}
 
Example 20
Source File: DCTree.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
DCLink(Kind kind, DCReference ref, List<DCTree> label) {
    Assert.check(kind == Kind.LINK || kind == Kind.LINK_PLAIN);
    this.kind = kind;
    this.ref = ref;
    this.label = label;
}