com.sun.tools.javac.tree.JCTree.JCMethodDecl Java Examples

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCMethodDecl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GenStubs.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * methods: remove method bodies, make methods native
 */
@Override
public void visitMethodDef(JCMethodDecl tree) {
    tree.mods = translate(tree.mods);
    tree.restype = translate(tree.restype);
    tree.typarams = translateTypeParams(tree.typarams);
    tree.params = translateVarDefs(tree.params);
    tree.thrown = translate(tree.thrown);
    if (tree.body != null) {
        if ((currClassMods & Flags.INTERFACE) != 0) {
            tree.mods.flags &= ~(Flags.DEFAULT | Flags.STATIC);
        } else {
            tree.mods.flags |= Flags.NATIVE;
        }
        tree.body = null;
    }
    result = tree;
}
 
Example #2
Source File: GenStubs.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * methods: remove method bodies, make methods native
 */
@Override
public void visitMethodDef(JCMethodDecl tree) {
    tree.mods = translate(tree.mods);
    tree.restype = translate(tree.restype);
    tree.typarams = translateTypeParams(tree.typarams);
    tree.params = translateVarDefs(tree.params);
    tree.thrown = translate(tree.thrown);
    if (tree.body != null) {
        if ((currClassMods & Flags.INTERFACE) != 0) {
            tree.mods.flags &= ~(Flags.DEFAULT | Flags.STATIC);
        } else {
            tree.mods.flags |= Flags.NATIVE;
        }
        tree.body = null;
    }
    result = tree;
}
 
Example #3
Source File: TreeFinder.java    From annotation-tools with MIT License 6 votes vote down vote up
@Override
public Pair<ASTRecord, Integer> visitMethod(MethodTree node, Insertion ins) {
  dbug.debug("TypePositionFinder.visitMethod%n");
  super.visitMethod(node, ins);

  JCMethodDecl jcnode = (JCMethodDecl) node;
  JCVariableDecl jcvar = (JCVariableDecl) node.getReceiverParameter();
  if (jcvar != null) { return pathAndPos(jcvar); }

  int pos = Position.NOPOS;
  ASTRecord astPath = astRecord(jcnode)
      .extend(Tree.Kind.METHOD, ASTPath.PARAMETER, -1);

  if (node.getParameters().isEmpty()) {
    // no parameters; find first (uncommented) '(' after method name
    pos = findMethodName(jcnode);
    if (pos >= 0) { pos = getFirstInstanceAfter('(', pos); }
    if (++pos <= 0) {
      throw new RuntimeException("Couldn't find param opening paren for: "
          + jcnode);
    }
  } else {
    pos = ((JCTree) node.getParameters().get(0)).getStartPosition();
  }
  return Pair.of(astPath, pos);
}
 
Example #4
Source File: TypeAnnotations.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private int methodParamIndex(List<JCTree> path, JCTree param) {
    List<JCTree> curr = path;
    while (curr.head.getTag() != Tag.METHODDEF &&
            curr.head.getTag() != Tag.LAMBDA) {
        curr = curr.tail;
    }
    if (curr.head.getTag() == Tag.METHODDEF) {
        JCMethodDecl method = (JCMethodDecl)curr.head;
        return method.params.indexOf(param);
    } else if (curr.head.getTag() == Tag.LAMBDA) {
        JCLambda lambda = (JCLambda)curr.head;
        return lambda.params.indexOf(param);
    } else {
        Assert.error("methodParamIndex expected to find method or lambda for param: " + param);
        return -1;
    }
}
 
Example #5
Source File: ExpressionResolver.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
private Expression getExpressionFromMethod(JCMethodDecl method) {
    System.out.println("CompleteExpression.getExpressionFromMethod");

    Expression expression;
    List<JCVariableDecl> parameters = method.getParameters();

    for (JCVariableDecl parameter : parameters) {
        expression = getExpressionFromStatement(parameter);
        if (expression != null) {
            expression.addRoot(method);
            return expression;
        }
    }

    expression = getExpressionFromStatement(method.getBody());

    return addRootIfNeeded(method, expression);
}
 
Example #6
Source File: HandleEqualsAndHashCode.java    From EasyMPermission with MIT License 6 votes vote down vote up
public JCMethodDecl createCanEqual(JavacNode typeNode, JCTree source, List<JCAnnotation> onParam) {
	/* public boolean canEqual(final java.lang.Object other) {
	 *     return other instanceof Outer.Inner.MyType;
	 * }
	 */
	JavacTreeMaker maker = typeNode.getTreeMaker();
	
	JCModifiers mods = maker.Modifiers(Flags.PROTECTED, List.<JCAnnotation>nil());
	JCExpression returnType = maker.TypeIdent(CTC_BOOLEAN);
	Name canEqualName = typeNode.toName("canEqual");
	JCExpression objectType = genJavaLangTypeRef(typeNode, "Object");
	Name otherName = typeNode.toName("other");
	long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext());
	List<JCVariableDecl> params = List.of(maker.VarDef(maker.Modifiers(flags, onParam), otherName, objectType, null));
	
	JCBlock body = maker.Block(0, List.<JCStatement>of(
			maker.Return(maker.TypeTest(maker.Ident(otherName), createTypeReference(typeNode)))));
	
	return recursiveSetGeneratedBy(maker.MethodDef(mods, canEqualName, returnType, List.<JCTypeParameter>nil(), params, List.<JCExpression>nil(), body, null), source, typeNode.getContext());
}
 
Example #7
Source File: JavacJavaUtilListSetSingularizer.java    From EasyMPermission with MIT License 6 votes vote down vote up
void generateSingularMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
	List<JCTypeParameter> typeParams = List.nil();
	List<JCExpression> thrown = List.nil();
	
	JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
	ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
	statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source));
	JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "add");
	JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getSingularName())));
	statements.append(maker.Exec(invokeAdd));
	if (returnStatement != null) statements.append(returnStatement);
	JCBlock body = maker.Block(0, statements.toList());
	Name name = data.getSingularName();
	long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
	if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("add", name.toString()));
	JCExpression paramType = cloneParamType(0, maker, data.getTypeArgs(), builderType, source);
	JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getSingularName(), paramType, null);
	JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null);
	injectMethod(builderType, method);
}
 
Example #8
Source File: HandleSneakyThrows.java    From EasyMPermission with MIT License 6 votes vote down vote up
@Override public void handle(AnnotationValues<SneakyThrows> annotation, JCAnnotation ast, JavacNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.SNEAKY_THROWS_FLAG_USAGE, "@SneakyThrows");
	
	deleteAnnotationIfNeccessary(annotationNode, SneakyThrows.class);
	Collection<String> exceptionNames = annotation.getRawExpressions("value");
	if (exceptionNames.isEmpty()) {
		exceptionNames = Collections.singleton("java.lang.Throwable");
	}
	
	java.util.List<String> exceptions = new ArrayList<String>();
	for (String exception : exceptionNames) {
		if (exception.endsWith(".class")) exception = exception.substring(0, exception.length() - 6);
		exceptions.add(exception);
	}
	
	JavacNode owner = annotationNode.up();
	switch (owner.getKind()) {
	case METHOD:
		handleMethod(annotationNode, (JCMethodDecl)owner.get(), exceptions);
		break;
	default:
		annotationNode.addError("@SneakyThrows is legal only on methods and constructors.");
		break;
	}
}
 
Example #9
Source File: GenStubs.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * methods: remove method bodies, make methods native
 */
@Override
public void visitMethodDef(JCMethodDecl tree) {
    tree.mods = translate(tree.mods);
    tree.restype = translate(tree.restype);
    tree.typarams = translateTypeParams(tree.typarams);
    tree.params = translateVarDefs(tree.params);
    tree.thrown = translate(tree.thrown);
    if (tree.body != null) {
        if ((currClassMods & Flags.INTERFACE) != 0) {
            tree.mods.flags &= ~(Flags.DEFAULT | Flags.STATIC);
        } else {
            tree.mods.flags |= Flags.NATIVE;
        }
        tree.body = null;
    }
    result = tree;
}
 
Example #10
Source File: TypeAnnotations.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private int methodParamIndex(List<JCTree> path, JCTree param) {
    List<JCTree> curr = path;
    while (curr.head.getTag() != Tag.METHODDEF &&
            curr.head.getTag() != Tag.LAMBDA) {
        curr = curr.tail;
    }
    if (curr.head.getTag() == Tag.METHODDEF) {
        JCMethodDecl method = (JCMethodDecl)curr.head;
        return method.params.indexOf(param);
    } else if (curr.head.getTag() == Tag.LAMBDA) {
        JCLambda lambda = (JCLambda)curr.head;
        return lambda.params.indexOf(param);
    } else {
        Assert.error("methodParamIndex expected to find method or lambda for param: " + param);
        return -1;
    }
}
 
Example #11
Source File: TypeAnnotations.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private int methodParamIndex(List<JCTree> path, JCTree param) {
    List<JCTree> curr = path;
    while (curr.head.getTag() != Tag.METHODDEF &&
            curr.head.getTag() != Tag.LAMBDA) {
        curr = curr.tail;
    }
    if (curr.head.getTag() == Tag.METHODDEF) {
        JCMethodDecl method = (JCMethodDecl)curr.head;
        return method.params.indexOf(param);
    } else if (curr.head.getTag() == Tag.LAMBDA) {
        JCLambda lambda = (JCLambda)curr.head;
        return lambda.params.indexOf(param);
    } else {
        Assert.error("methodParamIndex expected to find method or lambda for param: " + param);
        return -1;
    }
}
 
Example #12
Source File: JavacHandlerUtil.java    From EasyMPermission with MIT License 6 votes vote down vote up
/**
 * Checks if there is a (non-default) constructor. In case of multiple constructors (overloading), only
 * the first constructor decides if EXISTS_BY_USER or EXISTS_BY_LOMBOK is returned.
 * 
 * @param node Any node that represents the Type (JCClassDecl) to look in, or any child node thereof.
 */
public static MemberExistsResult constructorExists(JavacNode node) {
	node = upToTypeNode(node);
	
	if (node != null && node.get() instanceof JCClassDecl) {
		top: for (JCTree def : ((JCClassDecl)node.get()).defs) {
			if (def instanceof JCMethodDecl) {
				JCMethodDecl md = (JCMethodDecl) def;
				if (md.name.contentEquals("<init>")) {
					if ((md.mods.flags & Flags.GENERATEDCONSTR) != 0) continue;
					List<JCAnnotation> annotations = md.getModifiers().getAnnotations();
					if (annotations != null) for (JCAnnotation anno : annotations) {
						if (typeMatches(Tolerate.class, node, anno.getAnnotationType())) continue top;
					}
					return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
				}
			}
		}
	}
	
	return MemberExistsResult.NOT_EXISTS;
}
 
Example #13
Source File: TypeAnnotations.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private int methodParamIndex(List<JCTree> path, JCTree param) {
    List<JCTree> curr = path;
    while (curr.head.getTag() != Tag.METHODDEF &&
            curr.head.getTag() != Tag.LAMBDA) {
        curr = curr.tail;
    }
    if (curr.head.getTag() == Tag.METHODDEF) {
        JCMethodDecl method = (JCMethodDecl)curr.head;
        return method.params.indexOf(param);
    } else if (curr.head.getTag() == Tag.LAMBDA) {
        JCLambda lambda = (JCLambda)curr.head;
        return lambda.params.indexOf(param);
    } else {
        Assert.error("methodParamIndex expected to find method or lambda for param: " + param);
        return -1;
    }
}
 
Example #14
Source File: GenStubs.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * methods: remove method bodies, make methods native
 */
@Override
public void visitMethodDef(JCMethodDecl tree) {
    tree.mods = translate(tree.mods);
    tree.restype = translate(tree.restype);
    tree.typarams = translateTypeParams(tree.typarams);
    tree.params = translateVarDefs(tree.params);
    tree.thrown = translate(tree.thrown);
    if (tree.body != null) {
        if ((currClassMods & Flags.INTERFACE) != 0) {
            tree.mods.flags &= ~(Flags.DEFAULT | Flags.STATIC);
        } else {
            tree.mods.flags |= Flags.NATIVE;
        }
        tree.body = null;
    }
    result = tree;
}
 
Example #15
Source File: TypeAnnotations.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private int methodParamIndex(List<JCTree> path, JCTree param) {
    List<JCTree> curr = path;
    while (curr.head.getTag() != Tag.METHODDEF &&
            curr.head.getTag() != Tag.LAMBDA) {
        curr = curr.tail;
    }
    if (curr.head.getTag() == Tag.METHODDEF) {
        JCMethodDecl method = (JCMethodDecl)curr.head;
        return method.params.indexOf(param);
    } else if (curr.head.getTag() == Tag.LAMBDA) {
        JCLambda lambda = (JCLambda)curr.head;
        return lambda.params.indexOf(param);
    } else {
        Assert.error("methodParamIndex expected to find method or lambda for param: " + param);
        return -1;
    }
}
 
Example #16
Source File: GenStubs.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * methods: remove method bodies, make methods native
 */
@Override
public void visitMethodDef(JCMethodDecl tree) {
    tree.mods = translate(tree.mods);
    tree.restype = translate(tree.restype);
    tree.typarams = translateTypeParams(tree.typarams);
    tree.params = translateVarDefs(tree.params);
    tree.thrown = translate(tree.thrown);
    if (tree.body != null) {
        if ((currClassMods & Flags.INTERFACE) != 0) {
            tree.mods.flags &= ~(Flags.DEFAULT | Flags.STATIC);
        } else {
            tree.mods.flags |= Flags.NATIVE;
        }
        tree.body = null;
    }
    result = tree;
}
 
Example #17
Source File: JavacAST.java    From EasyMPermission with MIT License 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected JavacNode buildTree(JCTree node, Kind kind) {
	switch (kind) {
	case COMPILATION_UNIT:
		return buildCompilationUnit((JCCompilationUnit) node);
	case TYPE:
		return buildType((JCClassDecl) node);
	case FIELD:
		return buildField((JCVariableDecl) node);
	case INITIALIZER:
		return buildInitializer((JCBlock) node);
	case METHOD:
		return buildMethod((JCMethodDecl) node);
	case ARGUMENT:
		return buildLocalVar((JCVariableDecl) node, kind);
	case LOCAL:
		return buildLocalVar((JCVariableDecl) node, kind);
	case STATEMENT:
		return buildStatementOrExpression(node);
	case ANNOTATION:
		return buildAnnotation((JCAnnotation) node, false);
	default:
		throw new AssertionError("Did not expect: " + kind);
	}
}
 
Example #18
Source File: GenStubs.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * methods: remove method bodies, make methods native
 */
@Override
public void visitMethodDef(JCMethodDecl tree) {
    tree.mods = translate(tree.mods);
    tree.restype = translate(tree.restype);
    tree.typarams = translateTypeParams(tree.typarams);
    tree.params = translateVarDefs(tree.params);
    tree.thrown = translate(tree.thrown);
    if (tree.body != null) {
        if ((currClassMods & Flags.INTERFACE) != 0) {
            tree.mods.flags &= ~(Flags.DEFAULT | Flags.STATIC);
        } else {
            tree.mods.flags |= Flags.NATIVE;
        }
        tree.body = null;
    }
    result = tree;
}
 
Example #19
Source File: Method.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override
public JCMethodDecl build() {

    return typeNode.getTreeMaker().MethodDef(
            modifiers,
            name,
            returnType,
            typeList,
            paramList,
            thrownList,
            body,
            null);
}
 
Example #20
Source File: TestInvokeDynamic.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Void visitMethod(MethodTree node, Void p) {
    super.visitMethod(node, p);
    if (node.getName().toString().equals("bsm")) {
        bsm = ((JCMethodDecl)node).sym;
    }
    return null;
}
 
Example #21
Source File: TypeEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Add the implicit members for an enum type
 *  to the symbol table.
 */
private void addEnumMembers(JCClassDecl tree, Env<AttrContext> env) {
    JCExpression valuesType = make.Type(new ArrayType(tree.sym.type, syms.arrayClass));

    // public static T[] values() { return ???; }
    JCMethodDecl values = make.
        MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC),
                  names.values,
                  valuesType,
                  List.nil(),
                  List.nil(),
                  List.nil(), // thrown
                  null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))),
                  null);
    memberEnter.memberEnter(values, env);

    // public static T valueOf(String name) { return ???; }
    JCMethodDecl valueOf = make.
        MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC),
                  names.valueOf,
                  make.Type(tree.sym.type),
                  List.nil(),
                  List.of(make.VarDef(make.Modifiers(Flags.PARAMETER |
                                                     Flags.MANDATED),
                                        names.fromString("name"),
                                        make.Type(syms.stringType), null)),
                  List.nil(), // thrown
                  null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))),
                  null);
    memberEnter.memberEnter(valueOf, env);
}
 
Example #22
Source File: ExpressionResolver.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private Expression getExpressionFromClass(JCClassDecl tree) {
    System.out.println("CompleteExpression.getExpressionFromClass");

    if (!isCursorInsideTree(tree)) {
        return null;
    }
    Expression expression = null;
    //members of class: methods, field, inner class
    List<JCTree> members = tree.getMembers();
    for (JCTree member : members) {
        if (member instanceof JCMethodDecl) {
            expression = getExpressionFromMethod((JCMethodDecl) member);

        } else if (member instanceof JCVariableDecl) {
            expression = getExpressionFromStatement((JCVariableDecl) member);

        } else if (member instanceof JCClassDecl) {

            expression = getExpressionFromClass((JCClassDecl) member);
        }

        if (expression != null) {
            return addRootIfNeeded(tree, expression);
        }
    }
    return null;
}
 
Example #23
Source File: Utilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean isSynthetic(CompilationUnitTree cut, Tree leaf) throws NullPointerException {
    JCTree tree = (JCTree) leaf;

    if (tree.pos == (-1))
        return true;

    if (leaf.getKind() == Kind.METHOD) {
        //check for synthetic constructor:
        return (((JCMethodDecl)leaf).mods.flags & Flags.GENERATEDCONSTR) != 0L;
    }

    //check for synthetic superconstructor call:
    if (cut != null && leaf.getKind() == Kind.EXPRESSION_STATEMENT) {
        ExpressionStatementTree est = (ExpressionStatementTree) leaf;

        if (est.getExpression().getKind() == Kind.METHOD_INVOCATION) {
            MethodInvocationTree mit = (MethodInvocationTree) est.getExpression();

            if (mit.getMethodSelect().getKind() == Kind.IDENTIFIER) {
                IdentifierTree it = (IdentifierTree) mit.getMethodSelect();

                if ("super".equals(it.getName().toString())) {
                    return ((JCCompilationUnit) cut).endPositions.getEndPos(tree) == (-1);
                }
            }
        }
    }

    return false;
}
 
Example #24
Source File: HandleRuntimePermission.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override
public void handle(AnnotationValues<RuntimePermission> annotation, JCAnnotation ast, JavacNode annotationNode) {

    deleteAnnotationIfNeccessary(annotationNode, RuntimePermission.class);
    JavacNode typeNode = annotationNode.up();
    boolean notAClass = !isClass(typeNode);

    if (notAClass) {
        annotationNode.addError("@RuntimePermission is only supported on a class.");
        return;
    }

    JCMethodDecl method;

    List<PermissionAnnotatedItem> permissionList = findAllAnnotatedMethods(typeNode);
    for (PermissionAnnotatedItem item : permissionList) {
        method = createPermissionCheckedMethod(typeNode, item);
        removeMethod(typeNode, item.getMethod());
        injectMethod(typeNode, recursiveSetGeneratedBy(method, annotationNode.get(), typeNode.getContext()));
    }

    method = recursiveSetGeneratedBy(createIsPermissionGrantedMethod(typeNode), annotationNode.get(), typeNode.getContext());
    injectMethod(typeNode, method);

    method = recursiveSetGeneratedBy(createOnRequestPermissionMethod(typeNode, permissionList), annotationNode.get(), typeNode.getContext());
    injectMethod(typeNode, method);
}
 
Example #25
Source File: MemberEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Env<AttrContext> getMethodEnv(JCMethodDecl tree, Env<AttrContext> env) {
    Env<AttrContext> mEnv = methodEnv(tree, env);
    mEnv.info.lint = mEnv.info.lint.augment(tree.sym);
    for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail)
        mEnv.info.scope.enterIfAbsent(l.head.type.tsym);
    for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail)
        mEnv.info.scope.enterIfAbsent(l.head.sym);
    return mEnv;
}
 
Example #26
Source File: HandleConstructor.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void generateConstructor(JavacNode typeNode, AccessLevel level, List<JCAnnotation> onConstructor, List<JavacNode> fields, String staticName, SkipIfConstructorExists skipIfConstructorExists, Boolean suppressConstructorProperties, JavacNode source) {
	boolean staticConstrRequired = staticName != null && !staticName.equals("");
	
	if (skipIfConstructorExists != SkipIfConstructorExists.NO && constructorExists(typeNode) != MemberExistsResult.NOT_EXISTS) return;
	if (skipIfConstructorExists != SkipIfConstructorExists.NO) {
		for (JavacNode child : typeNode.down()) {
			if (child.getKind() == Kind.ANNOTATION) {
				boolean skipGeneration = annotationTypeMatches(NoArgsConstructor.class, child) ||
						annotationTypeMatches(AllArgsConstructor.class, child) ||
						annotationTypeMatches(RequiredArgsConstructor.class, child);
				
				if (!skipGeneration && skipIfConstructorExists == SkipIfConstructorExists.YES) {
					skipGeneration = annotationTypeMatches(Builder.class, child);
				}
				
				if (skipGeneration) {
					if (staticConstrRequired) {
						// @Data has asked us to generate a constructor, but we're going to skip this instruction, as an explicit 'make a constructor' annotation
						// will take care of it. However, @Data also wants a specific static name; this will be ignored; the appropriate way to do this is to use
						// the 'staticName' parameter of the @XArgsConstructor you've stuck on your type.
						// We should warn that we're ignoring @Data's 'staticConstructor' param.
						source.addWarning("Ignoring static constructor name: explicit @XxxArgsConstructor annotation present; its `staticName` parameter will be used.");
					}
					return;
				}
			}
		}
	}
	
	JCMethodDecl constr = createConstructor(staticConstrRequired ? AccessLevel.PRIVATE : level, onConstructor, typeNode, fields, suppressConstructorProperties, source);
	injectMethod(typeNode, constr);
	if (staticConstrRequired) {
		JCMethodDecl staticConstr = createStaticConstructor(staticName, level, typeNode, fields, source.get());
		injectMethod(typeNode, staticConstr);
	}
}
 
Example #27
Source File: TestInvokeDynamic.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Void visitMethod(MethodTree node, Void p) {
    super.visitMethod(node, p);
    if (node.getName().toString().equals("bsm")) {
        bsm = ((JCMethodDecl)node).sym;
    }
    return null;
}
 
Example #28
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 5 votes vote down vote up
private void removeImplicitModifiersForInterfaceMembers(List<JCTree> defs) {
	for (JCTree def :defs) {
		if (def instanceof JCVariableDecl) {
			((JCVariableDecl) def).mods.flags &= ~(Flags.PUBLIC | Flags.STATIC | Flags.FINAL);
		}
		if (def instanceof JCMethodDecl) {
			((JCMethodDecl) def).mods.flags &= ~(Flags.PUBLIC | Flags.ABSTRACT);
		}
		if (def instanceof JCClassDecl) {
			((JCClassDecl) def).mods.flags &= ~(Flags.PUBLIC | Flags.STATIC);
		}
	}
}
 
Example #29
Source File: TestInvokeDynamic.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Void visitMethod(MethodTree node, Void p) {
    super.visitMethod(node, p);
    if (node.getName().toString().equals("bsm")) {
        bsm = ((JCMethodDecl)node).sym;
    }
    return null;
}
 
Example #30
Source File: JavacNode.java    From EasyMPermission with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override public String getName() {
	final Name n;
	
	if (node instanceof JCClassDecl) n = ((JCClassDecl) node).name;
	else if (node instanceof JCMethodDecl) n = ((JCMethodDecl) node).name;
	else if (node instanceof JCVariableDecl) n = ((JCVariableDecl) node).name;
	else n = null;
	
	return n == null ? null : n.toString();
}