本文整理汇总了Java中org.codehaus.groovy.ast.Parameter.getName方法的典型用法代码示例。如果您正苦于以下问题:Java Parameter.getName方法的具体用法?Java Parameter.getName怎么用?Java Parameter.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.Parameter
的用法示例。
在下文中一共展示了Parameter.getName方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypeFromClosureArguments
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
private ClassNode getTypeFromClosureArguments(Parameter parameter, TypeCheckingContext.EnclosingClosure enclosingClosure) {
ClosureExpression closureExpression = enclosingClosure.getClosureExpression();
ClassNode[] closureParamTypes = (ClassNode[]) closureExpression.getNodeMetaData(StaticTypesMarker.CLOSURE_ARGUMENTS);
if (closureParamTypes == null) return null;
final Parameter[] parameters = closureExpression.getParameters();
String name = parameter.getName();
if (parameters.length == 0) {
return "it".equals(name) && closureParamTypes.length != 0 ? closureParamTypes[0] : null;
}
for (int index = 0; index < parameters.length; index++) {
if (name.equals(parameters[index].getName())) {
return closureParamTypes.length > index ? closureParamTypes[index] : null;
}
}
return null;
}
示例2: doCreateSuperForwarder
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
/**
* Creates a method to dispatch to "super traits" in a "stackable" fashion. The generated method looks like this:
* <p>
* <code>ReturnType trait$super$method(Class clazz, Arg1 arg1, Arg2 arg2, ...) {
* if (SomeTrait.is(A) { return SomeOtherTrait$Trait$Helper.method(this, arg1, arg2) }
* super.method(arg1,arg2)
* }</code>
* </p>
* @param targetNode
* @param forwarderMethod
* @param interfacesToGenerateForwarderFor
* @param genericsSpec
*/
private static void doCreateSuperForwarder(ClassNode targetNode, MethodNode forwarderMethod, ClassNode[] interfacesToGenerateForwarderFor, Map<String,ClassNode> genericsSpec) {
Parameter[] parameters = forwarderMethod.getParameters();
Parameter[] superForwarderParams = new Parameter[parameters.length];
for (int i = 0; i < parameters.length; i++) {
Parameter parameter = parameters[i];
ClassNode originType = parameter.getOriginType();
superForwarderParams[i] = new Parameter(correctToGenericsSpecRecurse(genericsSpec, originType), parameter.getName());
}
for (int i = 0; i < interfacesToGenerateForwarderFor.length; i++) {
final ClassNode current = interfacesToGenerateForwarderFor[i];
final ClassNode next = i < interfacesToGenerateForwarderFor.length - 1 ? interfacesToGenerateForwarderFor[i + 1] : null;
String forwarderName = Traits.getSuperTraitMethodName(current, forwarderMethod.getName());
if (targetNode.getDeclaredMethod(forwarderName, superForwarderParams) == null) {
ClassNode returnType = correctToGenericsSpecRecurse(genericsSpec, forwarderMethod.getReturnType());
Statement delegate = next == null ? createSuperFallback(forwarderMethod, returnType) : createDelegatingForwarder(forwarderMethod, next);
MethodNode methodNode = targetNode.addMethod(forwarderName, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, returnType, superForwarderParams, ClassNode.EMPTY_ARRAY, delegate);
methodNode.setGenericsTypes(forwarderMethod.getGenericsTypes());
}
}
}
示例3: makeRawTypes
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
private static Parameter[] makeRawTypes(Parameter[] params) {
Parameter[] newParam = new Parameter[params.length];
for (int i=0; i<params.length; i++) {
Parameter oldP = params[i];
Parameter newP = new Parameter(makeRawType(oldP.getType()),oldP.getName());
newParam[i] = newP;
}
return newParam;
}
示例4: buildParameter
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
/**
* Given a parameter, builds a new parameter for which the known generics placeholders are resolved.
* @param genericFromReceiver resolved generics from the receiver of the message
* @param placeholdersFromContext, resolved generics from the method context
* @param methodParameter the method parameter for which we want to resolve generic types
* @param paramType the (unresolved) type of the method parameter
* @return a new parameter with the same name and type as the original one, but with resolved generic types
*/
private static Parameter buildParameter(final Map<String, GenericsType> genericFromReceiver, final Map<String, GenericsType> placeholdersFromContext, final Parameter methodParameter, final ClassNode paramType) {
if (genericFromReceiver.isEmpty() && (placeholdersFromContext==null||placeholdersFromContext.isEmpty())) {
return methodParameter;
}
if (paramType.isArray()) {
ClassNode componentType = paramType.getComponentType();
Parameter subMethodParameter = new Parameter(componentType, methodParameter.getName());
Parameter component = buildParameter(genericFromReceiver, placeholdersFromContext, subMethodParameter, componentType);
return new Parameter(component.getType().makeArray(), component.getName());
}
ClassNode resolved = resolveClassNodeGenerics(genericFromReceiver, placeholdersFromContext, paramType);
return new Parameter(resolved, methodParameter.getName());
}
示例5: verifyParameters
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
private void verifyParameters(List<Parameter> parameters, AST firstParameterNode) {
if (parameters.size() <= 1) return;
Parameter first = parameters.get(0);
if (firstParamIsVarArg) {
throw new ASTRuntimeException(firstParameterNode, "The var-arg parameter " + first.getName() + " must be the last parameter.");
}
}
示例6: correctToGenericsSpec
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
public static MethodNode correctToGenericsSpec(Map<String,ClassNode> genericsSpec, MethodNode mn) {
ClassNode correctedType = correctToGenericsSpecRecurse(genericsSpec, mn.getReturnType());
Parameter[] origParameters = mn.getParameters();
Parameter[] newParameters = new Parameter[origParameters.length];
for (int i = 0; i < origParameters.length; i++) {
Parameter origParameter = origParameters[i];
newParameters[i] = new Parameter(correctToGenericsSpecRecurse(genericsSpec, origParameter.getType()), origParameter.getName(), origParameter.getInitialExpression());
}
return new MethodNode(mn.getName(), mn.getModifiers(), correctedType, newParameters, mn.getExceptions(), mn.getCode());
}
示例7: cloneParams
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
public static Parameter[] cloneParams(Parameter[] source) {
Parameter[] result = new Parameter[source.length];
for (int i = 0; i < source.length; i++) {
Parameter srcParam = source[i];
Parameter dstParam = new Parameter(srcParam.getOriginType(), srcParam.getName());
result[i] = dstParam;
}
return result;
}
示例8: selectAccessibleConstructorFromSuper
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
private static Parameter[] selectAccessibleConstructorFromSuper(ConstructorNode node) {
ClassNode type = node.getDeclaringClass();
ClassNode superType = type.getUnresolvedSuperClass();
Parameter[] bestMatch = null;
for (ConstructorNode c : superType.getDeclaredConstructors()) {
// Only look at things we can actually call
if (!c.isPublic() && !c.isProtected()) continue;
Parameter[] parameters = c.getParameters();
// workaround for GROOVY-5859: remove generic type info
Parameter[] copy = new Parameter[parameters.length];
for (int i = 0; i < copy.length; i++) {
Parameter orig = parameters[i];
copy[i] = new Parameter(orig.getOriginType().getPlainNodeReference(), orig.getName());
}
if (noExceptionToAvoid(node,c)) return copy;
if (bestMatch==null) bestMatch = copy;
}
if (bestMatch!=null) return bestMatch;
// fall back for parameterless constructor
if (superType.isPrimaryClassNode()) {
return Parameter.EMPTY_ARRAY;
}
return null;
}
示例9: convertParamsToFields
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
private static List<FieldNode> convertParamsToFields(ClassNode builder, Parameter[] parameters) {
List<FieldNode> fieldNodes = new ArrayList<FieldNode>();
for(Parameter parameter: parameters) {
Map<String,ClassNode> genericsSpec = createGenericsSpec(builder);
ClassNode correctedType = correctToGenericsSpecRecurse(genericsSpec, parameter.getType());
FieldNode fieldNode = new FieldNode(parameter.getName(), parameter.getModifiers(), correctedType, builder, DEFAULT_INITIAL_VALUE);
fieldNodes.add(fieldNode);
builder.addField(fieldNode);
}
return fieldNodes;
}
示例10: cloneParamsWithDefaultValues
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
static Parameter[] cloneParamsWithDefaultValues(Parameter[] source) {
Parameter[] result = new Parameter[source.length];
for (int i = 0; i < source.length; i++) {
Parameter srcParam = source[i];
Parameter dstParam = new Parameter(srcParam.getOriginType(), srcParam.getName(), srcParam.getInitialExpression());
result[i] = dstParam;
}
return result;
}
示例11: getDescription
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
private static String getDescription(Parameter node) {
return "parameter '" + node.getName() + "'";
}
示例12: writeClosure
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
public void writeClosure(ClosureExpression expression) {
CompileStack compileStack = controller.getCompileStack();
MethodVisitor mv = controller.getMethodVisitor();
ClassNode classNode = controller.getClassNode();
AsmClassGenerator acg = controller.getAcg();
// generate closure as public class to make sure it can be properly invoked by classes of the
// Groovy runtime without circumventing JVM access checks (see CachedMethod for example).
int mods = ACC_PUBLIC;
if (classNode.isInterface()) {
mods |= ACC_STATIC;
}
ClassNode closureClass = getOrAddClosureClass(expression, mods);
String closureClassinternalName = BytecodeHelper.getClassInternalName(closureClass);
List constructors = closureClass.getDeclaredConstructors();
ConstructorNode node = (ConstructorNode) constructors.get(0);
Parameter[] localVariableParams = node.getParameters();
mv.visitTypeInsn(NEW, closureClassinternalName);
mv.visitInsn(DUP);
if (controller.isStaticMethod() || compileStack.isInSpecialConstructorCall()) {
(new ClassExpression(classNode)).visit(acg);
(new ClassExpression(controller.getOutermostClass())).visit(acg);
} else {
mv.visitVarInsn(ALOAD, 0);
controller.getOperandStack().push(ClassHelper.OBJECT_TYPE);
loadThis();
}
// now let's load the various parameters we're passing
// we start at index 2 because the first variable we pass
// is the owner instance and at this point it is already
// on the stack
for (int i = 2; i < localVariableParams.length; i++) {
Parameter param = localVariableParams[i];
String name = param.getName();
loadReference(name, controller);
if (param.getNodeMetaData(ClosureWriter.UseExistingReference.class)==null) {
param.setNodeMetaData(ClosureWriter.UseExistingReference.class,Boolean.TRUE);
}
}
// we may need to pass in some other constructors
//cv.visitMethodInsn(INVOKESPECIAL, innerClassinternalName, "<init>", prototype + ")V");
mv.visitMethodInsn(INVOKESPECIAL, closureClassinternalName, "<init>", BytecodeHelper.getMethodDescriptor(ClassHelper.VOID_TYPE, localVariableParams), false);
controller.getOperandStack().replace(ClassHelper.CLOSURE_TYPE, localVariableParams.length);
}
示例13: defineMethodVariables
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
private void defineMethodVariables(Parameter[] paras, boolean isInStaticContext) {
Label startLabel = new Label();
thisStartLabel = startLabel;
controller.getMethodVisitor().visitLabel(startLabel);
makeLocalVariablesOffset(paras,isInStaticContext);
for (Parameter para : paras) {
String name = para.getName();
BytecodeVariable answer;
ClassNode type = para.getType();
if (para.isClosureSharedVariable()) {
boolean useExistingReference = para.getNodeMetaData(ClosureWriter.UseExistingReference.class) != null;
answer = defineVar(name, para.getOriginType(), true, useExistingReference);
answer.setStartLabel(startLabel);
if (!useExistingReference) {
controller.getOperandStack().load(type, currentVariableIndex);
controller.getOperandStack().box();
// GROOVY-4237, the original variable should always appear
// in the variable index, otherwise some programs get into
// trouble. So we define a dummy variable for the packaging
// phase and let it end right away before the normal
// reference will be used
Label newStart = new Label();
controller.getMethodVisitor().visitLabel(newStart);
BytecodeVariable var = new BytecodeVariable(currentVariableIndex, para.getOriginType(), name, currentVariableIndex);
var.setStartLabel(startLabel);
var.setEndLabel(newStart);
usedVariables.add(var);
answer.setStartLabel(newStart);
createReference(answer);
}
} else {
answer = defineVar(name, type, false, false);
answer.setStartLabel(startLabel);
}
stackVariables.put(name, answer);
}
nextVariableIndex = localVariableOffset;
}
示例14: createFieldCopy
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
private static FieldNode createFieldCopy(ClassNode buildee, Parameter param) {
Map<String,ClassNode> genericsSpec = createGenericsSpec(buildee);
extractSuperClassGenerics(param.getType(), buildee, genericsSpec);
ClassNode correctedParamType = correctToGenericsSpecRecurse(genericsSpec, param.getType());
return new FieldNode(param.getName(), ACC_PRIVATE, correctedParamType, buildee, param.getInitialExpression());
}