use of com.sun.tools.javac.code.Type in project RxCache by VictorAlbertos.
the class GetProvidersClass method getMethods.
private List<ProvidersClass.Method> getMethods(Element classElement) throws ValidationException {
List<? extends Element> enclosedElements = classElement.getEnclosedElements();
List<ProvidersClass.Method> methods = new ArrayList<>();
for (Element methodElement : enclosedElements) {
if (!isAnnotatedWithActionable(methodElement))
continue;
if (methodElement.getKind() != ElementKind.METHOD)
continue;
Symbol.MethodSymbol methodSymbol = (Symbol.MethodSymbol) methodElement;
String nameMethod = methodSymbol.getSimpleName().toString();
Type returnType = methodSymbol.getReturnType();
if (!returnType.tsym.toString().equals(TypeName.get(Observable.class).toString())) {
throw new ValidationException(methodSymbol, "Error parsing %s provider. Only Observable<List> type is supported as observable loader", nameMethod);
}
Type enclosingTypeObservable = returnType.getTypeArguments().get(0);
if (!enclosingTypeObservable.tsym.toString().equals(TypeName.get(List.class).toString())) {
throw new ValidationException(methodSymbol, "Error parsing %s provider. Only Observable<List> type is supported as observable loader", nameMethod);
}
List<Symbol.VarSymbol> params = methodSymbol.getParameters();
boolean hasEvictProvider = hasEvictProvider(params);
boolean hasEvictDynamicKey = hasEvictDynamicKey(params);
boolean hasEvictDynamicKeyGroup = hasEvictDynamicKeyGroup(params);
if (!hasEvictProvider && !hasEvictDynamicKey && !hasEvictDynamicKeyGroup) {
throw new ValidationException(methodElement, "Error parsing %s provider. The provider requires one evicting argument: EvictProvider, EvictDynamicKey or EvictDynamicKeyGroup", nameMethod);
}
if (hasEvictProvider && hasEvictDynamicKey) {
throw new ValidationException(methodElement, "Error parsing %s provider. The provider requires one evicting argument: EvictProvider, EvictDynamicKey or EvictDynamicKeyGroup", nameMethod);
}
if (hasEvictProvider && hasEvictDynamicKeyGroup) {
throw new ValidationException(methodElement, "Error parsing %s provider. The provider requires one evicting argument: EvictProvider, EvictDynamicKey or EvictDynamicKeyGroup", nameMethod);
}
if (hasEvictDynamicKey && hasEvictDynamicKeyGroup) {
throw new ValidationException(methodElement, "Error parsing %s provider. The provider requires one evicting argument: EvictProvider, EvictDynamicKey or EvictDynamicKeyGroup", nameMethod);
}
boolean hasDynamicKey = hasDynamicKey(params);
boolean hasDynamicKeyGroup = hasDynamicKeyGroup(params);
methods.add(new ProvidersClass.Method(nameMethod, methodElement, enclosingTypeObservable, hasDynamicKey, hasDynamicKeyGroup));
}
return methods;
}
use of com.sun.tools.javac.code.Type in project lombok by rzwitserloot.
the class FindTypeVarScanner method visitTypeVariable.
@Override
public Void visitTypeVariable(TypeVariable t, Void p) {
Name name = null;
try {
name = ((Type) t).tsym.name;
} catch (NullPointerException e) {
}
if (name != null)
typeVariables.add(name.toString());
subVisit(t.getLowerBound());
subVisit(t.getUpperBound());
return null;
}
use of com.sun.tools.javac.code.Type in project lombok by rzwitserloot.
the class JavacResolution method ifTypeIsIterableToComponent.
public static Type ifTypeIsIterableToComponent(Type type, JavacAST ast) {
Types types = Types.instance(ast.getContext());
Symtab syms = Symtab.instance(ast.getContext());
Type boundType = ReflectiveAccess.Types_upperBound(types, type);
// Type boundType = types.upperBound(type);
Type elemTypeIfArray = types.elemtype(boundType);
if (elemTypeIfArray != null)
return elemTypeIfArray;
Type base = types.asSuper(boundType, syms.iterableType.tsym);
if (base == null)
return syms.objectType;
List<Type> iterableParams = base.allparams();
return iterableParams.isEmpty() ? syms.objectType : ReflectiveAccess.Types_upperBound(types, iterableParams.head);
}
use of com.sun.tools.javac.code.Type in project lombok by rzwitserloot.
the class JavacResolution method typeToJCTree.
private static JCExpression typeToJCTree(Type type, JavacAST ast, boolean allowCompound, boolean allowVoid) throws TypeNotConvertibleException {
int dims = 0;
Type type0 = type;
while (type0 instanceof ArrayType) {
dims++;
type0 = ((ArrayType) type0).elemtype;
}
JCExpression result = typeToJCTree0(type0, ast, allowCompound, allowVoid);
while (dims > 0) {
result = ast.getTreeMaker().TypeArray(result);
dims--;
}
return result;
}
use of com.sun.tools.javac.code.Type in project lombok by rzwitserloot.
the class HandleDelegate method handle.
@Override
public void handle(AnnotationValues<Delegate> annotation, JCAnnotation ast, JavacNode annotationNode) {
handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.DELEGATE_FLAG_USAGE, "@Delegate");
@SuppressWarnings("deprecation") Class<? extends Annotation> oldDelegate = lombok.Delegate.class;
deleteAnnotationIfNeccessary(annotationNode, Delegate.class, oldDelegate);
Type delegateType;
Name delegateName = annotationNode.toName(annotationNode.up().getName());
DelegateReceiver delegateReceiver;
JavacResolution reso = new JavacResolution(annotationNode.getContext());
JCTree member = annotationNode.up().get();
if (annotationNode.up().getKind() == Kind.FIELD) {
if ((((JCVariableDecl) member).mods.flags & Flags.STATIC) != 0) {
annotationNode.addError(LEGALITY_OF_DELEGATE);
return;
}
delegateReceiver = DelegateReceiver.FIELD;
delegateType = member.type;
if (delegateType == null)
reso.resolveClassMember(annotationNode.up());
delegateType = member.type;
} else if (annotationNode.up().getKind() == Kind.METHOD) {
if (!(member instanceof JCMethodDecl)) {
annotationNode.addError(LEGALITY_OF_DELEGATE);
return;
}
JCMethodDecl methodDecl = (JCMethodDecl) member;
if (!methodDecl.params.isEmpty() || (methodDecl.mods.flags & Flags.STATIC) != 0) {
annotationNode.addError(LEGALITY_OF_DELEGATE);
return;
}
delegateReceiver = DelegateReceiver.METHOD;
delegateType = methodDecl.restype.type;
if (delegateType == null)
reso.resolveClassMember(annotationNode.up());
delegateType = methodDecl.restype.type;
} else {
// As the annotation is legal on fields and methods only, javac itself will take care of printing an error message for this.
return;
}
List<Object> delegateTypes = annotation.getActualExpressions("types");
List<Object> excludeTypes = annotation.getActualExpressions("excludes");
List<Type> toDelegate = new ArrayList<Type>();
List<Type> toExclude = new ArrayList<Type>();
if (delegateTypes.isEmpty()) {
if (delegateType != null)
toDelegate.add(delegateType);
} else {
for (Object dt : delegateTypes) {
if (dt instanceof JCFieldAccess && ((JCFieldAccess) dt).name.toString().equals("class")) {
Type type = ((JCFieldAccess) dt).selected.type;
if (type == null)
reso.resolveClassMember(annotationNode);
type = ((JCFieldAccess) dt).selected.type;
if (type != null)
toDelegate.add(type);
}
}
}
for (Object et : excludeTypes) {
if (et instanceof JCFieldAccess && ((JCFieldAccess) et).name.toString().equals("class")) {
Type type = ((JCFieldAccess) et).selected.type;
if (type == null)
reso.resolveClassMember(annotationNode);
type = ((JCFieldAccess) et).selected.type;
if (type != null)
toExclude.add(type);
}
}
List<MethodSig> signaturesToDelegate = new ArrayList<MethodSig>();
List<MethodSig> signaturesToExclude = new ArrayList<MethodSig>();
Set<String> banList = new HashSet<String>();
banList.addAll(METHODS_IN_OBJECT);
try {
for (Type t : toExclude) {
if (t instanceof ClassType) {
ClassType ct = (ClassType) t;
addMethodBindings(signaturesToExclude, ct, annotationNode.getTypesUtil(), banList);
} else {
annotationNode.addError("@Delegate can only use concrete class types, not wildcards, arrays, type variables, or primitives.");
return;
}
}
for (MethodSig sig : signaturesToExclude) {
banList.add(printSig(sig.type, sig.name, annotationNode.getTypesUtil()));
}
for (Type t : toDelegate) {
if (t instanceof ClassType) {
ClassType ct = (ClassType) t;
addMethodBindings(signaturesToDelegate, ct, annotationNode.getTypesUtil(), banList);
} else {
annotationNode.addError("@Delegate can only use concrete class types, not wildcards, arrays, type variables, or primitives.");
return;
}
}
for (MethodSig sig : signaturesToDelegate) generateAndAdd(sig, annotationNode, delegateName, delegateReceiver);
} catch (DelegateRecursion e) {
annotationNode.addError(String.format(RECURSION_NOT_ALLOWED, e.member, e.type));
}
}
Aggregations