use of com.sun.tools.javac.code.Type.ClassType in project ceylon-compiler by ceylon.
the class Attr method selectSym.
private Symbol selectSym(JCFieldAccess tree, Symbol location, Type site, Env<AttrContext> env, Type pt, int pkind) {
DiagnosticPosition pos = tree.pos();
Name name = tree.name;
switch(site.tag) {
case PACKAGE:
return rs.access(rs.findIdentInPackage(env, site.tsym, name, pkind), pos, location, site, name, true);
case ARRAY:
case CLASS:
if (pt.tag == METHOD || pt.tag == FORALL) {
return rs.resolveQualifiedMethod(pos, env, location, site, name, pt.getParameterTypes(), pt.getTypeArguments());
} else if (name == names._this || name == names._super) {
return rs.resolveSelf(pos, env, site.tsym, name);
} else if (name == names._class) {
// In this case, we have already made sure in
// visitSelect that qualifier expression is a type.
Type t = syms.classType;
List<Type> typeargs = allowGenerics ? List.of(types.erasure(site)) : List.<Type>nil();
t = new ClassType(t.getEnclosingType(), typeargs, t.tsym);
return new VarSymbol(STATIC | PUBLIC | FINAL, names._class, t, site.tsym);
} else {
// We are seeing a plain identifier as selector.
Symbol sym = rs.findIdentInType(env, site, name, pkind);
if ((pkind & ERRONEOUS) == 0)
sym = rs.access(sym, pos, location, site, name, true);
return sym;
}
case WILDCARD:
throw new AssertionError(tree);
case TYPEVAR:
// Normally, site.getUpperBound() shouldn't be null.
// It should only happen during memberEnter/attribBase
// when determining the super type which *must* beac
// done before attributing the type variables. In
// other words, we are seeing this illegal program:
// class B<T> extends A<T.foo> {}
Symbol sym = (site.getUpperBound() != null) ? selectSym(tree, location, capture(site.getUpperBound()), env, pt, pkind) : null;
if (sym == null) {
log.error(pos, "type.var.cant.be.deref");
return syms.errSymbol;
} else {
// Ceylon: relax the rules for private methods in wildcards, damnit, we want the private
// method to be called, not any subtype's method we can't possibly know about, this is really
// a lame Java decision.
Symbol sym2 = (!sourceLanguage.isCeylon() && (sym.flags() & Flags.PRIVATE) != 0) ? rs.new AccessError(env, site, sym) : sym;
rs.access(sym2, pos, location, site, name, true);
return sym;
}
case ERROR:
// preserve identifier names through errors
return types.createErrorType(name, site.tsym, site).tsym;
default:
// .class is allowed for these.
if (name == names._class) {
// In this case, we have already made sure in Select that
// qualifier expression is a type.
Type t = syms.classType;
Type arg = types.boxedClass(site).type;
t = new ClassType(t.getEnclosingType(), List.of(arg), t.tsym);
return new VarSymbol(STATIC | PUBLIC | FINAL, names._class, t, site.tsym);
} else {
log.error(pos, "cant.deref", site);
return syms.errSymbol;
}
}
}
use of com.sun.tools.javac.code.Type.ClassType in project ceylon-compiler by ceylon.
the class CeylonEnter method resetClassSymbol.
/**
* This resets a ClassSymbol recursively, for bootstrap
*/
private void resetClassSymbol(ClassSymbol classSymbol) {
// look for inner classes
if (classSymbol.members_field != null) {
for (Symbol member : classSymbol.getEnclosedElements()) {
if (member instanceof ClassSymbol) {
resetClassSymbol((ClassSymbol) member);
}
}
}
// reset its type, we need to keep it
com.sun.tools.javac.code.Type.ClassType classType = (ClassType) classSymbol.type;
classType.all_interfaces_field = null;
classType.interfaces_field = null;
classType.supertype_field = null;
classType.typarams_field = null;
// reset its members and completer
classSymbol.members_field = null;
classSymbol.completer = null;
classSymbol.attributes_field = List.nil();
}
use of com.sun.tools.javac.code.Type.ClassType in project error-prone by google.
the class ImmutableAnalysis method isFieldImmutable.
/** Check a single field for immutability. */
private Violation isFieldImmutable(Optional<Tree> tree, ImmutableSet<String> immutableTyParams, ClassSymbol classSym, ClassType classType, VarSymbol var) {
if (bugChecker.isSuppressed(var)) {
return Violation.absent();
}
if (ASTHelpers.hasAnnotation(var, LazyInit.class, state)) {
return Violation.absent();
}
if (!var.getModifiers().contains(Modifier.FINAL)) {
if (tree.isPresent()) {
// If we have a tree to attach diagnostics to, report the error immediately instead of
// accumulating the path to the error from the top-level class being checked
state.reportMatch(BugChecker.buildDescriptionFromChecker(tree.get(), bugChecker).setMessage(nonFinalFieldMessage).addFix(SuggestedFixes.addModifiers(tree.get(), state, Modifier.FINAL)).build());
return Violation.absent();
}
return Violation.of(String.format("'%s' has non-final field '%s'", getPrettyName(classSym), var.getSimpleName()));
}
Type varType = state.getTypes().memberType(classType, var);
Violation info = isImmutableType(immutableTyParams, varType);
if (info.isPresent()) {
if (tree.isPresent()) {
// If we have a tree to attach diagnostics to, report the error immediately instead of
// accumulating the path to the error from the top-level class being checked
state.reportMatch(BugChecker.buildDescriptionFromChecker(tree.get(), bugChecker).setMessage(info.plus(mutableFieldMessage).message()).build());
return Violation.absent();
}
return info.plus(String.format("'%s' has field '%s' of type '%s'", getPrettyName(classSym), var.getSimpleName(), varType));
}
return Violation.absent();
}
use of com.sun.tools.javac.code.Type.ClassType in project error-prone by google.
the class ImmutableAnalysis method checkForImmutability.
/**
* Check that an {@code @Immutable}-annotated class:
*
* <ul>
* <li>does not declare or inherit any mutable fields,
* <li>any immutable supertypes are instantiated with immutable type arguments as required by
* their containerOf spec, and
* <li>any enclosing instances are immutable.
* </ul>
*
* requiring supertypes to be annotated immutable would be too restrictive.
*/
Violation checkForImmutability(Optional<ClassTree> tree, ImmutableSet<String> immutableTyParams, ClassType type) {
Violation info = areFieldsImmutable(tree, immutableTyParams, type);
if (info.isPresent()) {
return info;
}
for (Type interfaceType : state.getTypes().interfaces(type)) {
ImmutableAnnotationInfo interfaceAnnotation = getImmutableAnnotation(interfaceType.tsym);
if (interfaceAnnotation == null) {
continue;
}
info = immutableInstantiation(immutableTyParams, interfaceAnnotation, interfaceType);
if (info.isPresent()) {
return info.plus(String.format("'%s' extends '%s'", getPrettyName(type.tsym), getPrettyName(interfaceType.tsym)));
}
}
info = checkSuper(immutableTyParams, type);
if (info.isPresent()) {
return info;
}
Type mutableEnclosing = mutableEnclosingInstance(tree, type);
if (mutableEnclosing != null) {
return info.plus(String.format("'%s' has mutable enclosing instance '%s'", getPrettyName(type.tsym), mutableEnclosing));
}
return Violation.absent();
}
use of com.sun.tools.javac.code.Type.ClassType in project lombok by rzwitserloot.
the class HandleExtensionMethod method getExtensions.
public List<Extension> getExtensions(final JavacNode typeNode, final List<Object> extensionProviders) {
List<Extension> extensions = new ArrayList<Extension>();
for (Object extensionProvider : extensionProviders) {
if (!(extensionProvider instanceof JCFieldAccess))
continue;
JCFieldAccess provider = (JCFieldAccess) extensionProvider;
if (!("class".equals(provider.name.toString())))
continue;
Type providerType = CLASS.resolveMember(typeNode, provider.selected);
if (providerType == null)
continue;
if ((providerType.tsym.flags() & (INTERFACE | ANNOTATION)) != 0)
continue;
extensions.add(getExtension(typeNode, (ClassType) providerType));
}
return extensions;
}
Aggregations