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 File: Resolve.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** 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 #2
Source File: Check.java From javaide with GNU General Public License v3.0 | 6 votes |
/** 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 File: Check.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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 #4
Source File: Flow.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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 #5
Source File: Check.java From javaide with GNU General Public License v3.0 | 6 votes |
/** 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 #6
Source File: Gen.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** * 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 #7
Source File: Check.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * 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 #8
Source File: Check.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** 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 #9
Source File: Check.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** 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 #10
Source File: Check.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** 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 #11
Source File: Check.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** 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 #12
Source File: Annotate.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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 #13
Source File: Check.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** 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 #14
Source File: Annotate.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@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 #15
Source File: Check.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** 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 File: Check.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** 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 #17
Source File: Check.java From hottub with GNU General Public License v2.0 | 5 votes |
/** 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 #18
Source File: Flow.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
/** 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 #19
Source File: Resolve.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** Resolve a qualified method identifier, throw a fatal error if not * found. * @param pos The position to use for error reporting. * @param env The environment current at the method invocation. * @param site The type of the qualifying expression, in which * identifier is searched. * @param name The identifier's name. * @param argtypes The types of the invocation's value arguments. * @param typeargtypes The types of the invocation's type arguments. */ public MethodSymbol resolveInternalMethod(DiagnosticPosition pos, Env<AttrContext> env, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { MethodResolutionContext resolveContext = new MethodResolutionContext(); resolveContext.internalResolution = true; Symbol sym = resolveQualifiedMethod(resolveContext, pos, env, site.tsym, site, name, argtypes, typeargtypes); if (sym.kind == MTH) return (MethodSymbol)sym; else throw new FatalError( diags.fragment("fatal.err.cant.locate.meth", name)); }
Example #20
Source File: Check.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
void checkSunAPI(final DiagnosticPosition pos, final Symbol s) { if ((s.flags() & PROPRIETARY) != 0) { deferredLintHandler.report(new DeferredLintHandler.LintLogger() { public void report() { if (enableSunApiLintControl) warnSunApi(pos, "sun.proprietary", s); else log.strictWarning(pos, "sun.proprietary", s); } }); } }
Example #21
Source File: Check.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
void checkDeprecatedAnnotation(DiagnosticPosition pos, Symbol s) { if (allowAnnotations && lint.isEnabled(LintCategory.DEP_ANN) && (s.flags() & DEPRECATED) != 0 && !syms.deprecatedType.isErroneous() && s.attribute(syms.deprecatedType.tsym) == null) { log.warning(LintCategory.DEP_ANN, pos, "missing.deprecated.annotation"); } }
Example #22
Source File: Check.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** 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 #23
Source File: MemberEnter.java From hottub with GNU General Public License v2.0 | 5 votes |
void annotateTypeLater(final List<JCAnnotation> annotations) { if (annotations.isEmpty()) { return; } final DiagnosticPosition deferPos = this.deferPos; annotate.normal(new Annotate.Worker() { @Override public String toString() { return "type annotate " + annotations + " onto " + sym + " in " + sym.owner; } @Override public void run() { JavaFileObject prev = log.useSource(env.toplevel.sourcefile); DiagnosticPosition prevLintPos = null; if (deferPos != null) { prevLintPos = deferredLintHandler.setPos(deferPos); } try { actualEnterTypeAnnotations(annotations, env, sym); } finally { if (prevLintPos != null) deferredLintHandler.setPos(prevLintPos); log.useSource(prev); } } }); }
Example #24
Source File: Check.java From hottub with GNU General Public License v2.0 | 5 votes |
/** 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 #25
Source File: Check.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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 #26
Source File: Resolve.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) { if (sym.kind >= AMBIGUOUS) { //if nothing is found return the 'first' error sym = accessMethod(sym, pos, location, site, name, true, argtypes, typeargtypes); } return sym; }
Example #27
Source File: Check.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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 #28
Source File: Check.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** 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 #29
Source File: Check.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** 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 #30
Source File: Annotate.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** 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(); }