本文整理汇总了Java中org.codehaus.groovy.ast.Parameter.EMPTY_ARRAY属性的典型用法代码示例。如果您正苦于以下问题:Java Parameter.EMPTY_ARRAY属性的具体用法?Java Parameter.EMPTY_ARRAY怎么用?Java Parameter.EMPTY_ARRAY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.codehaus.groovy.ast.Parameter
的用法示例。
在下文中一共展示了Parameter.EMPTY_ARRAY属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitFormalParameterList
@Override
public Parameter[] visitFormalParameterList(FormalParameterListContext ctx) {
if (!asBoolean(ctx)) {
return Parameter.EMPTY_ARRAY;
}
List<Parameter> parameterList = new LinkedList<>();
if (asBoolean(ctx.thisFormalParameter())) {
parameterList.add(this.visitThisFormalParameter(ctx.thisFormalParameter()));
}
List<? extends FormalParameterContext> formalParameterList = ctx.formalParameter();
if (asBoolean(formalParameterList)) {
validateVarArgParameter(formalParameterList);
parameterList.addAll(
formalParameterList.stream()
.map(this::visitFormalParameter)
.collect(Collectors.toList()));
}
validateParameterList(parameterList);
return parameterList.toArray(Parameter.EMPTY_ARRAY);
}
示例2: allParametersAndArgumentsMatch
/**
* Checks that arguments and parameter types match.
* @param params method parameters
* @param args type arguments
* @return -1 if arguments do not match, 0 if arguments are of the exact type and >0 when one or more argument is
* not of the exact type but still match
*/
public static int allParametersAndArgumentsMatch(Parameter[] params, ClassNode[] args) {
if (params==null) {
params = Parameter.EMPTY_ARRAY;
}
int dist = 0;
if (args.length<params.length) return -1;
// we already know there are at least params.length elements in both arrays
for (int i = 0; i < params.length; i++) {
ClassNode paramType = params[i].getType();
ClassNode argType = args[i];
if (!isAssignableTo(argType, paramType)) return -1;
else {
if (!paramType.equals(argType)) dist+=getDistance(argType, paramType);
}
}
return dist;
}
示例3: newMethod
public MethodNode newMethod(final String name,
final Callable<ClassNode> returnType) {
MethodNode node = new MethodNode(name,
Opcodes.ACC_PUBLIC,
ClassHelper.OBJECT_TYPE,
Parameter.EMPTY_ARRAY,
ClassNode.EMPTY_ARRAY,
EmptyStatement.INSTANCE) {
@Override
public ClassNode getReturnType() {
try {
return returnType.call();
} catch (Exception e) {
return super.getReturnType();
}
}
};
generatedMethods.add(node);
return node;
}
示例4: makeDynamic
/**
* Used to instruct the type checker that the call is a dynamic method call.
* Calling this method automatically sets the handled flag to true.
* @param call the method call which is a dynamic method call
* @param returnType the expected return type of the dynamic call
* @return a virtual method node with the same name as the expected call
*/
public MethodNode makeDynamic(MethodCall call, ClassNode returnType) {
TypeCheckingContext.EnclosingClosure enclosingClosure = context.getEnclosingClosure();
MethodNode enclosingMethod = context.getEnclosingMethod();
((ASTNode)call).putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, returnType);
if (enclosingClosure!=null) {
enclosingClosure.getClosureExpression().putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, Boolean.TRUE);
} else {
enclosingMethod.putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, Boolean.TRUE);
}
setHandled(true);
if (debug) {
LOG.info("Turning "+call.getText()+" into a dynamic method call returning "+returnType.toString(false));
}
return new MethodNode(call.getMethodAsString(), 0, returnType, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, EmptyStatement.INSTANCE);
}
示例5: blockExpression
protected Expression blockExpression(AST node) {
AST codeNode = node.getFirstChild();
if (codeNode == null) return ConstantExpression.NULL;
if (codeNode.getType() == EXPR && codeNode.getNextSibling() == null) {
// Simplify common case of {expr} to expr.
return expression(codeNode);
}
Parameter[] parameters = Parameter.EMPTY_ARRAY;
Statement code = statementListNoChild(codeNode, node);
ClosureExpression closureExpression = new ClosureExpression(parameters, code);
configureAST(closureExpression, node);
// Call it immediately.
String callName = "call";
Expression noArguments = new ArgumentListExpression();
MethodCallExpression call = new MethodCallExpression(closureExpression, callName, noArguments);
configureAST(call, node);
return call;
}
示例6: resolveClassNode
private static ClassNode resolveClassNode(final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final MethodNode mn, final ASTNode usage, final ClassNode parsedNode) {
ClassNode dummyClass = new ClassNode("dummy",0, ClassHelper.OBJECT_TYPE);
dummyClass.setModule(new ModuleNode(sourceUnit));
dummyClass.setGenericsTypes(mn.getDeclaringClass().getGenericsTypes());
MethodNode dummyMN = new MethodNode(
"dummy",
0,
parsedNode,
Parameter.EMPTY_ARRAY,
ClassNode.EMPTY_ARRAY,
EmptyStatement.INSTANCE
);
dummyMN.setGenericsTypes(mn.getGenericsTypes());
dummyClass.addMethod(dummyMN);
ResolveVisitor visitor = new ResolveVisitor(compilationUnit) {
@Override
public void addError(final String msg, final ASTNode expr) {
sourceUnit.addError(new IncorrectTypeHintException(mn, msg, usage.getLineNumber(), usage.getColumnNumber()));
}
};
visitor.startResolving(dummyClass, sourceUnit);
return dummyMN.getReturnType();
}
示例7: visitClosure
@Override
public ClosureExpression visitClosure(ClosureContext ctx) {
Parameter[] parameters = asBoolean(ctx.formalParameterList())
? this.visitFormalParameterList(ctx.formalParameterList())
: null;
if (!asBoolean(ctx.ARROW())) {
parameters = Parameter.EMPTY_ARRAY;
}
Statement code = this.visitBlockStatementsOpt(ctx.blockStatementsOpt());
return configureAST(new ClosureExpression(parameters, code), ctx);
}
示例8: visitFormalParameters
@Override
public Parameter[] visitFormalParameters(FormalParametersContext ctx) {
if (!asBoolean(ctx)) {
return Parameter.EMPTY_ARRAY;
}
return this.visitFormalParameterList(ctx.formalParameterList());
}
示例9: visitMethodCallArguments
protected void visitMethodCallArguments(final ClassNode receiver, ArgumentListExpression arguments, boolean visitClosures, final MethodNode selectedMethod) {
Parameter[] params = selectedMethod!=null?selectedMethod.getParameters(): Parameter.EMPTY_ARRAY;
List<Expression> expressions = new LinkedList<Expression>(arguments.getExpressions());
if (selectedMethod instanceof ExtensionMethodNode) {
params = ((ExtensionMethodNode) selectedMethod).getExtensionMethodNode().getParameters();
expressions.add(0, varX("$self", receiver));
}
ArgumentListExpression newArgs = args(expressions);
for (int i = 0, expressionsSize = expressions.size(); i < expressionsSize; i++) {
final Expression expression = expressions.get(i);
if (visitClosures && expression instanceof ClosureExpression
|| !visitClosures && !(expression instanceof ClosureExpression)) {
if (i<params.length && visitClosures) {
Parameter param = params[i];
checkClosureWithDelegatesTo(receiver, selectedMethod, newArgs,params , expression, param);
if (selectedMethod instanceof ExtensionMethodNode) {
if (i>0) {
inferClosureParameterTypes(receiver, arguments, (ClosureExpression)expression, param, selectedMethod);
}
} else {
inferClosureParameterTypes(receiver, newArgs, (ClosureExpression) expression, param, selectedMethod);
}
}
expression.visit(this);
if (expression.getNodeMetaData(StaticTypesMarker.DELEGATION_METADATA)!=null) {
expression.removeNodeMetaData(StaticTypesMarker.DELEGATION_METADATA);
}
}
}
}
示例10: selectAccessibleConstructorFromSuper
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;
}
示例11: makeParameters
private Parameter[] makeParameters(CompileUnit cu, Type[] types, Class[] cls, Annotation[][] parameterAnnotations) {
Parameter[] params = Parameter.EMPTY_ARRAY;
if (types.length > 0) {
params = new Parameter[types.length];
for (int i = 0; i < params.length; i++) {
params[i] = makeParameter(cu, types[i], cls[i], parameterAnnotations[i], i);
}
}
return params;
}
示例12: transformMethodCall
private Expression transformMethodCall(final MethodCallExpression exp) {
String name = exp.getMethodAsString();
if (exp.isImplicitThis() && "include".equals(name)) {
return tryTransformInclude(exp);
} else if (exp.isImplicitThis() && name.startsWith(":")) {
List<Expression> args;
if (exp.getArguments() instanceof ArgumentListExpression) {
args = ((ArgumentListExpression) exp.getArguments()).getExpressions();
} else {
args = Collections.singletonList(exp.getArguments());
}
Expression newArguments = transform(new ArgumentListExpression(new ConstantExpression(name.substring(1)), new ArrayExpression(ClassHelper.OBJECT_TYPE, args)));
MethodCallExpression call = new MethodCallExpression(
new VariableExpression("this"),
"methodMissing",
newArguments
);
call.setImplicitThis(true);
call.setSafe(exp.isSafe());
call.setSpreadSafe(exp.isSpreadSafe());
call.setSourcePosition(exp);
return call;
} else if (name!=null && name.startsWith("$")) {
MethodCallExpression reformatted = new MethodCallExpression(
exp.getObjectExpression(),
name.substring(1),
exp.getArguments()
);
reformatted.setImplicitThis(exp.isImplicitThis());
reformatted.setSafe(exp.isSafe());
reformatted.setSpreadSafe(exp.isSpreadSafe());
reformatted.setSourcePosition(exp);
// wrap in a stringOf { ... } closure call
ClosureExpression clos = new ClosureExpression(Parameter.EMPTY_ARRAY, new ExpressionStatement(reformatted));
clos.setVariableScope(new VariableScope());
MethodCallExpression stringOf = new MethodCallExpression(new VariableExpression("this"),
"stringOf",
clos);
stringOf.setImplicitThis(true);
stringOf.setSourcePosition(reformatted);
return stringOf;
}
return super.transform(exp);
}
示例13: visitClosureExpression
@Override
public void visitClosureExpression(final ClosureExpression expression) {
boolean oldStaticContext = typeCheckingContext.isInStaticContext;
typeCheckingContext.isInStaticContext = false;
// collect every variable expression used in the loop body
final Map<VariableExpression, ClassNode> varOrigType = new HashMap<VariableExpression, ClassNode>();
Statement code = expression.getCode();
code.visit(new VariableExpressionTypeMemoizer(varOrigType));
Map<VariableExpression, List<ClassNode>> oldTracker = pushAssignmentTracking();
// first, collect closure shared variables and reinitialize types
SharedVariableCollector collector = new SharedVariableCollector(getSourceUnit());
collector.visitClosureExpression(expression);
Set<VariableExpression> closureSharedExpressions = collector.getClosureSharedExpressions();
Map<VariableExpression, ListHashMap> typesBeforeVisit = null;
if (!closureSharedExpressions.isEmpty()) {
typesBeforeVisit = new HashMap<VariableExpression, ListHashMap>();
saveVariableExpressionMetadata(closureSharedExpressions, typesBeforeVisit);
}
// perform visit
typeCheckingContext.pushEnclosingClosureExpression(expression);
DelegationMetadata dmd = getDelegationMetadata(expression);
if (dmd ==null) {
typeCheckingContext.delegationMetadata = new DelegationMetadata(
typeCheckingContext.getEnclosingClassNode(), Closure.OWNER_FIRST, typeCheckingContext.delegationMetadata
);
} else {
typeCheckingContext.delegationMetadata = new DelegationMetadata(
dmd.getType(),
dmd.getStrategy(),
typeCheckingContext.delegationMetadata
);
}
super.visitClosureExpression(expression);
typeCheckingContext.delegationMetadata = typeCheckingContext.delegationMetadata.getParent();
MethodNode node = new MethodNode("dummy", 0, ClassHelper.OBJECT_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, code);
returnAdder.visitMethod(node);
TypeCheckingContext.EnclosingClosure enclosingClosure = typeCheckingContext.getEnclosingClosure();
if (!enclosingClosure.getReturnTypes().isEmpty()) {
ClassNode returnType = lowestUpperBound(enclosingClosure.getReturnTypes());
storeInferredReturnType(expression, returnType);
ClassNode inferredType = wrapClosureType(returnType);
storeType(enclosingClosure.getClosureExpression(), inferredType);
}
typeCheckingContext.popEnclosingClosure();
boolean typeChanged = isSecondPassNeededForControlStructure(varOrigType, oldTracker);
if (typeChanged) visitClosureExpression(expression);
// restore original metadata
restoreVariableExpressionMetadata(typesBeforeVisit);
typeCheckingContext.isInStaticContext = oldStaticContext;
Parameter[] parameters = expression.getParameters();
if (parameters!=null) {
for (Parameter parameter : parameters) {
typeCheckingContext.controlStructureVariables.remove(parameter);
}
}
}
示例14: createGroovyTruthClosureExpression
@NotNull
private ClosureExpression createGroovyTruthClosureExpression(VariableScope scope) {
ClosureExpression result = new ClosureExpression(Parameter.EMPTY_ARRAY, returnS(varX("it")));
result.setVariableScope(new VariableScope());
return result;
}