use of com.sun.tools.javac.util.ListBuffer in project lombok by rzwitserloot.
the class JavacHandlerUtil method copyTypeParams.
public static List<JCTypeParameter> copyTypeParams(JavacNode source, List<JCTypeParameter> params) {
if (params == null || params.isEmpty())
return params;
ListBuffer<JCTypeParameter> out = new ListBuffer<JCTypeParameter>();
JavacTreeMaker maker = source.getTreeMaker();
Context context = source.getContext();
for (JCTypeParameter tp : params) {
List<JCExpression> bounds = tp.bounds;
if (bounds != null && !bounds.isEmpty()) {
ListBuffer<JCExpression> boundsCopy = new ListBuffer<JCExpression>();
for (JCExpression expr : tp.bounds) {
boundsCopy.append(cloneType(maker, expr, source.get(), context));
}
bounds = boundsCopy.toList();
}
out.append(maker.TypeParameter(tp.name, bounds));
}
return out.toList();
}
use of com.sun.tools.javac.util.ListBuffer in project lombok by rzwitserloot.
the class JavacHandlerUtil method findAnnotations.
/**
* Searches the given field node for annotations and returns each one that matches the provided regular expression pattern.
*
* Only the simple name is checked - the package and any containing class are ignored.
*/
public static List<JCAnnotation> findAnnotations(JavacNode fieldNode, Pattern namePattern) {
ListBuffer<JCAnnotation> result = new ListBuffer<JCAnnotation>();
for (JavacNode child : fieldNode.down()) {
if (child.getKind() == Kind.ANNOTATION) {
JCAnnotation annotation = (JCAnnotation) child.get();
String name = annotation.annotationType.toString();
int idx = name.lastIndexOf(".");
String suspect = idx == -1 ? name : name.substring(idx + 1);
if (namePattern.matcher(suspect).matches()) {
result.append(annotation);
}
}
}
return result.toList();
}
use of com.sun.tools.javac.util.ListBuffer in project lombok by rzwitserloot.
the class JavacHandlerUtil method deleteImportFromCompilationUnit.
public static void deleteImportFromCompilationUnit(JavacNode node, String name) {
if (inNetbeansEditor(node))
return;
if (!node.shouldDeleteLombokAnnotations())
return;
ListBuffer<JCTree> newDefs = new ListBuffer<JCTree>();
JCCompilationUnit unit = (JCCompilationUnit) node.top().get();
for (JCTree def : unit.defs) {
boolean delete = false;
if (def instanceof JCImport) {
JCImport imp0rt = (JCImport) def;
delete = (!imp0rt.staticImport && imp0rt.qualid.toString().equals(name));
}
if (!delete)
newDefs.append(def);
}
unit.defs = newDefs.toList();
}
use of com.sun.tools.javac.util.ListBuffer in project lombok by rzwitserloot.
the class HandleGetter method findDelegatesAndRemoveFromField.
public static List<JCAnnotation> findDelegatesAndRemoveFromField(JavacNode field) {
JCVariableDecl fieldNode = (JCVariableDecl) field.get();
List<JCAnnotation> delegates = List.nil();
for (JCAnnotation annotation : fieldNode.mods.annotations) {
if (typeMatches(Delegate.class, field, annotation.annotationType)) {
delegates = delegates.append(annotation);
}
}
if (!delegates.isEmpty()) {
ListBuffer<JCAnnotation> withoutDelegates = new ListBuffer<JCAnnotation>();
for (JCAnnotation annotation : fieldNode.mods.annotations) {
if (!delegates.contains(annotation)) {
withoutDelegates.append(annotation);
}
}
fieldNode.mods.annotations = withoutDelegates.toList();
field.rebuild();
}
return delegates;
}
use of com.sun.tools.javac.util.ListBuffer in project lombok by rzwitserloot.
the class HandleBuilder method generateBuilderMethod.
public JCMethodDecl generateBuilderMethod(boolean isStatic, String builderMethodName, String builderClassName, JavacNode source, JavacNode type, List<JCTypeParameter> typeParams) {
JavacTreeMaker maker = type.getTreeMaker();
ListBuffer<JCExpression> typeArgs = new ListBuffer<JCExpression>();
for (JCTypeParameter typeParam : typeParams) {
typeArgs.append(maker.Ident(typeParam.name));
}
JCExpression call = maker.NewClass(null, List.<JCExpression>nil(), namePlusTypeParamsToTypeReference(maker, type.toName(builderClassName), typeParams), List.<JCExpression>nil(), null);
JCStatement statement = maker.Return(call);
JCBlock body = maker.Block(0, List.<JCStatement>of(statement));
int modifiers = Flags.PUBLIC;
if (isStatic)
modifiers |= Flags.STATIC;
return maker.MethodDef(maker.Modifiers(modifiers), type.toName(builderMethodName), namePlusTypeParamsToTypeReference(maker, type.toName(builderClassName), typeParams), copyTypeParams(source, typeParams), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null);
}
Aggregations