use of lombok.eclipse.EclipseAST in project lombok by rzwitserloot.
the class PatchDelegate method fillMethodBindingsForFields.
private static void fillMethodBindingsForFields(CompilationUnitDeclaration cud, ClassScope scope, List<BindingTuple> methodsToDelegate) {
TypeDeclaration decl = scope.referenceContext;
if (decl == null)
return;
if (decl.fields != null)
for (FieldDeclaration field : decl.fields) {
if (field.annotations == null)
continue;
for (Annotation ann : field.annotations) {
if (!isDelegate(ann, decl))
continue;
if (Annotation_applied.getAndSet(ann, true))
continue;
if ((field.modifiers & ClassFileConstants.AccStatic) != 0) {
EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true);
eclipseAst.get(ann).addError(LEGALITY_OF_DELEGATE);
break;
}
List<ClassLiteralAccess> rawTypes = rawTypes(ann, "types");
List<ClassLiteralAccess> excludedRawTypes = rawTypes(ann, "excludes");
List<BindingTuple> methodsToExclude = new ArrayList<BindingTuple>();
List<BindingTuple> methodsToDelegateForThisAnn = new ArrayList<BindingTuple>();
try {
for (ClassLiteralAccess cla : excludedRawTypes) {
addAllMethodBindings(methodsToExclude, cla.type.resolveType(decl.initializerScope), new HashSet<String>(), field.name, ann);
}
Set<String> banList = new HashSet<String>();
for (BindingTuple excluded : methodsToExclude) banList.add(printSig(excluded.parameterized));
if (rawTypes.isEmpty()) {
addAllMethodBindings(methodsToDelegateForThisAnn, field.type.resolveType(decl.initializerScope), banList, field.name, ann);
} else {
for (ClassLiteralAccess cla : rawTypes) {
addAllMethodBindings(methodsToDelegateForThisAnn, cla.type.resolveType(decl.initializerScope), banList, field.name, ann);
}
}
} catch (DelegateRecursion e) {
EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true);
eclipseAst.get(ann).addError(String.format(RECURSION_NOT_ALLOWED, new String(e.member), new String(e.type)));
break;
}
// Not doing this right now because of problems - see commented-out-method for info.
// removeExistingMethods(methodsToDelegate, decl, scope);
String dupe = containsDuplicates(methodsToDelegateForThisAnn);
if (dupe != null) {
EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true);
eclipseAst.get(ann).addError("The method '" + dupe + "' is being delegated by more than one specified type.");
} else {
methodsToDelegate.addAll(methodsToDelegateForThisAnn);
}
}
}
}
use of lombok.eclipse.EclipseAST in project lombok by rzwitserloot.
the class PatchDelegate method fillMethodBindingsForMethods.
private static void fillMethodBindingsForMethods(CompilationUnitDeclaration cud, ClassScope scope, List<BindingTuple> methodsToDelegate) {
TypeDeclaration decl = scope.referenceContext;
if (decl == null)
return;
if (decl.methods != null)
for (AbstractMethodDeclaration methodDecl : decl.methods) {
if (methodDecl.annotations == null)
continue;
for (Annotation ann : methodDecl.annotations) {
if (!isDelegate(ann, decl))
continue;
if (Annotation_applied.getAndSet(ann, true))
continue;
if (!(methodDecl instanceof MethodDeclaration)) {
EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true);
eclipseAst.get(ann).addError(LEGALITY_OF_DELEGATE);
break;
}
if (methodDecl.arguments != null) {
EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true);
eclipseAst.get(ann).addError(LEGALITY_OF_DELEGATE);
break;
}
if ((methodDecl.modifiers & ClassFileConstants.AccStatic) != 0) {
EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true);
eclipseAst.get(ann).addError(LEGALITY_OF_DELEGATE);
break;
}
MethodDeclaration method = (MethodDeclaration) methodDecl;
List<ClassLiteralAccess> rawTypes = rawTypes(ann, "types");
List<ClassLiteralAccess> excludedRawTypes = rawTypes(ann, "excludes");
List<BindingTuple> methodsToExclude = new ArrayList<BindingTuple>();
List<BindingTuple> methodsToDelegateForThisAnn = new ArrayList<BindingTuple>();
try {
for (ClassLiteralAccess cla : excludedRawTypes) {
addAllMethodBindings(methodsToExclude, cla.type.resolveType(decl.initializerScope), new HashSet<String>(), method.selector, ann);
}
Set<String> banList = new HashSet<String>();
for (BindingTuple excluded : methodsToExclude) banList.add(printSig(excluded.parameterized));
if (rawTypes.isEmpty()) {
if (method.returnType == null)
continue;
addAllMethodBindings(methodsToDelegateForThisAnn, method.returnType.resolveType(decl.initializerScope), banList, method.selector, ann);
} else {
for (ClassLiteralAccess cla : rawTypes) {
addAllMethodBindings(methodsToDelegateForThisAnn, cla.type.resolveType(decl.initializerScope), banList, method.selector, ann);
}
}
} catch (DelegateRecursion e) {
EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true);
eclipseAst.get(ann).addError(String.format(RECURSION_NOT_ALLOWED, new String(e.member), new String(e.type)));
break;
}
// Not doing this right now because of problems - see commented-out-method for info.
// removeExistingMethods(methodsToDelegate, decl, scope);
String dupe = containsDuplicates(methodsToDelegateForThisAnn);
if (dupe != null) {
EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true);
eclipseAst.get(ann).addError("The method '" + dupe + "' is being delegated by more than one specified type.");
} else {
methodsToDelegate.addAll(methodsToDelegateForThisAnn);
}
}
}
}
use of lombok.eclipse.EclipseAST in project lombok by rzwitserloot.
the class PatchDelegate method handleDelegateForType.
public static boolean handleDelegateForType(ClassScope scope) {
if (TransformEclipseAST.disableLombok)
return false;
if (!hasDelegateMarkedFieldsOrMethods(scope.referenceContext))
return false;
List<ClassScopeEntry> stack = visited.get();
StringBuilder corrupted = null;
for (ClassScopeEntry entry : stack) {
if (corrupted != null) {
corrupted.append(" -> ").append(nameOfScope(entry.scope));
} else if (entry.scope == scope) {
corrupted = new StringBuilder().append(nameOfScope(scope));
}
}
if (corrupted != null) {
boolean found = false;
String path = corrupted.toString();
for (ClassScopeEntry entry : stack) {
if (!found && entry.scope == scope)
found = true;
if (found)
entry.corruptedPath = path;
}
} else {
ClassScopeEntry entry = new ClassScopeEntry(scope);
stack.add(entry);
try {
TypeDeclaration decl = scope.referenceContext;
if (decl != null) {
CompilationUnitDeclaration cud = scope.compilationUnitScope().referenceContext;
EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true);
List<BindingTuple> methodsToDelegate = new ArrayList<BindingTuple>();
fillMethodBindingsForFields(cud, scope, methodsToDelegate);
if (entry.corruptedPath != null) {
eclipseAst.get(scope.referenceContext).addError("No @Delegate methods created because there's a loop: " + entry.corruptedPath);
} else {
generateDelegateMethods(eclipseAst.get(decl), methodsToDelegate, DelegateReceiver.FIELD);
}
methodsToDelegate.clear();
fillMethodBindingsForMethods(cud, scope, methodsToDelegate);
if (entry.corruptedPath != null) {
eclipseAst.get(scope.referenceContext).addError("No @Delegate methods created because there's a loop: " + entry.corruptedPath);
} else {
generateDelegateMethods(eclipseAst.get(decl), methodsToDelegate, DelegateReceiver.METHOD);
}
}
} finally {
stack.remove(stack.size() - 1);
}
}
return false;
}
use of lombok.eclipse.EclipseAST in project lombok by rzwitserloot.
the class PatchExtensionMethod method getTypeNode.
public static EclipseNode getTypeNode(TypeDeclaration decl) {
CompilationUnitDeclaration cud = decl.scope.compilationUnitScope().referenceContext;
EclipseAST astNode = TransformEclipseAST.getAST(cud, false);
EclipseNode node = astNode.get(decl);
if (node == null) {
astNode = TransformEclipseAST.getAST(cud, true);
node = astNode.get(decl);
}
return node;
}
Aggregations