/** Returns an enclosing instance for the specified type if it is thread-safe. */ public Type mutableEnclosingInstance(Optional<ClassTree> tree, ClassType type) { if (tree.isPresent() && !CanBeStaticAnalyzer.referencesOuter( tree.get(), ASTHelpers.getSymbol(tree.get()), state)) { return null; } Type enclosing = type.getEnclosingType(); while (!Type.noType.equals(enclosing)) { if (getMarkerOrAcceptedAnnotation(enclosing.tsym, state) == null && isThreadSafeType( /* allowContainerTypeParameters= */ false, /* containerTypeParameters= */ ImmutableSet.of(), enclosing) .isPresent()) { return enclosing; } enclosing = enclosing.getEnclosingType(); } return null; }
Type enclosing = tree.type.getEnclosingType(); if (enclosing != null) { enclosing.accept(new TypeVariableScanner(), null);
private <T extends Symbol> T getMember( Class<T> type, ElementKind kind, Symbol classSymbol, String name) { if (classSymbol.type == null) { return null; } for (Type t : types.closure(classSymbol.type)) { Scope scope = t.tsym.members(); for (Symbol sym : scope.getSymbolsByName(getName(name))) { if (sym.getKind().equals(kind)) { return type.cast(sym); } } } if (classSymbol.hasOuterInstance()) { T sym = getMember(type, kind, classSymbol.type.getEnclosingType().asElement(), name); if (sym != null) { return sym; } } if (classSymbol.owner != null && classSymbol != classSymbol.owner && classSymbol.owner instanceof Symbol.ClassSymbol) { T sym = getMember(type, kind, classSymbol.owner, name); if (sym != null && sym.isStatic()) { return sym; } } return null; }
calledType = calledType.getEnclosingType(); tyargIndex = findTypeArgInList(encloser, typeArgName); if (tyargIndex != -1) {
/** A class is an inner class if it it has an enclosing instance class. */ public boolean isInner() { return type.getEnclosingType().tag == CLASS; }
/** A class is an inner class if it it has an enclosing instance class. */ public boolean isInner() { return type.getEnclosingType().hasTag(CLASS); }
/** Enter type variables of this classtype and all enclosing ones in * `typevars'. */ protected void enterTypevars(Type t) { if (t.getEnclosingType() != null && t.getEnclosingType().tag == CLASS) enterTypevars(t.getEnclosingType()); for (List<Type> xs = t.getTypeArguments(); xs.nonEmpty(); xs = xs.tail) typevars.enter(xs.head.tsym); }
/** Enter type variables of this classtype and all enclosing ones in * `typevars'. */ protected void enterTypevars(Type t) { if (t.getEnclosingType() != null && t.getEnclosingType().tag == CLASS) enterTypevars(t.getEnclosingType()); for (List<Type> xs = t.getTypeArguments(); xs.nonEmpty(); xs = xs.tail) typevars.enter(xs.head.tsym); }
@Override JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { return diags.create(dkind, log.currentSource(), pos, "cant.access.inner.cls.constr", site.tsym.name, argtypes, site.getEnclosingType()); } };
/** An inner class has an outer instance if it is not an interface * it has an enclosing instance class which might be referenced from the class. * Nested classes can see instance members of their enclosing class. * Their constructors carry an additional this$n parameter, inserted * implicitly by the compiler. * * @see #isInner */ public boolean hasOuterInstance() { return type.getEnclosingType().hasTag(CLASS) && (flags() & (INTERFACE | NOOUTERTHIS)) == 0; }
public Type erasure(Types types) { if (erasure_field == null) erasure_field = new ClassType(types.erasure(type.getEnclosingType()), List.<Type>nil(), this); return erasure_field; }
public Type erasure(Types types) { if (erasure_field == null) erasure_field = new ClassType(types.erasure(type.getEnclosingType()), List.<Type>nil(), this); return erasure_field; }
/** * Resolve an appropriate implicit this instance for t's container. * JLS2 8.8.5.1 and 15.9.2 */ Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t) { Type thisType = (((t.tsym.owner.kind & (MTH|VAR)) != 0) ? resolveSelf(pos, env, t.getEnclosingType().tsym, names._this) : resolveSelfContaining(pos, env, t.tsym)).type; if (env.info.isSelfCall && thisType.tsym == env.enclClass.sym) log.error(pos, "cant.ref.before.ctor.called", "this"); return thisType; }
Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t, boolean isSuperCall) { Type thisType = (((t.tsym.owner.kind & (MTH|VAR)) != 0) ? resolveSelf(pos, env, t.getEnclosingType().tsym, names._this) : resolveSelfContaining(pos, env, t.tsym, isSuperCall)).type; if (env.info.isSelfCall && thisType.tsym == env.enclClass.sym) log.error(pos, "cant.ref.before.ctor.called", "this"); return thisType; }
private void outerThisDef(Symbol owner) { Type target = types.erasure(owner.enclClass().type.getEnclosingType()); Pair<TypeSymbol, Symbol> outerThis = Pair.of(target.tsym, owner); outerThisStack = outerThisStack.prepend(outerThis); }
public void visitSelectInternal(JCFieldAccess tree) { if (tree.type.getEnclosingType().tag != CLASS && tree.selected.type.isParameterized()) { // The enclosing type is not a class, so we are // looking at a static member type. However, the // qualifying expression is parameterized. log.error(tree.pos(), "cant.select.static.class.from.param.type"); } else { // otherwise validate the rest of the expression validate(tree.selected); } }
@Override public void visitNewClass(JCNewClass tree) { super.visitNewClass(tree); Symbol c = tree.constructor != null ? tree.constructor.owner : null; if (c != null && c.hasOuterInstance()) { if (tree.encl == null && c.isLocal()) { checkThis(tree.pos(), c.type.getEnclosingType().tsym); } } }
static Type makeClassType(Types types, Type type) { Type arg = type.isPrimitive() ? types.boxedClass(type).type : types.erasure(type); return new Type.ClassType(types.syms.classType.getEnclosingType(), List.of(arg), types.syms.classType.tsym); } public String toString() {
static Type makeClassType(Types types, Type type) { Type arg = type.isPrimitive() ? types.boxedClass(type).type : types.erasure(type); return new Type.ClassType(types.syms.classType.getEnclosingType(), List.of(arg), types.syms.classType.tsym); } public String toString() {
private VarSymbol makeOuterThisVarSymbol(Symbol owner, long flags) { if (owner.kind == TYP && target.usePrivateSyntheticFields()) flags |= PRIVATE; Type target = types.erasure(owner.enclClass().type.getEnclosingType()); VarSymbol outerThis = new VarSymbol(flags, outerThisName(target, owner), target, owner); outerThisStack = outerThisStack.prepend(outerThis); return outerThis; }