com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition Java Examples

The following examples show how to use com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition. 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 Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: Check.java    License: GNU General Public License v2.0 6 votes vote down vote up
void checkConflicts(DiagnosticPosition pos, Symbol sym, TypeSymbol c) {
    for (Type ct = c.type; ct != Type.noType ; ct = types.supertype(ct)) {
        for (Scope.Entry e = ct.tsym.members().lookup(sym.name); e.scope == ct.tsym.members(); e = e.next()) {
            // VM allows methods and variables with differing types
            if (sym.kind == e.sym.kind &&
                types.isSameType(types.erasure(sym.type), types.erasure(e.sym.type)) &&
                sym != e.sym &&
                (sym.flags() & Flags.SYNTHETIC) != (e.sym.flags() & Flags.SYNTHETIC) &&
                (sym.flags() & IPROXY) == 0 && (e.sym.flags() & IPROXY) == 0 &&
                (sym.flags() & BRIDGE) == 0 && (e.sym.flags() & BRIDGE) == 0) {
                syntheticError(pos, (e.sym.flags() & SYNTHETIC) == 0 ? e.sym : sym);
                return;
            }
        }
    }
}
 
Example #2
Source Project: javaide   Author: tranleduy2000   File: Check.java    License: GNU General Public License v3.0 6 votes vote down vote up
/** Return the first method which is defined with same args
 *  but different return types in two given interfaces, or null if none
 *  exists.
 *  @param t1     The first type.
 *  @param t2     The second type.
 *  @param site   The most derived type.
 *  @returns symbol from t2 that conflicts with one in t1.
 */
private Symbol firstIncompatibility(DiagnosticPosition pos, Type t1, Type t2, Type site) {
    Map<TypeSymbol,Type> interfaces1 = new HashMap<TypeSymbol,Type>();
    closure(t1, interfaces1);
    Map<TypeSymbol,Type> interfaces2;
    if (t1 == t2)
        interfaces2 = interfaces1;
    else
        closure(t2, interfaces1, interfaces2 = new HashMap<TypeSymbol,Type>());

    for (Type t3 : interfaces1.values()) {
        for (Type t4 : interfaces2.values()) {
            Symbol s = firstDirectIncompatibility(pos, t3, t4, site);
            if (s != null) return s;
        }
    }
    return null;
}
 
Example #3
Source Project: javaide   Author: tranleduy2000   File: Check.java    License: GNU General Public License v3.0 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).getElementsByName(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), false) &&
                types.hasSameArgs(s.erasure(types), sym.erasure(types))) {
            log.error(pos,
                    "name.clash.same.erasure.no.hide",
                    sym, sym.location(),
                    s, s.location());
            return;
         }
     }
 }
 
Example #4
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: Check.java    License: Apache License 2.0 6 votes vote down vote up
/** Check that all abstract members of given class have definitions.
 *  @param pos          Position to be used for error reporting.
 *  @param c            The class.
 */
void checkAllDefined(DiagnosticPosition pos, ClassSymbol c) {
    try {
        MethodSymbol undef = firstUndef(c, c);
        if (undef != null) {
            if ((c.flags() & ENUM) != 0 &&
                types.supertype(c.type).tsym == syms.enumSym &&
                (c.flags() & FINAL) == 0) {
                // add the ABSTRACT flag to an enum
                c.flags_field |= ABSTRACT;
            } else {
                MethodSymbol undef1 =
                    new MethodSymbol(undef.flags(), undef.name,
                                     types.memberType(c.type, undef), undef.owner);
                log.error(pos, "does.not.override.abstract",
                          c, undef1, undef1.location());
            }
        }
    } catch (CompletionFailure ex) {
        completionError(pos, ex);
    }
}
 
Example #5
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Check.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** Check that single-type import is not already imported or top-level defined,
 *  but make an exception for two single-type imports which denote the same type.
 *  @param pos           Position for error reporting.
 *  @param sym           The symbol.
 *  @param s             The scope.
 *  @param staticImport  Whether or not this was a static import
 */
private boolean checkUniqueImport(DiagnosticPosition pos, Symbol sym, Scope s, boolean staticImport) {
    for (Scope.Entry e = s.lookup(sym.name); e.scope != null; e = e.next()) {
        // is encountered class entered via a class declaration?
        boolean isClassDecl = e.scope == s;
        if ((isClassDecl || sym != e.sym) &&
            sym.kind == e.sym.kind &&
            sym.name != names.error &&
            (!staticImport || !e.isStaticallyImported())) {
            if (!e.sym.type.isErroneous()) {
                if (!isClassDecl) {
                    if (staticImport)
                        log.error(pos, "already.defined.static.single.import", e.sym);
                    else
                    log.error(pos, "already.defined.single.import", e.sym);
                }
                else if (sym != e.sym)
                    log.error(pos, "already.defined.this.unit", e.sym);
            }
            return false;
        }
    }
    return true;
}
 
Example #6
Source Project: openjdk-8   Author: bpupadhyaya   File: Check.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** Return the first method which is defined with same args
 *  but different return types in two given interfaces, or null if none
 *  exists.
 *  @param t1     The first type.
 *  @param t2     The second type.
 *  @param site   The most derived type.
 *  @returns symbol from t2 that conflicts with one in t1.
 */
private Symbol firstIncompatibility(DiagnosticPosition pos, Type t1, Type t2, Type site) {
    Map<TypeSymbol,Type> interfaces1 = new HashMap<TypeSymbol,Type>();
    closure(t1, interfaces1);
    Map<TypeSymbol,Type> interfaces2;
    if (t1 == t2)
        interfaces2 = interfaces1;
    else
        closure(t2, interfaces1, interfaces2 = new HashMap<TypeSymbol,Type>());

    for (Type t3 : interfaces1.values()) {
        for (Type t4 : interfaces2.values()) {
            Symbol s = firstDirectIncompatibility(pos, t3, t4, site);
            if (s != null) return s;
        }
    }
    return null;
}
 
Example #7
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Annotate.java    License: GNU General Public License v2.0 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, "duplicate.annotation.missing.container", origAnnoType, syms.repeatableType);
        return null;
    }

    return filterSame(extractContainingType(ca, pos, origAnnoDecl),
            origAnnoType);
}
 
Example #8
Source Project: TencentKona-8   Author: Tencent   File: Check.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** Return the first method which is defined with same args
 *  but different return types in two given interfaces, or null if none
 *  exists.
 *  @param t1     The first type.
 *  @param t2     The second type.
 *  @param site   The most derived type.
 *  @returns symbol from t2 that conflicts with one in t1.
 */
private Symbol firstIncompatibility(DiagnosticPosition pos, Type t1, Type t2, Type site) {
    Map<TypeSymbol,Type> interfaces1 = new HashMap<TypeSymbol,Type>();
    closure(t1, interfaces1);
    Map<TypeSymbol,Type> interfaces2;
    if (t1 == t2)
        interfaces2 = interfaces1;
    else
        closure(t2, interfaces1, interfaces2 = new HashMap<TypeSymbol,Type>());

    for (Type t3 : interfaces1.values()) {
        for (Type t4 : interfaces2.values()) {
            Symbol s = firstDirectIncompatibility(pos, t3, t4, site);
            if (s != null) return s;
        }
    }
    return null;
}
 
Example #9
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Annotate.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visitVarDef(JCVariableDecl tree) {
    DiagnosticPosition prevPos = deferPos;
    deferPos = tree.pos();
    try {
        if (sym != null && sym.kind == VAR) {
            // Don't visit a parameter once when the sym is the method
            // and once when the sym is the parameter.
            scan(tree.mods);
            scan(tree.vartype);
        }
        scan(tree.init);
    } finally {
        deferPos = prevPos;
    }
}
 
Example #10
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: Resolve.java    License: Apache License 2.0 6 votes vote down vote up
/** Resolve constructor.
 *  @param pos       The position to use for error reporting.
 *  @param env       The environment current at the constructor invocation.
 *  @param site      The type of class for which a constructor is searched.
 *  @param argtypes  The types of the constructor invocation's value
 *                   arguments.
 *  @param typeargtypes  The types of the constructor invocation's type
 *                   arguments.
 */
Symbol resolveConstructor(DiagnosticPosition pos,
                          Env<AttrContext> env,
                          Type site,
                          List<Type> argtypes,
                          List<Type> typeargtypes) {
    Symbol sym = startResolution();
    List<MethodResolutionPhase> steps = methodResolutionSteps;
    while (steps.nonEmpty() &&
           steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
           sym.kind >= ERRONEOUS) {
        currentStep = steps.head;
        sym = resolveConstructor(pos, env, site, argtypes, typeargtypes,
                steps.head.isBoxingRequired(),
                env.info.varArgs = steps.head.isVarargsRequired());
        methodResolutionCache.put(steps.head, sym);
        steps = steps.tail;
    }
    if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
        MethodResolutionPhase errPhase = firstErroneousResolutionPhase();
        sym = access(methodResolutionCache.get(errPhase),
                pos, site, names.init, true, argtypes, typeargtypes);
        env.info.varArgs = errPhase.isVarargsRequired();
    }
    return sym;
}
 
Example #11
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: Check.java    License: Apache License 2.0 6 votes vote down vote up
/** Check that single-type import is not already imported or top-level defined,
 *  but make an exception for two single-type imports which denote the same type.
 *  @param pos           Position for error reporting.
 *  @param sym           The symbol.
 *  @param s             The scope.
 *  @param staticImport  Whether or not this was a static import
 */
private boolean checkUniqueImport(DiagnosticPosition pos, Symbol sym, Scope s, boolean staticImport) {
    for (Scope.Entry e = s.lookup(sym.name); e.scope != null; e = e.next()) {
        // is encountered class entered via a class declaration?
        boolean isClassDecl = e.scope == s;
        if ((isClassDecl || sym != e.sym) &&
            sym.kind == e.sym.kind &&
            sym.name != names.error) {
            if (!e.sym.type.isErroneous()) {
                String what = e.sym.toString();
                if (!isClassDecl) {
                    if (staticImport)
                        log.error(pos, "already.defined.static.single.import", what);
                    else
                        log.error(pos, "already.defined.single.import", what);
                }
                else if (sym != e.sym)
                    log.error(pos, "already.defined.this.unit", what);
            }
            return false;
        }
    }
    return true;
}
 
Example #12
Source Project: openjdk-8-source   Author: keerath   File: Flow.java    License: GNU General Public License v2.0 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, "except.already.caught", exc);
    } else if (!chk.isUnchecked(pos, exc) &&
            !isExceptionOrThrowable(exc) &&
            !chk.intersects(exc, thrownInTry)) {
        log.error(pos, "except.never.thrown.in.try", 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 #13
Source Project: TencentKona-8   Author: Tencent   File: Check.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate the proposed container 'repeatable' on the
 * annotation type symbol 's'. Report errors at position
 * 'pos'.
 *
 * @param s The (annotation)type declaration annotated with a @Repeatable
 * @param repeatable the @Repeatable on 's'
 * @param pos where to report errors
 */
public void validateRepeatable(TypeSymbol s, Attribute.Compound repeatable, DiagnosticPosition pos) {
    Assert.check(types.isSameType(repeatable.type, syms.repeatableType));

    Type t = null;
    List<Pair<MethodSymbol,Attribute>> l = repeatable.values;
    if (!l.isEmpty()) {
        Assert.check(l.head.fst.name == names.value);
        t = ((Attribute.Class)l.head.snd).getValue();
    }

    if (t == null) {
        // errors should already have been reported during Annotate
        return;
    }

    validateValue(t.tsym, s, pos);
    validateRetention(t.tsym, s, pos);
    validateDocumented(t.tsym, s, pos);
    validateInherited(t.tsym, s, pos);
    validateTarget(t.tsym, s, pos);
    validateDefault(t.tsym, pos);
}
 
Example #14
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: Gen.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Check if the given type is an array with too many dimensions.
 */
private void checkDimension(DiagnosticPosition pos, Type t) {
    switch (t.tag) {
        case METHOD:
            checkDimension(pos, t.getReturnType());
            for (List<Type> args = t.getParameterTypes(); args.nonEmpty(); args = args.tail)
                checkDimension(pos, args.head);
            break;
        case ARRAY:
            if (types.dimensions(t) > ClassFile.MAX_DIMENSIONS) {
                log.error(pos, "limit.dimensions");
                nerrs++;
            }
            break;
        default:
            break;
    }
}
 
Example #15
Source Project: openjdk-8   Author: bpupadhyaya   File: Check.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** Check that a class or interface does not hide a class or
 *  interface with same name in immediately enclosing local scope.
 *  @param pos           Position for error reporting.
 *  @param c             The symbol.
 *  @param s             The scope.
 */
void checkTransparentClass(DiagnosticPosition pos, ClassSymbol c, Scope s) {
    if (s.next != null) {
        for (Scope.Entry e = s.next.lookup(c.name);
             e.scope != null && e.sym.owner == c.owner;
             e = e.next()) {
            if (e.sym.kind == TYP && !e.sym.type.hasTag(TYPEVAR) &&
                (e.sym.owner.kind & (VAR | MTH)) != 0 &&
                c.name != names.error) {
                duplicateError(pos, e.sym);
                return;
            }
        }
    }
}
 
Example #16
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: Check.java    License: Apache License 2.0 5 votes vote down vote up
void checkAnnotationResType(DiagnosticPosition pos, Type type) {
    switch (type.tag) {
    case TypeTags.CLASS:
        if ((type.tsym.flags() & ANNOTATION) != 0)
            checkNonCyclicElementsInternal(pos, type.tsym);
        break;
    case TypeTags.ARRAY:
        checkAnnotationResType(pos, types.elemtype(type));
        break;
    default:
        break; // int etc
    }
}
 
Example #17
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: Flow.java    License: Apache License 2.0 5 votes vote down vote up
/** Check that trackable variable is initialized.
 */
void checkInit(DiagnosticPosition pos, VarSymbol sym) {
    if ((sym.adr >= firstadr || sym.owner.kind != TYP) &&
        trackable(sym) &&
        !inits.isMember(sym.adr)) {
        log.error(pos, "var.might.not.have.been.initialized",
                  sym);
        inits.incl(sym.adr);
    }
}
 
Example #18
Source Project: openjdk-8-source   Author: keerath   File: Check.java    License: GNU General Public License v2.0 5 votes vote down vote up
void checkDefaultMethodClashes(DiagnosticPosition pos, Type site) {
    DefaultMethodClashFilter dcf = new DefaultMethodClashFilter(site);
    for (Symbol m : types.membersClosure(site, false).getElements(dcf)) {
        Assert.check(m.kind == MTH);
        List<MethodSymbol> prov = types.interfaceCandidates(site, (MethodSymbol)m);
        if (prov.size() > 1) {
            ListBuffer<Symbol> abstracts = new ListBuffer<>();
            ListBuffer<Symbol> defaults = new ListBuffer<>();
            for (MethodSymbol provSym : prov) {
                if ((provSym.flags() & DEFAULT) != 0) {
                    defaults = defaults.append(provSym);
                } else if ((provSym.flags() & ABSTRACT) != 0) {
                    abstracts = abstracts.append(provSym);
                }
                if (defaults.nonEmpty() && defaults.size() + abstracts.size() >= 2) {
                    //strong semantics - issue an error if two sibling interfaces
                    //have two override-equivalent defaults - or if one is abstract
                    //and the other is default
                    String errKey;
                    Symbol s1 = defaults.first();
                    Symbol s2;
                    if (defaults.size() > 1) {
                        errKey = "types.incompatible.unrelated.defaults";
                        s2 = defaults.toList().tail.head;
                    } else {
                        errKey = "types.incompatible.abstract.default";
                        s2 = abstracts.first();
                    }
                    log.error(pos, errKey,
                            Kinds.kindName(site.tsym), site,
                            m.name, types.memberType(site, m).getParameterTypes(),
                            s1.location(), s2.location());
                    break;
                }
            }
        }
    }
}
 
Example #19
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Annotate.java    License: GNU General Public License v2.0 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, "invalid.repeatable.annotation", 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, "invalid.repeatable.annotation", annoDecl);
        return null;
    }
    if (!(p.snd instanceof Attribute.Class)) { // check that the value of "value" is an Attribute.Class
        log.error(pos, "invalid.repeatable.annotation", annoDecl);
        return null;
    }

    return ((Attribute.Class)p.snd).getValue();
}
 
Example #20
Source Project: jdk8u60   Author: chenghanpeng   File: Check.java    License: GNU General Public License v2.0 5 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, "already.defined.in.clinit", kindName(sym), sym,
                    kindName(sym.location()), kindName(sym.location().enclClass()),
                    sym.location().enclClass());
        } else {
            log.error(pos, "already.defined", kindName(sym), sym,
                    kindName(sym.location()), sym.location());
        }
    }
}
 
Example #21
Source Project: openjdk-8-source   Author: keerath   File: Check.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** Check that a class or interface does not hide a class or
 *  interface with same name in immediately enclosing local scope.
 *  @param pos           Position for error reporting.
 *  @param c             The symbol.
 *  @param s             The scope.
 */
void checkTransparentClass(DiagnosticPosition pos, ClassSymbol c, Scope s) {
    if (s.next != null) {
        for (Scope.Entry e = s.next.lookup(c.name);
             e.scope != null && e.sym.owner == c.owner;
             e = e.next()) {
            if (e.sym.kind == TYP && !e.sym.type.hasTag(TYPEVAR) &&
                (e.sym.owner.kind & (VAR | MTH)) != 0 &&
                c.name != names.error) {
                duplicateError(pos, e.sym);
                return;
            }
        }
    }
}
 
Example #22
Source Project: openjdk-8-source   Author: keerath   File: Resolve.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void reportMC(DiagnosticPosition pos, MethodCheckDiag diag, InferenceContext inferenceContext, Object... args) {
    boolean inferDiag = inferenceContext != infer.emptyContext;
    InapplicableMethodException ex = inferDiag ?
            infer.inferenceException : inapplicableMethodException;
    if (inferDiag && (!diag.inferKey.equals(diag.basicKey))) {
        Object[] args2 = new Object[args.length + 1];
        System.arraycopy(args, 0, args2, 1, args.length);
        args2[0] = inferenceContext.inferenceVars();
        args = args2;
    }
    String key = inferDiag ? diag.inferKey : diag.basicKey;
    throw ex.setMessage(diags.create(DiagnosticType.FRAGMENT, log.currentSource(), pos, key, args));
}
 
Example #23
Source Project: jdk8u60   Author: chenghanpeng   File: Resolve.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Resolve `c.this' for an enclosing class c that contains the
 * named member.
 * @param pos           The position to use for error reporting.
 * @param env           The environment current at the expression.
 * @param member        The member that must be contained in the result.
 */
Symbol resolveSelfContaining(DiagnosticPosition pos,
                             Env<AttrContext> env,
                             Symbol member,
                             boolean isSuperCall) {
    Symbol sym = resolveSelfContainingInternal(env, member, isSuperCall);
    if (sym == null) {
        log.error(pos, "encl.class.required", member);
        return syms.errSymbol;
    } else {
        return accessBase(sym, pos, env.enclClass.sym.type, sym.name, true);
    }
}
 
Example #24
Source Project: hottub   Author: dsrg-uoft   File: Check.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** Check that variable does not hide variable with same name in
 *  immediately enclosing local scope.
 *  @param pos           Position for error reporting.
 *  @param v             The symbol.
 *  @param s             The scope.
 */
void checkTransparentVar(DiagnosticPosition pos, VarSymbol v, Scope s) {
    if (s.next != null) {
        for (Scope.Entry e = s.next.lookup(v.name);
             e.scope != null && e.sym.owner == v.owner;
             e = e.next()) {
            if (e.sym.kind == VAR &&
                (e.sym.owner.kind & (VAR | MTH)) != 0 &&
                v.name != names.error) {
                duplicateError(pos, e.sym);
                return;
            }
        }
    }
}
 
Example #25
Source Project: jdk8u60   Author: chenghanpeng   File: Check.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** Check that a class or interface does not hide a class or
 *  interface with same name in immediately enclosing local scope.
 *  @param pos           Position for error reporting.
 *  @param c             The symbol.
 *  @param s             The scope.
 */
void checkTransparentClass(DiagnosticPosition pos, ClassSymbol c, Scope s) {
    if (s.next != null) {
        for (Scope.Entry e = s.next.lookup(c.name);
             e.scope != null && e.sym.owner == c.owner;
             e = e.next()) {
            if (e.sym.kind == TYP && !e.sym.type.hasTag(TYPEVAR) &&
                (e.sym.owner.kind & (VAR | MTH)) != 0 &&
                c.name != names.error) {
                duplicateError(pos, e.sym);
                return;
            }
        }
    }
}
 
Example #26
Source Project: hottub   Author: dsrg-uoft   File: Check.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** Note that we found an inheritance cycle. */
private void noteCyclic(DiagnosticPosition pos, ClassSymbol c) {
    log.error(pos, "cyclic.inheritance", 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 #27
Source Project: TencentKona-8   Author: Tencent   File: Check.java    License: GNU General Public License v2.0 5 votes vote down vote up
Type checkClassOrArrayType(DiagnosticPosition pos, Type t) {
    if (!t.hasTag(CLASS) && !t.hasTag(ARRAY) && !t.hasTag(ERROR)) {
        return typeTagError(pos,
                            diags.fragment("type.req.class.array"),
                            asTypeParam(t));
    } else {
        return t;
    }
}
 
Example #28
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Check.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** Check that an auxiliary class is not accessed from any other file than its own.
 */
void checkForBadAuxiliaryClassAccess(DiagnosticPosition pos, Env<AttrContext> env, ClassSymbol c) {
    if (lint.isEnabled(Lint.LintCategory.AUXILIARYCLASS) &&
        (c.flags() & AUXILIARY) != 0 &&
        rs.isAccessible(env, c) &&
        !fileManager.isSameFile(c.sourcefile, env.toplevel.sourcefile))
    {
        log.warning(pos, "auxiliary.class.accessed.from.outside.of.its.source.file",
                    c, c.sourcefile);
    }
}
 
Example #29
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Check.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** Check that variable does not hide variable with same name in
 *  immediately enclosing local scope.
 *  @param pos           Position for error reporting.
 *  @param v             The symbol.
 *  @param s             The scope.
 */
void checkTransparentVar(DiagnosticPosition pos, VarSymbol v, Scope s) {
    if (s.next != null) {
        for (Scope.Entry e = s.next.lookup(v.name);
             e.scope != null && e.sym.owner == v.owner;
             e = e.next()) {
            if (e.sym.kind == VAR &&
                (e.sym.owner.kind & (VAR | MTH)) != 0 &&
                v.name != names.error) {
                duplicateError(pos, e.sym);
                return;
            }
        }
    }
}
 
Example #30
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Check.java    License: GNU General Public License v2.0 5 votes vote down vote up
void checkDefaultMethodClashes(DiagnosticPosition pos, Type site) {
    DefaultMethodClashFilter dcf = new DefaultMethodClashFilter(site);
    for (Symbol m : types.membersClosure(site, false).getElements(dcf)) {
        Assert.check(m.kind == MTH);
        List<MethodSymbol> prov = types.interfaceCandidates(site, (MethodSymbol)m);
        if (prov.size() > 1) {
            ListBuffer<Symbol> abstracts = new ListBuffer<>();
            ListBuffer<Symbol> defaults = new ListBuffer<>();
            for (MethodSymbol provSym : prov) {
                if ((provSym.flags() & DEFAULT) != 0) {
                    defaults = defaults.append(provSym);
                } else if ((provSym.flags() & ABSTRACT) != 0) {
                    abstracts = abstracts.append(provSym);
                }
                if (defaults.nonEmpty() && defaults.size() + abstracts.size() >= 2) {
                    //strong semantics - issue an error if two sibling interfaces
                    //have two override-equivalent defaults - or if one is abstract
                    //and the other is default
                    String errKey;
                    Symbol s1 = defaults.first();
                    Symbol s2;
                    if (defaults.size() > 1) {
                        errKey = "types.incompatible.unrelated.defaults";
                        s2 = defaults.toList().tail.head;
                    } else {
                        errKey = "types.incompatible.abstract.default";
                        s2 = abstracts.first();
                    }
                    log.error(pos, errKey,
                            Kinds.kindName(site.tsym), site,
                            m.name, types.memberType(site, m).getParameterTypes(),
                            s1.location(), s2.location());
                    break;
                }
            }
        }
    }
}