本文整理汇总了Java中org.codehaus.groovy.ast.Parameter类的典型用法代码示例。如果您正苦于以下问题:Java Parameter类的具体用法?Java Parameter怎么用?Java Parameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Parameter类属于org.codehaus.groovy.ast包,在下文中一共展示了Parameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformationOfAnnotationOnLocalVariable
import org.codehaus.groovy.ast.Parameter; //导入依赖的package包/类
@Test
public void transformationOfAnnotationOnLocalVariable() {
ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
this.moduleNode.addClass(classNode);
DeclarationExpression declarationExpression = new DeclarationExpression(
new VariableExpression("test"), null, new ConstantExpression("test"));
declarationExpression.addAnnotation(this.grabAnnotation);
BlockStatement code = new BlockStatement(
Arrays.asList((Statement) new ExpressionStatement(declarationExpression)),
new VariableScope());
MethodNode methodNode = new MethodNode("test", 0, new ClassNode(Void.class),
new Parameter[0], new ClassNode[0], code);
classNode.addMethod(methodNode);
assertGrabAnnotationHasBeenTransformed();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:ResolveDependencyCoordinatesTransformationTests.java
示例2: addGeneratedClosureConstructorCall
import org.codehaus.groovy.ast.Parameter; //导入依赖的package包/类
public boolean addGeneratedClosureConstructorCall(ConstructorCallExpression call) {
ClassNode classNode = controller.getClassNode();
if (!classNode.declaresInterface(ClassHelper.GENERATED_CLOSURE_Type)) return false;
AsmClassGenerator acg = controller.getAcg();
OperandStack operandStack = controller.getOperandStack();
MethodVisitor mv = controller.getMethodVisitor();
mv.visitVarInsn(ALOAD, 0);
ClassNode callNode = classNode.getSuperClass();
TupleExpression arguments = (TupleExpression) call.getArguments();
if (arguments.getExpressions().size()!=2) throw new GroovyBugError("expected 2 arguments for closure constructor super call, but got"+arguments.getExpressions().size());
arguments.getExpression(0).visit(acg);
operandStack.box();
arguments.getExpression(1).visit(acg);
operandStack.box();
//TODO: replace with normal String, p not needed
Parameter p = new Parameter(ClassHelper.OBJECT_TYPE,"_p");
String descriptor = BytecodeHelper.getMethodDescriptor(ClassHelper.VOID_TYPE, new Parameter[]{p,p});
mv.visitMethodInsn(INVOKESPECIAL, BytecodeHelper.getClassInternalName(callNode), "<init>", descriptor, false);
operandStack.remove(2);
return true;
}
示例3: createCatchBlockForOuterNewTryCatchStatement
import org.codehaus.groovy.ast.Parameter; //导入依赖的package包/类
private CatchStatement createCatchBlockForOuterNewTryCatchStatement(String primaryExcName) {
// { ... }
BlockStatement blockStatement = new BlockStatement();
String tExcName = this.genTExcName();
// #primaryExc = #t;
ExpressionStatement primaryExcAssignStatement =
new ExpressionStatement(
new BinaryExpression(
new VariableExpression(primaryExcName),
org.codehaus.groovy.syntax.Token.newSymbol(Types.ASSIGN, -1, -1),
new VariableExpression(tExcName)));
astBuilder.appendStatementsToBlockStatement(blockStatement, primaryExcAssignStatement);
// throw #t;
ThrowStatement throwTExcStatement = new ThrowStatement(new VariableExpression(tExcName));
astBuilder.appendStatementsToBlockStatement(blockStatement, throwTExcStatement);
// Throwable #t
Parameter tExcParameter = new Parameter(ClassHelper.make(Throwable.class), tExcName);
return new CatchStatement(tExcParameter, blockStatement);
}
示例4: methodDescriptor
import org.codehaus.groovy.ast.Parameter; //导入依赖的package包/类
/**
* Return the method node's descriptor which includes its return type,
* name and parameter types without generics.
*
* @param mNode the method node
* @return the method node's descriptor
*/
public static String methodDescriptor(MethodNode mNode) {
StringBuilder sb = new StringBuilder(mNode.getName().length() + mNode.getParameters().length * 10);
sb.append(mNode.getReturnType().getName());
sb.append(' ');
sb.append(mNode.getName());
sb.append('(');
for (int i = 0; i < mNode.getParameters().length; i++) {
if (i > 0) {
sb.append(", ");
}
Parameter p = mNode.getParameters()[i];
sb.append(ClassNodeUtils.formatTypeName(p.getType()));
}
sb.append(')');
return sb.toString();
}
示例5: makeMapTypedArgsTransformer
import org.codehaus.groovy.ast.Parameter; //导入依赖的package包/类
private static ClassCodeExpressionTransformer makeMapTypedArgsTransformer() {
return new ClassCodeExpressionTransformer() {
@Override
public Expression transform(Expression exp) {
if (exp instanceof ClosureExpression) {
ClosureExpression ce = (ClosureExpression) exp;
ce.getCode().visit(this);
} else if (exp instanceof VariableExpression) {
VariableExpression ve = (VariableExpression) exp;
if (ve.getName().equals("args") && ve.getAccessedVariable() instanceof DynamicVariable) {
VariableExpression newVe = new VariableExpression(new Parameter(MAP_TYPE, "args"));
newVe.setSourcePosition(ve);
return newVe;
}
}
return exp.transformExpression(this);
}
@Override
protected SourceUnit getSourceUnit() {
return null;
}
};
}
示例6: addHolderClassIdiomBody
import org.codehaus.groovy.ast.Parameter; //导入依赖的package包/类
private static void addHolderClassIdiomBody(BlockStatement body, FieldNode fieldNode, Expression initExpr) {
final ClassNode declaringClass = fieldNode.getDeclaringClass();
final ClassNode fieldType = fieldNode.getType();
final int visibility = ACC_PRIVATE | ACC_STATIC;
final String fullName = declaringClass.getName() + "$" + fieldType.getNameWithoutPackage() + "Holder_" + fieldNode.getName().substring(1);
final InnerClassNode holderClass = new InnerClassNode(declaringClass, fullName, visibility, ClassHelper.OBJECT_TYPE);
final String innerFieldName = "INSTANCE";
// we have two options:
// (1) embed initExpr within holder class but redirect field access/method calls to declaring class members
// (2) keep initExpr within a declaring class method that is only called by the holder class
// currently we have gone with (2) for simplicity with only a slight memory footprint increase in the declaring class
final String initializeMethodName = (fullName + "_initExpr").replace('.', '_');
declaringClass.addMethod(initializeMethodName, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, fieldType,
Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, returnS(initExpr));
holderClass.addField(innerFieldName, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, fieldType,
callX(declaringClass, initializeMethodName));
final Expression innerField = propX(classX(holderClass), innerFieldName);
declaringClass.getModule().addClass(holderClass);
body.addStatement(returnS(innerField));
}
示例7: visitMethod
import org.codehaus.groovy.ast.Parameter; //导入依赖的package包/类
public void visitMethod(MethodNode node) {
inConstructor = false;
inStaticConstructor = node.isStaticConstructor();
checkAbstractDeclaration(node);
checkRepetitiveMethod(node);
checkOverloadingPrivateAndPublic(node);
checkMethodModifiers(node);
checkGenericsUsage(node, node.getParameters());
checkGenericsUsage(node, node.getReturnType());
for (Parameter param : node.getParameters()) {
if (param.getType().equals(VOID_TYPE)) {
addError("The " + getDescription(param) + " in " + getDescription(node) + " has invalid type void", param);
}
}
super.visitMethod(node);
}
示例8: typeCheckMethodsWithGenericsOrFail
import org.codehaus.groovy.ast.Parameter; //导入依赖的package包/类
protected boolean typeCheckMethodsWithGenericsOrFail(ClassNode receiver, ClassNode[] arguments, MethodNode candidateMethod, Expression location) {
if (!typeCheckMethodsWithGenerics(receiver, arguments, candidateMethod)) {
Map<String, GenericsType> classGTs = GenericsUtils.extractPlaceholders(receiver);
ClassNode[] ptypes = new ClassNode[candidateMethod.getParameters().length];
final Parameter[] parameters = candidateMethod.getParameters();
for (int i = 0; i < parameters.length; i++) {
final Parameter parameter = parameters[i];
ClassNode type = parameter.getType();
ptypes[i] = fullyResolveType(type, classGTs);
}
addStaticTypeError("Cannot call " + toMethodGenericTypesString(candidateMethod) + receiver.toString(false) + "#" +
toMethodParametersString(candidateMethod.getName(), ptypes) +
" with arguments " + formatArgumentList(arguments), location);
return false;
}
return true;
}
示例9: checkClosureParameters
import org.codehaus.groovy.ast.Parameter; //导入依赖的package包/类
/**
* @deprecated this method is unused, replaced with {@link DelegatesTo} inference.
* @param callArguments
* @param receiver
*/
@Deprecated
protected void checkClosureParameters(final Expression callArguments, final ClassNode receiver) {
if (callArguments instanceof ArgumentListExpression) {
ArgumentListExpression argList = (ArgumentListExpression) callArguments;
ClosureExpression closure = (ClosureExpression) argList.getExpression(0);
Parameter[] parameters = closure.getParameters();
if (parameters.length > 1) {
addStaticTypeError("Unexpected number of parameters for a with call", argList);
} else if (parameters.length == 1) {
Parameter param = parameters[0];
if (!param.isDynamicTyped() && !isAssignableTo(receiver, param.getType().redirect())) {
addStaticTypeError("Expected parameter type: " + receiver.toString(false) + " but was: " + param.getType().redirect().toString(false), param);
}
}
closure.putNodeMetaData(StaticTypesMarker.DELEGATION_METADATA, new DelegationMetadata(
receiver,
Closure.DELEGATE_FIRST,
typeCheckingContext.delegationMetadata
));
}
}
示例10: inferSAMTypeGenericsInAssignment
import org.codehaus.groovy.ast.Parameter; //导入依赖的package包/类
private ClassNode inferSAMTypeGenericsInAssignment(ClassNode samUsage, MethodNode sam, ClassNode closureType, ClosureExpression closureExpression) {
// if the sam type or closure type do not provide generics information,
// we cannot infer anything, thus we simply return the provided samUsage
GenericsType[] samGt = samUsage.getGenericsTypes();
GenericsType[] closureGt = closureType.getGenericsTypes();
if (samGt==null || closureGt==null) return samUsage;
// extract the generics from the return type
Map<String,GenericsType> connections = new HashMap<String,GenericsType>();
extractGenericsConnections(connections, getInferredReturnType(closureExpression),sam.getReturnType());
// next we get the block parameter types and set the generics
// information just like before
// TODO: add vargs handling
Parameter[] closureParams = closureExpression.getParameters();
Parameter[] methodParams = sam.getParameters();
for (int i=0; i<closureParams.length; i++) {
ClassNode fromClosure = closureParams[i].getType();
ClassNode fromMethod = methodParams[i].getType();
extractGenericsConnections(connections,fromClosure,fromMethod);
}
ClassNode result = applyGenericsContext(connections, samUsage.redirect());
return result;
}
示例11: visitClosureExpression
import org.codehaus.groovy.ast.Parameter; //导入依赖的package包/类
@Override
public void visitClosureExpression(ClosureExpression expr) {
for (Parameter parameter : expr.getParameters()) {
if (parameter.hasInitialExpression()) {
parameter.setInitialExpression(replaceExpr(parameter.getInitialExpression()));
}
}
expr.getCode().visit(this);
replaceVisitedExpressionWith(expr);
}
示例12: inspectClosureExpression
import org.codehaus.groovy.ast.Parameter; //导入依赖的package包/类
private void inspectClosureExpression(String in, int childIndent, ClosureExpression ce) {
System.out.println(in+"-parameters:");
for (Parameter p : ce.getParameters()){
inspectParameter(in+" ", p);
}
System.out.println(in+"-type:");
inspectClassNode(childIndent, in, ce.getType().getComponentType());
System.out.println(in+"-code:");
inspect(ce.getCode(), childIndent);
}
示例13: inspectMethodNode
import org.codehaus.groovy.ast.Parameter; //导入依赖的package包/类
private void inspectMethodNode(int childIndent, String in, MethodNode methodNode) {
System.out.println(in + "methodName:" + methodNode.getName());
System.out.println(in+"class="+methodNode.getClass());
if (true)
return;
Parameter[] params = methodNode.getParameters();
for (Parameter p : params) {
inspect(p, childIndent);
}
}
示例14: transformationOfAnnotationOnMethod
import org.codehaus.groovy.ast.Parameter; //导入依赖的package包/类
@Test
public void transformationOfAnnotationOnMethod() {
ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
this.moduleNode.addClass(classNode);
MethodNode methodNode = new MethodNode("test", 0, new ClassNode(Void.class),
new Parameter[0], new ClassNode[0], null);
methodNode.addAnnotation(this.grabAnnotation);
classNode.addMethod(methodNode);
assertGrabAnnotationHasBeenTransformed();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:ResolveDependencyCoordinatesTransformationTests.java
示例15: transformationOfAnnotationOnMethodParameter
import org.codehaus.groovy.ast.Parameter; //导入依赖的package包/类
@Test
public void transformationOfAnnotationOnMethodParameter() {
ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
this.moduleNode.addClass(classNode);
Parameter parameter = new Parameter(new ClassNode(Object.class), "test");
parameter.addAnnotation(this.grabAnnotation);
MethodNode methodNode = new MethodNode("test", 0, new ClassNode(Void.class),
new Parameter[] { parameter }, new ClassNode[0], null);
classNode.addMethod(methodNode);
assertGrabAnnotationHasBeenTransformed();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:ResolveDependencyCoordinatesTransformationTests.java