com.sun.tools.javac.resources.CompilerProperties.Errors Java Examples

The following examples show how to use com.sun.tools.javac.resources.CompilerProperties.Errors. 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: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
void checkCaughtType(DiagnosticPosition pos, Type exc, List<Type> thrownInTry, List<Type> caughtInTry) {
    if (chk.subset(exc, caughtInTry)) {
        log.error(pos, Errors.ExceptAlreadyCaught(exc));
    } else if (!chk.isUnchecked(pos, exc) &&
            !isExceptionOrThrowable(exc) &&
            !chk.intersects(exc, thrownInTry)) {
        log.error(pos, Errors.ExceptNeverThrownInTry(exc));
    } else if (allowImprovedCatchAnalysis) {
        List<Type> catchableThrownTypes = chk.intersect(List.of(exc), thrownInTry);
        // 'catchableThrownTypes' cannnot possibly be empty - if 'exc' was an
        // unchecked exception, the result list would not be empty, as the augmented
        // thrown set includes { RuntimeException, Error }; if 'exc' was a checked
        // exception, that would have been covered in the branch above
        if (chk.diff(catchableThrownTypes, caughtInTry).isEmpty() &&
                !isExceptionOrThrowable(exc)) {
            String key = catchableThrownTypes.length() == 1 ?
                    "unreachable.catch" :
                    "unreachable.catch.1";
            log.warning(pos, key, catchableThrownTypes);
        }
    }
}
 
Example #2
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visitRequires(JCRequires tree) {
    ModuleSymbol msym = lookupModule(tree.moduleName);
    if (msym.kind != MDL) {
        log.error(tree.moduleName.pos(), Errors.ModuleNotFound(msym));
        warnedMissing.add(msym);
    } else if (allRequires.contains(msym)) {
        log.error(tree.moduleName.pos(), Errors.DuplicateRequires(msym));
    } else {
        allRequires.add(msym);
        Set<RequiresFlag> flags = EnumSet.noneOf(RequiresFlag.class);
        if (tree.isTransitive)
            flags.add(RequiresFlag.TRANSITIVE);
        if (tree.isStaticPhase)
            flags.add(RequiresFlag.STATIC_PHASE);
        RequiresDirective d = new RequiresDirective(msym, flags);
        tree.directive = d;
        sym.requires = sym.requires.prepend(d);
    }
}
 
Example #3
Source File: JavaCompiler.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/** Resolve an identifier which may be the binary name of a class or
 * the Java name of a class or package.
 * @param name      The name to resolve
 */
public Symbol resolveBinaryNameOrIdent(String name) {
    ModuleSymbol msym;
    String typeName;
    int sep = name.indexOf('/');
    if (sep == -1) {
        msym = modules.getDefaultModule();
        typeName = name;
    } else if (source.allowModules()) {
        Name modName = names.fromString(name.substring(0, sep));

        msym = moduleFinder.findModule(modName);
        typeName = name.substring(sep + 1);
    } else {
        log.error(Errors.InvalidModuleSpecifier(name));
        return silentFail;
    }

    return resolveBinaryNameOrIdent(msym, typeName);
}
 
Example #4
Source File: JavacProcessingEnvironment.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private boolean needClassLoader(String procNames, Iterable<? extends File> workingpath) {
    if (procNames != null)
        return true;

    URL[] urls = new URL[1];
    for(File pathElement : workingpath) {
        try {
            urls[0] = pathElement.toURI().toURL();
            if (ServiceProxy.hasService(Processor.class, urls))
                return true;
        } catch (MalformedURLException ex) {
            throw new AssertionError(ex);
        }
        catch (ServiceProxy.ServiceConfigurationError e) {
            log.error(Errors.ProcBadConfigFile(e.getLocalizedMessage()));
            return true;
        }
    }

    return false;
}
 
Example #5
Source File: Annotate.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Attribute getAnnotationClassValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) {
    Type result = attr.attribTree(tree, env, annotationValueInfo(expectedElementType));
    if (result.isErroneous()) {
        // Does it look like an unresolved class literal?
        if (TreeInfo.name(tree) == names._class &&
                ((JCFieldAccess) tree).selected.type.isErroneous()) {
            Name n = (((JCFieldAccess) tree).selected).type.tsym.flatName();
            return new Attribute.UnresolvedClass(expectedElementType,
                    types.createErrorType(n,
                            syms.unknownSymbol, syms.classType));
        } else {
            return new Attribute.Error(result.getOriginalType());
        }
    }

    // Class literals look like field accesses of a field named class
    // at the tree level
    if (TreeInfo.name(tree) != names._class) {
        log.error(tree.pos(), Errors.AnnotationValueMustBeClassLiteral);
        return new Attribute.Error(syms.errType);
    }

    return new Attribute.Class(types,
            (((JCFieldAccess) tree).selected).type);
}
 
Example #6
Source File: JavaCompiler.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Resolve an identifier which may be the binary name of a class or
 * the Java name of a class or package.
 * @param name      The name to resolve
 */
public Symbol resolveBinaryNameOrIdent(String name) {
    ModuleSymbol msym;
    String typeName;
    int sep = name.indexOf('/');
    if (sep == -1) {
        msym = modules.getDefaultModule();
        typeName = name;
    } else if (source.allowModules()) {
        Name modName = names.fromString(name.substring(0, sep));

        msym = moduleFinder.findModule(modName);
        typeName = name.substring(sep + 1);
    } else {
        log.error(Errors.InvalidModuleSpecifier(name));
        return silentFail;
    }

    return resolveBinaryNameOrIdent(msym, typeName);
}
 
Example #7
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void checkImportedPackagesObservable(final JCCompilationUnit toplevel) {
    OUTER: for (JCImport imp : toplevel.getImports()) {
        if (!imp.staticImport && TreeInfo.name(imp.qualid) == names.asterisk) {
            TypeSymbol tsym = ((JCFieldAccess)imp.qualid).selected.type.tsym;
            if (toplevel.modle.visiblePackages != null) {
                //TODO - unclear: selects like javax.* will get resolved from the current module
                //(as javax is not an exported package from any module). And as javax in the current
                //module typically does not contain any classes or subpackages, we need to go through
                //the visible packages to find a sub-package:
                for (PackageSymbol known : toplevel.modle.visiblePackages.values()) {
                    if (Convert.packagePart(known.fullname) == tsym.flatName())
                        continue OUTER;
                }
            }
            if (tsym.kind == PCK && tsym.members().isEmpty() && !tsym.exists()) {
                log.error(DiagnosticFlag.RESOLVE_ERROR, imp.pos, Errors.DoesntExist(tsym));
            }
        }
    }
}
 
Example #8
Source File: Annotate.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Fetches the actual Type that should be the containing annotation.
 */
private Type getContainingType(Attribute.Compound currentAnno,
                               DiagnosticPosition pos,
                               boolean reportError)
{
    Type origAnnoType = currentAnno.type;
    TypeSymbol origAnnoDecl = origAnnoType.tsym;

    // Fetch the Repeatable annotation from the current
    // annotation's declaration, or null if it has none
    Attribute.Compound ca = origAnnoDecl.getAnnotationTypeMetadata().getRepeatable();
    if (ca == null) { // has no Repeatable annotation
        if (reportError)
            log.error(pos, Errors.DuplicateAnnotationMissingContainer(origAnnoType));
        return null;
    }

    return filterSame(extractContainingType(ca, pos, origAnnoDecl),
            origAnnoType);
}
 
Example #9
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 #10
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void checkImportsResolvable(final JCCompilationUnit toplevel) {
    for (final JCImport imp : toplevel.getImports()) {
        if (!imp.staticImport || !imp.qualid.hasTag(SELECT))
            continue;
        final JCFieldAccess select = (JCFieldAccess) imp.qualid;
        final Symbol origin;
        if (select.name == names.asterisk || (origin = TreeInfo.symbol(select.selected)) == null || origin.kind != TYP)
            continue;

        TypeSymbol site = (TypeSymbol) TreeInfo.symbol(select.selected);
        if (!checkTypeContainsImportableElement(site, site, toplevel.packge, select.name, new HashSet<Symbol>())) {
            log.error(imp.pos(),
                      Errors.CantResolveLocation(KindName.STATIC,
                                                 select.name,
                                                 null,
                                                 null,
                                                 Fragments.Location(kindName(site),
                                                                    site,
                                                                    null)));
        }
    }
}
 
Example #11
Source File: Annotate.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private <T extends Attribute.Compound> T makeContainerAnnotation(List<T> toBeReplaced,
        AnnotationContext<T> ctx, Symbol sym, boolean isTypeParam)
{
    // Process repeated annotations
    T validRepeated =
            processRepeatedAnnotations(toBeReplaced, ctx, sym, isTypeParam);

    if (validRepeated != null) {
        // Check that the container isn't manually
        // present along with repeated instances of
        // its contained annotation.
        ListBuffer<T> manualContainer = ctx.annotated.get(validRepeated.type.tsym);
        if (manualContainer != null) {
            log.error(ctx.pos.get(manualContainer.first()),
                      Errors.InvalidRepeatableAnnotationRepeatedAndContainerPresent(manualContainer.first().type.tsym));
        }
    }

    // A null return will delete the Placeholder
    return validRepeated;
}
 
Example #12
Source File: Check.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/** Check that usage of diamond operator is correct (i.e. diamond should not
 * be used with non-generic classes or in anonymous class creation expressions)
 */
Type checkDiamond(JCNewClass tree, Type t) {
    if (!TreeInfo.isDiamond(tree) ||
            t.isErroneous()) {
        return checkClassType(tree.clazz.pos(), t, true);
    } else {
        if (tree.def != null && !allowDiamondWithAnonymousClassCreation) {
            log.error(DiagnosticFlag.SOURCE_LEVEL, tree.clazz.pos(),
                    Errors.CantApplyDiamond1(t, Fragments.DiamondAndAnonClassNotSupportedInSource(source.name)));
        }
        if (t.tsym.type.getTypeArguments().isEmpty()) {
            log.error(tree.clazz.pos(),
                "cant.apply.diamond.1",
                t, diags.fragment("diamond.non.generic", t));
            return types.createErrorType(t);
        } else if (tree.typeargs != null &&
                tree.typeargs.nonEmpty()) {
            log.error(tree.clazz.pos(),
                "cant.apply.diamond.1",
                t, diags.fragment("diamond.and.explicit.params", t));
            return types.createErrorType(t);
        } else {
            return t;
        }
    }
}
 
Example #13
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Report duplicate declaration error.
 */
void duplicateError(DiagnosticPosition pos, Symbol sym) {
    if (!sym.type.isErroneous()) {
        Symbol location = sym.location();
        if (location.kind == MTH &&
                ((MethodSymbol)location).isStaticOrInstanceInit()) {
            log.error(pos,
                      Errors.AlreadyDefinedInClinit(kindName(sym),
                                                    sym,
                                                    kindName(sym.location()),
                                                    kindName(sym.location().enclClass()),
                                                    sym.location().enclClass()));
        } else {
            log.error(pos,
                      Errors.AlreadyDefined(kindName(sym),
                                            sym,
                                            kindName(sym.location()),
                                            sym.location()));
        }
    }
}
 
Example #14
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
boolean validateTargetAnnotationValue(JCAnnotation a) {
    // special case: java.lang.annotation.Target must not have
    // repeated values in its value member
    if (a.annotationType.type.tsym != syms.annotationTargetType.tsym ||
            a.args.tail == null)
        return true;

    boolean isValid = true;
    if (!a.args.head.hasTag(ASSIGN)) return false; // error recovery
    JCAssign assign = (JCAssign) a.args.head;
    Symbol m = TreeInfo.symbol(assign.lhs);
    if (m.name != names.value) return false;
    JCTree rhs = assign.rhs;
    if (!rhs.hasTag(NEWARRAY)) return false;
    JCNewArray na = (JCNewArray) rhs;
    Set<Symbol> targets = new HashSet<>();
    for (JCTree elem : na.elems) {
        if (!targets.add(TreeInfo.symbol(elem))) {
            isValid = false;
            log.error(elem.pos(), Errors.RepeatedAnnotationTarget);
        }
    }
    return isValid;
}
 
Example #15
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Enter all interfaces of type `type' into the hash table `seensofar'
 *  with their class symbol as key and their type as value. Make
 *  sure no class is entered with two different types.
 */
void checkClassBounds(DiagnosticPosition pos,
                      Map<TypeSymbol,Type> seensofar,
                      Type type) {
    if (type.isErroneous()) return;
    for (List<Type> l = types.interfaces(type); l.nonEmpty(); l = l.tail) {
        Type it = l.head;
        Type oldit = seensofar.put(it.tsym, it);
        if (oldit != null) {
            List<Type> oldparams = oldit.allparams();
            List<Type> newparams = it.allparams();
            if (!types.containsTypeEquivalent(oldparams, newparams))
                log.error(pos,
                          Errors.CantInheritDiffArg(it.tsym,
                                                    Type.toString(oldparams),
                                                    Type.toString(newparams)));
        }
        checkClassBounds(pos, seensofar, it);
    }
    Type st = types.supertype(type);
    if (st != Type.noType) checkClassBounds(pos, seensofar, st);
}
 
Example #16
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Check that all static methods accessible from 'site' are
 *  mutually compatible (JLS 8.4.8).
 *
 *  @param pos  Position to be used for error reporting.
 *  @param site The class whose methods are checked.
 *  @param sym  The method symbol to be checked.
 */
void checkHideClashes(DiagnosticPosition pos, Type site, MethodSymbol sym) {
    ClashFilter cf = new ClashFilter(site);
    //for each method m1 that is a member of 'site'...
    for (Symbol s : types.membersClosure(site, true).getSymbolsByName(sym.name, cf)) {
        //if (i) the signature of 'sym' is not a subsignature of m1 (seen as
        //a member of 'site') and (ii) 'sym' has the same erasure as m1, issue an error
        if (!types.isSubSignature(sym.type, types.memberType(site, s), allowStrictMethodClashCheck)) {
            if (types.hasSameArgs(s.erasure(types), sym.erasure(types))) {
                log.error(pos,
                          Errors.NameClashSameErasureNoHide(sym, sym.location(), s, s.location()));
                return;
            } else {
                checkPotentiallyAmbiguousOverloads(pos, site, sym, (MethodSymbol)s);
            }
        }
     }
 }
 
Example #17
Source File: MemberEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
void checkReceiver(JCVariableDecl tree, Env<AttrContext> localEnv) {
    attr.attribExpr(tree.nameexpr, localEnv);
    MethodSymbol m = localEnv.enclMethod.sym;
    if (m.isConstructor()) {
        Type outertype = m.owner.owner.type;
        if (outertype.hasTag(TypeTag.METHOD)) {
            // we have a local inner class
            outertype = m.owner.owner.owner.type;
        }
        if (outertype.hasTag(TypeTag.CLASS)) {
            checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type");
            checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name");
        } else {
            log.error(tree, Errors.ReceiverParameterNotApplicableConstructorToplevelClass);
        }
    } else {
        checkType(tree.vartype, m.owner.type, "incorrect.receiver.type");
        checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name");
    }
}
 
Example #18
Source File: Annotate.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Pair<MethodSymbol, Attribute> attributeAnnotationNameValuePair(JCExpression nameValuePair,
        Type thisAnnotationType, boolean badAnnotation, Env<AttrContext> env, boolean elidedValue)
{
    if (!nameValuePair.hasTag(ASSIGN)) {
        log.error(nameValuePair.pos(), Errors.AnnotationValueMustBeNameValue);
        attributeAnnotationValue(nameValuePair.type = syms.errType, nameValuePair, env);
        return null;
    }
    JCAssign assign = (JCAssign)nameValuePair;
    if (!assign.lhs.hasTag(IDENT)) {
        log.error(nameValuePair.pos(), Errors.AnnotationValueMustBeNameValue);
        attributeAnnotationValue(nameValuePair.type = syms.errType, nameValuePair, env);
        return null;
    }

    // Resolve element to MethodSym
    JCIdent left = (JCIdent)assign.lhs;
    Symbol method = resolve.resolveQualifiedMethod(elidedValue ? assign.rhs.pos() : left.pos(),
            env, thisAnnotationType,
            left.name, List.nil(), null);
    left.sym = method;
    left.type = method.type;
    if (method.owner != thisAnnotationType.tsym && !badAnnotation)
        log.error(left.pos(), Errors.NoAnnotationMember(left.name, thisAnnotationType));
    Type resultType = method.type.getReturnType();

    // Compute value part
    Attribute value = attributeAnnotationValue(resultType, assign.rhs, env);
    nameValuePair.type = resultType;

    return method.type.isErroneous() ? null : new Pair<>((MethodSymbol)method, value);

}
 
Example #19
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 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 #20
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void validateDocumented(Symbol container, Symbol contained, DiagnosticPosition pos) {
    if (contained.attribute(syms.documentedType.tsym) != null) {
        if (container.attribute(syms.documentedType.tsym) == null) {
            log.error(pos, Errors.InvalidRepeatableAnnotationNotDocumented(container, contained));
        }
    }
}
 
Example #21
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void validateValue(TypeSymbol container, TypeSymbol contained, DiagnosticPosition pos) {
    Symbol sym = container.members().findFirst(names.value);
    if (sym != null && sym.kind == MTH) {
        MethodSymbol m = (MethodSymbol) sym;
        Type ret = m.getReturnType();
        if (!(ret.hasTag(ARRAY) && types.isSameType(((ArrayType)ret).elemtype, contained.type))) {
            log.error(pos,
                      Errors.InvalidRepeatableAnnotationValueReturn(container,
                                                                    ret,
                                                                    types.makeArrayType(contained.type)));
        }
    } else {
        log.error(pos, Errors.InvalidRepeatableAnnotationNoValue(container));
    }
}
 
Example #22
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void validateTypeAnnotation(JCAnnotation a, boolean isTypeParameter) {
    Assert.checkNonNull(a.type);
    validateAnnotationTree(a);

    if (a.hasTag(TYPE_ANNOTATION) &&
            !a.annotationType.type.isErroneous() &&
            !isTypeAnnotation(a, isTypeParameter)) {
        log.error(a.pos(), Errors.AnnotationTypeNotApplicableToType(a.type));
    }
}
 
Example #23
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Check an annotation of a symbol.
 */
private void validateAnnotation(JCAnnotation a, Symbol s) {
    validateAnnotationTree(a);

    if (a.type.tsym.isAnnotationType() && !annotationApplicable(a, s))
        log.error(a.pos(), Errors.AnnotationTypeNotApplicable);

    if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) {
        if (s.kind != TYP) {
            log.error(a.pos(), Errors.BadFunctionalIntfAnno);
        } else if (!s.isInterface() || (s.flags() & ANNOTATION) != 0) {
            log.error(a.pos(), Errors.BadFunctionalIntfAnno1(Fragments.NotAFunctionalIntf(s)));
        }
    }
}
 
Example #24
Source File: TypeEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Import statics types of a given name.  Non-types are handled in Attr.
 *  @param imp           The import that is being handled.
 *  @param tsym          The class from which the name is imported.
 *  @param name          The (simple) name being imported.
 *  @param env           The environment containing the named import
 *                  scope to add to.
 */
private void importNamedStatic(final JCImport imp,
                               final TypeSymbol tsym,
                               final Name name,
                               final Env<AttrContext> env) {
    if (tsym.kind != TYP) {
        log.error(DiagnosticFlag.RECOVERABLE, imp.pos(), Errors.StaticImpOnlyClassesAndInterfaces);
        return;
    }

    final NamedImportScope toScope = env.toplevel.namedImportScope;
    final Scope originMembers = tsym.members();

    imp.importScope = toScope.importByName(types, originMembers, name, staticImportFilter, imp, cfHandler);
}
 
Example #25
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void validateAnnotationType(DiagnosticPosition pos, Type type) {
    if (type.isPrimitive()) return;
    if (types.isSameType(type, syms.stringType)) return;
    if ((type.tsym.flags() & Flags.ENUM) != 0) return;
    if ((type.tsym.flags() & Flags.ANNOTATION) != 0) return;
    if (types.cvarLowerBound(type).tsym == syms.classType.tsym) return;
    if (types.isArray(type) && !types.isArray(types.elemtype(type))) {
        validateAnnotationType(pos, types.elemtype(type));
        return;
    }
    log.error(pos, Errors.InvalidAnnotationMemberType);
}
 
Example #26
Source File: Annotate.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Extract the actual Type to be used for a containing annotation. */
private Type extractContainingType(Attribute.Compound ca,
                                   DiagnosticPosition pos,
                                   TypeSymbol annoDecl)
{
    // The next three checks check that the Repeatable annotation
    // on the declaration of the annotation type that is repeating is
    // valid.

    // Repeatable must have at least one element
    if (ca.values.isEmpty()) {
        log.error(pos, Errors.InvalidRepeatableAnnotation(annoDecl));
        return null;
    }
    Pair<MethodSymbol,Attribute> p = ca.values.head;
    Name name = p.fst.name;
    if (name != names.value) { // should contain only one element, named "value"
        log.error(pos, Errors.InvalidRepeatableAnnotation(annoDecl));
        return null;
    }
    if (!(p.snd instanceof Attribute.Class)) { // check that the value of "value" is an Attribute.Class
        log.error(pos, Errors.InvalidRepeatableAnnotation(annoDecl));
        return null;
    }

    return ((Attribute.Class)p.snd).getValue();
}
 
Example #27
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Similar to makeOwnerThis but will never pick "this".
 */
JCExpression makeOwnerThisN(DiagnosticPosition pos, Symbol sym, boolean preciseMatch) {
    Symbol c = sym.owner;
    List<VarSymbol> ots = outerThisStack;
    if (ots.isEmpty()) {
        log.error(pos, Errors.NoEnclInstanceOfTypeInScope(c));
        Assert.error();
        return makeNull();
    }
    VarSymbol ot = ots.head;
    JCExpression tree = access(make.at(pos).Ident(ot));
    TypeSymbol otc = ot.type.tsym;
    while (!(preciseMatch ? sym.isMemberOf(otc, types) : otc.isSubClass(sym.owner, types))) {
        do {
            ots = ots.tail;
            if (ots.isEmpty()) {
                log.error(pos, Errors.NoEnclInstanceOfTypeInScope(c));
                Assert.error();
                return tree;
            }
            ot = ots.head;
        } while (ot.owner != otc);
        tree = access(make.at(pos).Select(tree, ot));
        otc = ot.type.tsym;
    }
    return tree;
}
 
Example #28
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void checkSourceLocation(JCCompilationUnit tree, ModuleSymbol msym) {
    try {
        JavaFileObject fo = tree.sourcefile;
        if (fileManager.contains(msym.sourceLocation, fo)) {
            return;
        }
        if (msym.patchLocation != null && fileManager.contains(msym.patchLocation, fo)) {
            return;
        }
        if (fileManager.hasLocation(StandardLocation.SOURCE_OUTPUT)) {
            if (fileManager.contains(StandardLocation.SOURCE_OUTPUT, fo)) {
                return;
            }
        } else {
            if (fileManager.contains(StandardLocation.CLASS_OUTPUT, fo)) {
                return;
            }
        }
    } catch (IOException e) {
        throw new Error(e);
    }

    JavaFileObject prev = log.useSource(tree.sourcefile);
    try {
        log.error(tree.pos(), Errors.FileSbOnSourceOrPatchPathForModule);
    } finally {
        log.useSource(prev);
    }
}
 
Example #29
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Note that we found an inheritance cycle. */
private void noteCyclic(DiagnosticPosition pos, ClassSymbol c) {
    log.error(pos, Errors.CyclicInheritance(c));
    for (List<Type> l=types.interfaces(c.type); l.nonEmpty(); l=l.tail)
        l.head = types.createErrorType((ClassSymbol)l.head.tsym, Type.noType);
    Type st = types.supertype(c.type);
    if (st.hasTag(CLASS))
        ((ClassType)c.type).supertype_field = types.createErrorType((ClassSymbol)st.tsym, Type.noType);
    c.type = types.createErrorType(c, c.type);
    c.flags_field |= ACYCLIC;
}
 
Example #30
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private String singleModuleOverride(List<JCCompilationUnit> trees) {
    if (!fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH)) {
        return null;
    }

    Set<String> override = new LinkedHashSet<>();
    for (JCCompilationUnit tree : trees) {
        JavaFileObject fo = tree.sourcefile;

        try {
            Location loc =
                    fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH, fo);

            if (loc != null) {
                override.add(fileManager.inferModuleName(loc));
            }
        } catch (IOException ex) {
            throw new Error(ex);
        }
    }

    switch (override.size()) {
        case 0: return null;
        case 1: return override.iterator().next();
        default:
            log.error(Errors.TooManyPatchedModules(override));
            return null;
    }
}