com.sun.tools.javac.util.Assert Java Examples

The following examples show how to use com.sun.tools.javac.util.Assert. 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 openjdk-jdk8u-backup 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: DefaultMethodFlags.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void checkDefaultInterface(TypeElement te) {
    System.err.println("Checking " + te.getSimpleName());
    Assert.check(te.getModifiers().contains(Modifier.ABSTRACT));
    for (Element e : te.getEnclosedElements()) {
        if (e.getSimpleName().toString().matches("(\\w)_(default|static|abstract)")) {
            boolean abstractExpected = false;
            String methodKind = e.getSimpleName().toString().substring(2);
            switch (methodKind) {
                case "default":
                case "static":
                    break;
                case "abstract":
                    abstractExpected = true;
                    break;
                default:
                    Assert.error("Cannot get here!" + methodKind);
            }
            Assert.check(e.getModifiers().contains(Modifier.ABSTRACT) == abstractExpected);
        }
    }
}
 
Example #3
Source File: JavacProcessingEnvironment.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/** Create a round (common code). */
private Round(Context context, int number, int priorErrors, int priorWarnings,
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this.context = context;
    this.number = number;

    compiler = JavaCompiler.instance(context);
    log = Log.instance(context);
    log.nerrors = priorErrors;
    log.nwarnings = priorWarnings;
    if (number == 1) {
        Assert.checkNonNull(deferredDiagnosticHandler);
        this.deferredDiagnosticHandler = deferredDiagnosticHandler;
    } else {
        this.deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log);
    }

    // the following is for the benefit of JavacProcessingEnvironment.getContext()
    JavacProcessingEnvironment.this.context = context;

    // the following will be populated as needed
    topLevelClasses  = List.nil();
    packageInfoFiles = List.nil();
}
 
Example #4
Source File: NoDeadCodeGenerationOnTrySmtTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void checkClassFile(final File cfile, String[] methodsToFind) throws Exception {
    ClassFile classFile = ClassFile.read(cfile);
    int numberOfmethodsFound = 0;
    for (String methodToFind : methodsToFind) {
        for (Method method : classFile.methods) {
            if (method.getName(classFile.constant_pool).equals(methodToFind)) {
                numberOfmethodsFound++;
                Code_attribute code = (Code_attribute) method.attributes.get("Code");
                Assert.check(code.exception_table_length == expectedExceptionTable.length,
                        "The ExceptionTable found has a length different to the expected one");
                int i = 0;
                for (Exception_data entry: code.exception_table) {
                    Assert.check(entry.start_pc == expectedExceptionTable[i][0] &&
                            entry.end_pc == expectedExceptionTable[i][1] &&
                            entry.handler_pc == expectedExceptionTable[i][2] &&
                            entry.catch_type == expectedExceptionTable[i][3],
                            "Exception table entry at pos " + i + " differ from expected.");
                    i++;
                }
            }
        }
    }
    Assert.check(numberOfmethodsFound == 2, "Some seek methods were not found");
}
 
Example #5
Source File: SymbolMetadata.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void setAttributes(SymbolMetadata other) {
    if (other == null) {
        throw new NullPointerException();
    }
    setDeclarationAttributes(other.getDeclarationAttributes());
    if ((sym.flags() & Flags.BRIDGE) != 0) {
        Assert.check(other.sym.kind == Kind.MTH);
        ListBuffer<TypeCompound> typeAttributes = new ListBuffer<>();
        for (TypeCompound tc : other.getTypeAttributes()) {
            // Carry over only contractual type annotations: i.e nothing interior to method body.
            if (!tc.position.type.isLocal())
                typeAttributes.append(tc);
        }
        setTypeAttributes(typeAttributes.toList());
    } else {
        setTypeAttributes(other.getTypeAttributes());
    }
    if (sym.kind == Kind.TYP) {
        setInitTypeAttributes(other.getInitTypeAttributes());
        setClassInitTypeAttributes(other.getClassInitTypeAttributes());
    }
}
 
Example #6
Source File: GenerateSuperInterfaceProcessor.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (Element el : roundEnv.getElementsAnnotatedWith(Generate.class)) {
        Generate g = el.getAnnotation(Generate.class);

        Assert.checkNonNull(g);

        try (OutputStream out =
                processingEnv.getFiler().createSourceFile(g.fileName()).openOutputStream()) {
            out.write(g.content().getBytes());
        } catch (IOException ex) {
            throw new IllegalStateException(ex);
        }
    }

    return false;
}
 
Example #7
Source File: NoDeadCodeGenerationOnTrySmtTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
void checkClassFile(final File cfile, String[] methodsToFind) throws Exception {
    ClassFile classFile = ClassFile.read(cfile);
    int numberOfmethodsFound = 0;
    for (String methodToFind : methodsToFind) {
        for (Method method : classFile.methods) {
            if (method.getName(classFile.constant_pool).equals(methodToFind)) {
                numberOfmethodsFound++;
                Code_attribute code = (Code_attribute) method.attributes.get("Code");
                Assert.check(code.exception_table_length == expectedExceptionTable.length,
                        "The ExceptionTable found has a length different to the expected one");
                int i = 0;
                for (Exception_data entry: code.exception_table) {
                    Assert.check(entry.start_pc == expectedExceptionTable[i][0] &&
                            entry.end_pc == expectedExceptionTable[i][1] &&
                            entry.handler_pc == expectedExceptionTable[i][2] &&
                            entry.catch_type == expectedExceptionTable[i][3],
                            "Exception table entry at pos " + i + " differ from expected.");
                    i++;
                }
            }
        }
    }
    Assert.check(numberOfmethodsFound == 2, "Some seek methods were not found");
}
 
Example #8
Source File: Scope.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Remove all entries of this scope from its table, if shared
 *  with next.
 */
public WriteableScope leave() {
    Assert.check(shared == 0);
    if (table != next.table) return next;
    while (elems != null) {
        int hash = getIndex(elems.sym.name);
        Entry e = table[hash];
        Assert.check(e == elems, elems.sym);
        table[hash] = elems.shadowed;
        elems = elems.sibling;
    }
    Assert.check(next.shared > 0);
    next.shared--;
    next.nelems = nelems;
    // System.out.println("====> leaving scope " + this.hashCode() + " owned by " + this.owner + " to " + next.hashCode());
    // new Error().printStackTrace(System.out);
    return next;
}
 
Example #9
Source File: BuildState.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Store references to all artifacts found in the module tree into the maps
 * stored in the build state.
 *
 * @param m The set of modules.
 */
public void flattenArtifacts(Map<String,Module> m) {
    modules = m;
    // Extract all the found packages.
    for (Module i : modules.values()) {
        for (Map.Entry<String,Package> j : i.packages().entrySet()) {
            Package p = packages.get(j.getKey());
            // Check that no two different packages are stored under same name.
            Assert.check(p == null || p == j.getValue());
            p = j.getValue();
            packages.put(j.getKey(),j.getValue());
            for (Map.Entry<String,File> g : p.artifacts().entrySet()) {
                File f = artifacts.get(g.getKey());
                // Check that no two artifacts are stored under the same file.
                Assert.check(f == null || f == g.getValue());
                artifacts.put(g.getKey(), g.getValue());
            }
        }
    }
}
 
Example #10
Source File: NoDeadCodeGenerationOnTrySmtTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
void checkClassFile(final File cfile, String[] methodsToFind) throws Exception {
    ClassFile classFile = ClassFile.read(cfile);
    int numberOfmethodsFound = 0;
    for (String methodToFind : methodsToFind) {
        for (Method method : classFile.methods) {
            if (method.getName(classFile.constant_pool).equals(methodToFind)) {
                numberOfmethodsFound++;
                Code_attribute code = (Code_attribute) method.attributes.get("Code");
                Assert.check(code.exception_table_length == expectedExceptionTable.length,
                        "The ExceptionTable found has a length different to the expected one");
                int i = 0;
                for (Exception_data entry: code.exception_table) {
                    Assert.check(entry.start_pc == expectedExceptionTable[i][0] &&
                            entry.end_pc == expectedExceptionTable[i][1] &&
                            entry.handler_pc == expectedExceptionTable[i][2] &&
                            entry.catch_type == expectedExceptionTable[i][3],
                            "Exception table entry at pos " + i + " differ from expected.");
                    i++;
                }
            }
        }
    }
    Assert.check(numberOfmethodsFound == 2, "Some seek methods were not found");
}
 
Example #11
Source File: ClassReader.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void complete(ClassSymbol sym) {
    Assert.check(proxyOn == sym);
    Attribute.Compound theTarget = null, theRepeatable = null;
    AnnotationDeproxy deproxy;

    try {
        if (target != null) {
            deproxy = new AnnotationDeproxy(proxyOn);
            theTarget = deproxy.deproxyCompound(target);
        }

        if (repeatable != null) {
            deproxy = new AnnotationDeproxy(proxyOn);
            theRepeatable = deproxy.deproxyCompound(repeatable);
        }
    } catch (Exception e) {
        throw new CompletionFailure(sym, ClassReader.this.diagFactory.fragment(Fragments.ExceptionMessage(e.getMessage())));
    }

    sym.getAnnotationTypeMetadata().setTarget(theTarget);
    sym.getAnnotationTypeMetadata().setRepeatable(theRepeatable);
}
 
Example #12
Source File: StringConcat.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static StringConcat makeConcat(Context context) {
    Target target = Target.instance(context);
    String opt = Options.instance(context).get("stringConcat");
    if (target.hasStringConcatFactory()) {
        if (opt == null) {
            opt = "inline";//"indyWithConstants";
        }
    } else {
        if (opt != null && !"inline".equals(opt)) {
            Assert.error("StringConcatFactory-based string concat is requested on a platform that does not support it.");
        }
        opt = "inline";
    }

    switch (opt) {
        case "inline":
            return new Inline(context);
        case "indy":
            return new IndyPlain(context);
        case "indyWithConstants":
            return new IndyConstants(context);
        default:
            Assert.error("Unknown stringConcat: " + opt);
            throw new IllegalStateException("Unknown stringConcat: " + opt);
    }
}
 
Example #13
Source File: DebugPointerAtBadPositionTest.java    From TencentKona-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 #14
Source File: FieldOverloadKindNotAssignedTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    Context context = new Context();
    JavacFileManager.preRegister(context);
    final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, Arrays.asList(new JavaSource()));
    Iterable<? extends CompilationUnitTree> elements = ct.parse();
    ct.analyze();
    Assert.check(elements.iterator().hasNext());
    JCTree topLevel = (JCTree)elements.iterator().next();
    new TreeScanner() {
        @Override
        public void visitReference(JCMemberReference tree) {
            Assert.check(tree.getOverloadKind() != null);
        }
    }.scan(topLevel);
}
 
Example #15
Source File: InlinedFinallyConfuseDebuggersTest.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,
                    "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 #16
Source File: NoDeadCodeGenerationOnTrySmtTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
void checkClassFile(final File cfile, String[] methodsToFind) throws Exception {
    ClassFile classFile = ClassFile.read(cfile);
    int numberOfmethodsFound = 0;
    for (String methodToFind : methodsToFind) {
        for (Method method : classFile.methods) {
            if (method.getName(classFile.constant_pool).equals(methodToFind)) {
                numberOfmethodsFound++;
                Code_attribute code = (Code_attribute) method.attributes.get("Code");
                Assert.check(code.exception_table_length == expectedExceptionTable.length,
                        "The ExceptionTable found has a length different to the expected one");
                int i = 0;
                for (Exception_data entry: code.exception_table) {
                    Assert.check(entry.start_pc == expectedExceptionTable[i][0] &&
                            entry.end_pc == expectedExceptionTable[i][1] &&
                            entry.handler_pc == expectedExceptionTable[i][2] &&
                            entry.catch_type == expectedExceptionTable[i][3],
                            "Exception table entry at pos " + i + " differ from expected.");
                    i++;
                }
            }
        }
    }
    Assert.check(numberOfmethodsFound == 2, "Some seek methods were not found");
}
 
Example #17
Source File: JavacProcessingEnvironment.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Create a round (common code). */
private Round(Context context, int number, int priorErrors, int priorWarnings,
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this.context = context;
    this.number = number;

    compiler = JavaCompiler.instance(context);
    log = Log.instance(context);
    log.nerrors = priorErrors;
    log.nwarnings = priorWarnings;
    if (number == 1) {
        Assert.checkNonNull(deferredDiagnosticHandler);
        this.deferredDiagnosticHandler = deferredDiagnosticHandler;
    } else {
        this.deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log);
    }

    // the following is for the benefit of JavacProcessingEnvironment.getContext()
    JavacProcessingEnvironment.this.context = context;

    // the following will be populated as needed
    topLevelClasses  = List.nil();
    packageInfoFiles = List.nil();
}
 
Example #18
Source File: Option.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Option(String text, String argsNameKey, String descrKey,
        OptionKind kind, OptionGroup group,
        ChoiceKind choiceKind, Set<String> choices,
        ArgKind argKind) {
    this.names = text.trim().split("\\s+");
    Assert.check(names.length >= 1);
    this.primaryName = names[0];
    this.argsNameKey = argsNameKey;
    this.descrKey = descrKey;
    this.kind = kind;
    this.group = group;
    this.choiceKind = choiceKind;
    this.choices = choices;
    this.argKind = argKind;
}
 
Example #19
Source File: Enter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Create a fresh environment for modules.
 *
 *  @param tree     The module definition.
 *  @param env      The environment current outside of the module definition.
 */
public Env<AttrContext> moduleEnv(JCModuleDecl tree, Env<AttrContext> env) {
    Assert.checkNonNull(tree.sym);
    Env<AttrContext> localEnv =
        env.dup(tree, env.info.dup(WriteableScope.create(tree.sym)));
    localEnv.enclClass = predefClassDef;
    localEnv.outer = env;
    localEnv.info.isSelfCall = false;
    localEnv.info.lint = null; // leave this to be filled in by Attr,
                               // when annotations have been processed
    return localEnv;
}
 
Example #20
Source File: AssertCheckAnalyzer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
AssertOverloadKind assertOverloadKind(Symbol method) {
    if (method == null ||
        !method.owner.getQualifiedName().contentEquals(Assert.class.getName()) ||
        method.type.getParameterTypes().tail == null) {
        return AssertOverloadKind.NONE;
    }
    Type formal = method.type.getParameterTypes().last();
    if (types.isSameType(formal, syms.stringType)) {
        return AssertOverloadKind.EAGER;
    } else if (types.isSameType(types.erasure(formal), types.erasure(syms.supplierType))) {
        return AssertOverloadKind.LAZY;
    } else {
        return AssertOverloadKind.NONE;
    }
}
 
Example #21
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 #22
Source File: DeferredAttr.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Type typeOf(DeferredType dt) {
    switch (deferredAttrContext.mode) {
        case CHECK:
            return dt.tree.type == null ? Type.noType : dt.tree.type;
        case SPECULATIVE:
            return dt.speculativeType(deferredAttrContext.msym, deferredAttrContext.phase);
    }
    Assert.error();
    return null;
}
 
Example #23
Source File: T7116676.java    From TencentKona-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 #24
Source File: Type.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/** Define a constant type, of the same kind as this type
 *  and with given constant value
 */
public Type constType(Object constValue) {
    final Object value = constValue;
    Assert.check(tag <= BOOLEAN);
    return new Type(tag, tsym) {
            @Override
            public Object constValue() {
                return value;
            }
            @Override
            public Type baseType() {
                return tsym.type;
            }
        };
}
 
Example #25
Source File: T7116676.java    From hottub 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 #26
Source File: ClassFinder.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Load directory of package into members scope.
 */
private void fillIn(PackageSymbol p) throws IOException {
    if (p.members_field == null)
        p.members_field = WriteableScope.create(p);

    ModuleSymbol msym = p.modle;

    Assert.checkNonNull(msym, p::toString);

    msym.complete();

    if (msym == syms.noModule) {
        preferCurrent = false;
        if (userPathsFirst) {
            scanUserPaths(p, true);
            preferCurrent = true;
            scanPlatformPath(p);
        } else {
            scanPlatformPath(p);
            scanUserPaths(p, true);
        }
    } else if (msym.classLocation == StandardLocation.CLASS_PATH) {
        scanUserPaths(p, msym.sourceLocation == StandardLocation.SOURCE_PATH);
    } else {
        scanModulePaths(p, msym);
    }
}
 
Example #27
Source File: T8068517.java    From openjdk-jdk8u-backup 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 #28
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void checkCyclicDependencies(JCModuleDecl mod) {
    for (JCDirective d : mod.directives) {
        JCRequires rd;
        if (!d.hasTag(Tag.REQUIRES) || (rd = (JCRequires) d).directive == null)
            continue;
        Set<ModuleSymbol> nonSyntheticDeps = new HashSet<>();
        List<ModuleSymbol> queue = List.of(rd.directive.module);
        while (queue.nonEmpty()) {
            ModuleSymbol current = queue.head;
            queue = queue.tail;
            if (!nonSyntheticDeps.add(current))
                continue;
            current.complete();
            if ((current.flags() & Flags.ACYCLIC) != 0)
                continue;
            Assert.checkNonNull(current.requires, current::toString);
            for (RequiresDirective dep : current.requires) {
                if (!dep.flags.contains(RequiresFlag.EXTRA))
                    queue = queue.prepend(dep.module);
            }
        }
        if (nonSyntheticDeps.contains(mod.sym)) {
            log.error(rd.moduleName.pos(), Errors.CyclicRequires(rd.directive.module));
        }
        mod.sym.flags_field |= Flags.ACYCLIC;
    }
}
 
Example #29
Source File: JavacProcessingEnvironment.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private List<ClassSymbol> getTopLevelClasses(List<? extends JCCompilationUnit> units) {
    List<ClassSymbol> classes = List.nil();
    for (JCCompilationUnit unit : units) {
        for (JCTree node : unit.defs) {
            if (node.getTag() == JCTree.CLASSDEF) {
                ClassSymbol sym = ((JCClassDecl) node).sym;
                Assert.checkNonNull(sym);
                classes = classes.prepend(sym);
            }
        }
    }
    return classes.reverse();
}
 
Example #30
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());
        }
    }
}