Search in sources :

Example 61 with ListBuffer

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();
}
Also used : JCTypeParameter(com.sun.tools.javac.tree.JCTree.JCTypeParameter) Context(com.sun.tools.javac.util.Context) JavacTreeMaker(lombok.javac.JavacTreeMaker) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) ListBuffer(com.sun.tools.javac.util.ListBuffer)

Example 62 with ListBuffer

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();
}
Also used : JavacNode(lombok.javac.JavacNode) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation)

Example 63 with ListBuffer

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();
}
Also used : JCCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit) JCImport(com.sun.tools.javac.tree.JCTree.JCImport) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCTree(com.sun.tools.javac.tree.JCTree)

Example 64 with ListBuffer

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;
}
Also used : ListBuffer(com.sun.tools.javac.util.ListBuffer) JCVariableDecl(com.sun.tools.javac.tree.JCTree.JCVariableDecl) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation)

Example 65 with ListBuffer

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);
}
Also used : JCTypeParameter(com.sun.tools.javac.tree.JCTree.JCTypeParameter) JCBlock(com.sun.tools.javac.tree.JCTree.JCBlock) JavacTreeMaker(lombok.javac.JavacTreeMaker) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement)

Aggregations

ListBuffer (com.sun.tools.javac.util.ListBuffer)88 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)54 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)25 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)25 JCTree (com.sun.tools.javac.tree.JCTree)22 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)22 Name (com.sun.tools.javac.util.Name)19 JavacNode (lombok.javac.JavacNode)18 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)17 JCBlock (com.sun.tools.javac.tree.JCTree.JCBlock)17 JavacTreeMaker (lombok.javac.JavacTreeMaker)17 JCMethodDecl (com.sun.tools.javac.tree.JCTree.JCMethodDecl)14 Type (com.redhat.ceylon.model.typechecker.model.Type)12 JCClassDecl (com.sun.tools.javac.tree.JCTree.JCClassDecl)12 JCModifiers (com.sun.tools.javac.tree.JCTree.JCModifiers)11 JCPrimitiveTypeTree (com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree)8 List (com.sun.tools.javac.util.List)7 ArrayList (java.util.ArrayList)7 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)6 ModelUtil.appliedType (com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType)6