com.sun.tools.javac.code.Symbol.TypeSymbol Java Examples
The following examples show how to use
com.sun.tools.javac.code.Symbol.TypeSymbol.
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: Annotate.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 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, Errors.DuplicateAnnotationMissingContainer(origAnnoType)); return null; } return filterSame(extractContainingType(ca, pos, origAnnoDecl), origAnnoType); }
Example #2
Source File: JavacTrees.java From hottub with GNU General Public License v2.0 | 6 votes |
public JCTree getTree(Element element) { Symbol symbol = (Symbol) element; TypeSymbol enclosing = symbol.enclClass(); Env<AttrContext> env = enter.getEnv(enclosing); if (env == null) return null; JCClassDecl classNode = env.enclClass; if (classNode != null) { if (TreeInfo.symbolFor(classNode) == element) return classNode; for (JCTree node : classNode.getMembers()) if (TreeInfo.symbolFor(node) == element) return node; } return null; }
Example #3
Source File: LambdaToMethod.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public void visitNewClass(JCNewClass tree) { TypeSymbol def = tree.type.tsym; boolean inReferencedClass = currentlyInClass(def); boolean isLocal = def.isLocal(); if ((inReferencedClass && isLocal || lambdaNewClassFilter(context(), tree))) { TranslationContext<?> localContext = context(); while (localContext != null) { if (localContext.tree.getTag() == LAMBDA) { ((LambdaTranslationContext)localContext) .addSymbol(tree.type.getEnclosingType().tsym, CAPTURED_THIS); } localContext = localContext.prev; } } if (context() != null && !inReferencedClass && isLocal) { LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context(); captureLocalClassDefs(def, lambdaContext); } super.visitNewClass(tree); }
Example #4
Source File: Type.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) { super(CLASS, tsym); this.outer_field = outer; this.typarams_field = typarams; this.allparams_field = null; this.supertype_field = null; this.interfaces_field = null; /* // this can happen during error recovery assert outer.isParameterized() ? typarams.length() == tsym.type.typarams().length() : outer.isRaw() ? typarams.length() == 0 : true; */ }
Example #5
Source File: JavacTrees.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
public JCTree getTree(Element element) { Symbol symbol = (Symbol) element; TypeSymbol enclosing = symbol.enclClass(); Env<AttrContext> env = enter.getEnv(enclosing); if (env == null) return null; JCClassDecl classNode = env.enclClass; if (classNode != null) { if (TreeInfo.symbolFor(classNode) == element) return classNode; for (JCTree node : classNode.getMembers()) if (TreeInfo.symbolFor(node) == element) return node; } return null; }
Example #6
Source File: Symtab.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** Create a new toplevel or member class symbol with given name * and owner and enter in `classes' unless already there. */ public ClassSymbol enterClass(ModuleSymbol msym, Name name, TypeSymbol owner) { Assert.checkNonNull(msym); Name flatname = TypeSymbol.formFlatName(name, owner); ClassSymbol c = getClass(msym, flatname); if (c == null) { c = defineClass(name, owner); doEnterClass(msym, c); } else if ((c.name != name || c.owner != owner) && owner.kind == TYP && c.owner.kind == PCK) { // reassign fields of classes that might have been loaded with // their flat names. c.owner.members().remove(c); c.name = name; c.owner = owner; c.fullname = ClassSymbol.formFullName(name, owner); } return c; }
Example #7
Source File: LambdaToMethod.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public void visitNewClass(JCNewClass tree) { TypeSymbol def = tree.type.tsym; boolean inReferencedClass = currentlyInClass(def); boolean isLocal = def.isLocal(); if ((inReferencedClass && isLocal || lambdaNewClassFilter(context(), tree))) { TranslationContext<?> localContext = context(); while (localContext != null) { if (localContext.tree.getTag() == LAMBDA) { ((LambdaTranslationContext)localContext) .addSymbol(tree.type.getEnclosingType().tsym, CAPTURED_THIS); } localContext = localContext.prev; } } if (context() != null && !inReferencedClass && isLocal) { LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context(); captureLocalClassDefs(def, lambdaContext); } super.visitNewClass(tree); }
Example #8
Source File: JavacTrees.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public JCTree getTree(Element element) { Symbol symbol = (Symbol) element; TypeSymbol enclosing = symbol.enclClass(); Env<AttrContext> env = enter.getEnv(enclosing); if (env == null) return null; JCClassDecl classNode = env.enclClass; if (classNode != null) { if (TreeInfo.symbolFor(classNode) == element) return classNode; for (JCTree node : classNode.getMembers()) if (TreeInfo.symbolFor(node) == element) return node; } return null; }
Example #9
Source File: PostFlowAnalysis.java From netbeans with Apache License 2.0 | 6 votes |
private void checkThis(DiagnosticPosition pos, TypeSymbol c) { if (checkThis && currentClass != c) { List<Pair<TypeSymbol, Symbol>> ots = outerThisStack; if (ots.isEmpty()) { log.error(pos, new Error("compiler", "no.encl.instance.of.type.in.scope", c)); //NOI18N return; } Pair<TypeSymbol, Symbol> ot = ots.head; TypeSymbol otc = ot.fst; while (otc != c) { do { ots = ots.tail; if (ots.isEmpty()) { log.error(pos, new Error("compiler", "no.encl.instance.of.type.in.scope", c)); //NOI18N return; } ot = ots.head; } while (ot.snd != otc); if (otc.owner.kind != Kinds.Kind.PCK && !otc.hasOuterInstance()) { log.error(pos, new Error("compiler", "cant.ref.before.ctor.called", c)); //NOI18N return; } otc = ot.fst; } } }
Example #10
Source File: LambdaToMethod.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public void visitNewClass(JCNewClass tree) { TypeSymbol def = tree.type.tsym; boolean inReferencedClass = currentlyInClass(def); boolean isLocal = def.isLocal(); if ((inReferencedClass && isLocal || lambdaNewClassFilter(context(), tree))) { TranslationContext<?> localContext = context(); while (localContext != null) { if (localContext.tree.getTag() == LAMBDA) { ((LambdaTranslationContext)localContext) .addSymbol(tree.type.getEnclosingType().tsym, CAPTURED_THIS); } localContext = localContext.prev; } } if (context() != null && !inReferencedClass && isLocal) { LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context(); captureLocalClassDefs(def, lambdaContext); } super.visitNewClass(tree); }
Example #11
Source File: Scope.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public Iterable<Symbol> getSymbols(final Filter<Symbol> sf, final LookupKind lookupKind) { if (filterName != null) return getSymbolsByName(filterName, sf, lookupKind); try { SymbolImporter si = new SymbolImporter(imp.staticImport) { @Override Iterable<Symbol> doLookup(TypeSymbol tsym) { return tsym.members().getSymbols(sf, lookupKind); } }; List<Iterable<Symbol>> results = si.importFrom((TypeSymbol) origin.owner, List.nil()); return () -> createFilterIterator(createCompoundIterator(results, Iterable::iterator), s -> filter.accepts(origin, s)); } catch (CompletionFailure cf) { cfHandler.accept(imp, cf); return Collections.emptyList(); } }
Example #12
Source File: Scope.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public Iterable<Symbol> getSymbolsByName(final Name name, final Filter<Symbol> sf, final LookupKind lookupKind) { if (filterName != null && filterName != name) return Collections.emptyList(); try { SymbolImporter si = new SymbolImporter(imp.staticImport) { @Override Iterable<Symbol> doLookup(TypeSymbol tsym) { return tsym.members().getSymbolsByName(name, sf, lookupKind); } }; List<Iterable<Symbol>> results = si.importFrom((TypeSymbol) origin.owner, List.nil()); return () -> createFilterIterator(createCompoundIterator(results, Iterable::iterator), s -> filter.accepts(origin, s)); } catch (CompletionFailure cf) { cfHandler.accept(imp, cf); return Collections.emptyList(); } }
Example #13
Source File: JavacTrees.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public JCTree getTree(Element element) { Symbol symbol = (Symbol) element; TypeSymbol enclosing = symbol.enclClass(); Env<AttrContext> env = enter.getEnv(enclosing); if (env == null) return null; JCClassDecl classNode = env.enclClass; if (classNode != null) { if (TreeInfo.symbolFor(classNode) == element) return classNode; for (JCTree node : classNode.getMembers()) if (TreeInfo.symbolFor(node) == element) return node; } return null; }
Example #14
Source File: UTemplater.java From Refaster with Apache License 2.0 | 6 votes |
@Override public UTypeVar visitTypeVar(TypeVar type, Void v) { /* * In order to handle recursively bounded type variables without a stack overflow, we first * cache a type var with no bounds, then we template the bounds. */ TypeSymbol tsym = type.asElement(); if (typeVariables.containsKey(tsym)) { return typeVariables.get(tsym); } UTypeVar var = UTypeVar.create(tsym.getSimpleName().toString()); typeVariables.put(tsym, var); // so the type variable can be used recursively in the bounds var.setLowerBound(type.getLowerBound().accept(this, null)); var.setUpperBound(type.getUpperBound().accept(this, null)); return var; }
Example #15
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void visitSelect(JCFieldAccess tree) { // need to special case-access of the form C.super.x // these will always need an access method, unless C // is a default interface subclassed by the current class. boolean qualifiedSuperAccess = tree.selected.hasTag(SELECT) && TreeInfo.name(tree.selected) == names._super && !types.isDirectSuperInterface(((JCFieldAccess)tree.selected).selected.type.tsym, currentClass); tree.selected = translate(tree.selected); if (tree.name == names._class) { result = classOf(tree.selected); } else if (tree.name == names._super && types.isDirectSuperInterface(tree.selected.type.tsym, currentClass)) { //default super call!! Not a classic qualified super call TypeSymbol supSym = tree.selected.type.tsym; Assert.checkNonNull(types.asSuper(currentClass.type, supSym)); result = tree; } else if (tree.name == names._this || tree.name == names._super) { result = makeThis(tree.pos(), tree.selected.type.tsym); } else result = access(tree.sym, tree, enclOp, qualifiedSuperAccess); }
Example #16
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
private boolean checkTypeContainsImportableElement(TypeSymbol tsym, TypeSymbol origin, PackageSymbol packge, Name name, Set<Symbol> processed) { if (tsym == null || !processed.add(tsym)) return false; // also search through inherited names if (checkTypeContainsImportableElement(types.supertype(tsym.type).tsym, origin, packge, name, processed)) return true; for (Type t : types.interfaces(tsym.type)) if (checkTypeContainsImportableElement(t.tsym, origin, packge, name, processed)) return true; for (Symbol sym : tsym.members().getSymbolsByName(name)) { if (sym.isStatic() && importAccessible(sym, packge) && sym.isMemberOf(origin, types)) { return true; } } return false; }
Example #17
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #18
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #19
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void checkFunctionalInterface(JCClassDecl tree, ClassSymbol cs) { Compound functionalType = cs.attribute(syms.functionalInterfaceType.tsym); if (functionalType != null) { try { types.findDescriptorSymbol((TypeSymbol)cs); } catch (Types.FunctionDescriptorLookupError ex) { DiagnosticPosition pos = tree.pos(); for (JCAnnotation a : tree.getModifiers().annotations) { if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { pos = a.pos(); break; } } log.error(pos, Errors.BadFunctionalIntfAnno1(ex.getDiagnostic())); } } }
Example #20
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
void checkNonCyclicElementsInternal(DiagnosticPosition pos, TypeSymbol tsym) { if ((tsym.flags_field & ACYCLIC_ANN) != 0) return; if ((tsym.flags_field & LOCKED) != 0) { log.error(pos, Errors.CyclicAnnotationElement(tsym)); return; } try { tsym.flags_field |= LOCKED; for (Symbol s : tsym.members().getSymbols(NON_RECURSIVE)) { if (s.kind != MTH) continue; checkAnnotationResType(pos, ((MethodSymbol)s).type.getReturnType()); } } finally { tsym.flags_field &= ~LOCKED; tsym.flags_field |= ACYCLIC_ANN; } }
Example #21
Source File: PostFlowAnalysis.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void visitClassDef(JCClassDecl tree) { TypeSymbol currentClassPrev = currentClass; currentClass = tree.sym; List<Pair<TypeSymbol, Symbol>> prevOuterThisStack = outerThisStack; try { if (currentClass != null) { if (currentClass.hasOuterInstance()) outerThisDef(currentClass); super.visitClassDef(tree); } } finally { outerThisStack = prevOuterThisStack; currentClass = currentClassPrev; } }
Example #22
Source File: LambdaToMethod.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public void visitNewClass(JCNewClass tree) { TypeSymbol def = tree.type.tsym; boolean inReferencedClass = currentlyInClass(def); boolean isLocal = def.isLocal(); if ((inReferencedClass && isLocal || lambdaNewClassFilter(context(), tree))) { TranslationContext<?> localContext = context(); final TypeSymbol outerInstanceSymbol = tree.type.getEnclosingType().tsym; while (localContext != null && !localContext.owner.isStatic()) { if (localContext.tree.hasTag(LAMBDA)) { if (outerInstanceSymbol != null) { JCTree block = capturedDecl(localContext.depth, outerInstanceSymbol); if (block == null) break; } ((LambdaTranslationContext)localContext) .addSymbol(outerInstanceSymbol, CAPTURED_THIS); } localContext = localContext.prev; } } if (context() != null && !inReferencedClass && isLocal) { LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context(); captureLocalClassDefs(def, lambdaContext); } super.visitNewClass(tree); }
Example #23
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 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 #24
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
boolean checkCommonOverriderIn(Symbol s1, Symbol s2, Type site) { Map<TypeSymbol,Type> supertypes = new HashMap<>(); Type st1 = types.memberType(site, s1); Type st2 = types.memberType(site, s2); closure(site, supertypes); for (Type t : supertypes.values()) { for (Symbol s3 : t.tsym.members().getSymbolsByName(s1.name)) { if (s3 == s1 || s3 == s2 || s3.kind != MTH || (s3.flags() & (BRIDGE|SYNTHETIC)) != 0) continue; Type st3 = types.memberType(site,s3); if (types.overrideEquivalent(st3, st1) && types.overrideEquivalent(st3, st2) && types.returnTypeSubstitutable(st3, st1) && types.returnTypeSubstitutable(st3, st2)) { return true; } } } return false; }
Example #25
Source File: ElementUtilities.java From netbeans with Apache License 2.0 | 5 votes |
/** * Find the element of the method descriptor associated to the functional interface. * * @param origin functional interface element * @return associated method descriptor element or <code>null</code> if the <code>origin</code> is not a functional interface. * @since 2.14 */ public ExecutableElement getDescriptorElement(TypeElement origin) { com.sun.tools.javac.code.Types types = com.sun.tools.javac.code.Types.instance(info.impl.getJavacTask().getContext()); if (types.isFunctionalInterface((TypeSymbol)origin)) { Symbol sym = types.findDescriptorSymbol((TypeSymbol)origin); if (sym != null && sym.getKind() == ElementKind.METHOD) { return (ExecutableElement)sym; } } return null; }
Example #26
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
void checkConflicts(DiagnosticPosition pos, Symbol sym, TypeSymbol c) { for (Type ct = c.type; ct != Type.noType ; ct = types.supertype(ct)) { for (Symbol sym2 : ct.tsym.members().getSymbolsByName(sym.name, NON_RECURSIVE)) { // VM allows methods and variables with differing types if (sym.kind == sym2.kind && types.isSameType(types.erasure(sym.type), types.erasure(sym2.type)) && sym != sym2 && (sym.flags() & Flags.SYNTHETIC) != (sym2.flags() & Flags.SYNTHETIC) && (sym.flags() & BRIDGE) == 0 && (sym2.flags() & BRIDGE) == 0) { syntheticError(pos, (sym2.flags() & SYNTHETIC) == 0 ? sym2 : sym); return; } } } }
Example #27
Source File: ElementsService.java From netbeans with Apache License 2.0 | 5 votes |
public Element getImplementationOf(ExecutableElement method, TypeElement origin) { MethodSymbol msym = (MethodSymbol)method; MethodSymbol implmethod = (msym).implementation((TypeSymbol)origin, jctypes, true); if ((msym.flags() & Flags.STATIC) != 0) { // return null if outside of hierarchy, or the method itself if origin extends method's class if (jctypes.isSubtype(((TypeSymbol)origin).type, ((TypeSymbol)((MethodSymbol)method).owner).type)) { return method; } else { return null; } } if (implmethod == null || implmethod == method) { //look for default implementations if (allowDefaultMethods) { com.sun.tools.javac.util.List<MethodSymbol> candidates = jctypes.interfaceCandidates(((TypeSymbol) origin).type, (MethodSymbol) method); X: for (com.sun.tools.javac.util.List<MethodSymbol> ptr = candidates; ptr.head != null; ptr = ptr.tail) { MethodSymbol prov = ptr.head; if (prov != null && prov.overrides((MethodSymbol) method, (TypeSymbol) origin, jctypes, true) && hasImplementation(prov)) { // PENDING: even if `prov' overrides the method, there may be a different method, in different interface, that overrides `method' // 'prov' must override all such compatible methods in order to present a valid implementation of `method'. for (com.sun.tools.javac.util.List<MethodSymbol> sibling = candidates; sibling.head != null; sibling = sibling.tail) { MethodSymbol redeclare = sibling.head; // if the default method does not override the alternative candidate from an interface, then the default will be rejected // as specified in JLS #8, par. 8.4.8 if (!prov.overrides(redeclare, (TypeSymbol)origin, jctypes, allowDefaultMethods)) { break X; } } implmethod = prov; break; } } } } return implmethod; }
Example #28
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #29
Source File: Enter.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Env<AttrContext> getClassEnv(TypeSymbol sym) { Env<AttrContext> localEnv = getEnv(sym); if (localEnv == null) return null; Env<AttrContext> lintEnv = localEnv; while (lintEnv.info.lint == null) lintEnv = lintEnv.next; localEnv.info.lint = lintEnv.info.lint.augment(sym); return localEnv; }
Example #30
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Compute all the supertypes of t, indexed by type symbol. */ private void closure(Type t, Map<TypeSymbol,Type> typeMap) { if (!t.hasTag(CLASS)) return; if (typeMap.put(t.tsym, t) == null) { closure(types.supertype(t), typeMap); for (Type i : types.interfaces(t)) closure(i, typeMap); } }