Java源码示例:org.codehaus.groovy.ast.expr.DeclarationExpression
示例1
private void changeBaseScriptTypeFromDeclaration(final SourceUnit source, final DeclarationExpression de, final AnnotationNode node) {
if (de.isMultipleAssignmentDeclaration()) {
addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de);
return;
}
ClassNode cNode = de.getDeclaringClass();
ClassNode baseScriptType = de.getVariableExpression().getType().getPlainNodeReference();
if (baseScriptType.isScript()) {
if (!(de.getRightExpression() instanceof EmptyExpression)) {
addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de);
return;
}
de.setRightExpression(new VariableExpression("this"));
} else {
baseScriptType = BASE_SCRIPT_TYPE;
}
Expression value = node.getMember("value");
if (value != null) {
addError("Annotation " + MY_TYPE_NAME + " cannot have member 'value' if used on a declaration.", value);
return;
}
changeBaseScriptType(source, de, cNode, baseScriptType, node);
}
示例2
@Override
public void visitDeclarationExpression(DeclarationExpression expression) {
// if we are in the same block we check position, if it occurs after
// current position we ignore it
if (blocks.isEmpty()
&& expression.getLineNumber() >= 0 && expression.getColumnNumber() >= 0
&& path.getLineNumber() >= 0 && path.getColumnNumber() >= 0
&& (expression.getLineNumber() > path.getLineNumber()
|| (expression.getLineNumber() == path.getLineNumber() && expression.getColumnNumber() >= path.getColumnNumber()))) {
return;
}
if (!expression.isMultipleAssignmentDeclaration()) {
VariableExpression variableExpression = expression.getVariableExpression();
if (variableExpression.getAccessedVariable() != null) {
String name = variableExpression.getAccessedVariable().getName();
variables.put(name, variableExpression.getAccessedVariable());
}
}
// perhaps we could visit just declaration or do nothing
super.visitDeclarationExpression(expression);
}
示例3
@Override
public void visitDeclarationExpression(DeclarationExpression expression) {
if (currentClassDoc.isScript()) {
if (hasAnno(expression, "Field")) {
VariableExpression varx = expression.getVariableExpression();
SimpleGroovyFieldDoc field = new SimpleGroovyFieldDoc(varx.getName(), currentClassDoc);
field.setType(new SimpleGroovyType(makeType(varx.getType())));
int mods = varx.getModifiers();
processModifiers(field, varx, mods);
boolean isProp = (mods & (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED)) == 0;
if (isProp) {
currentClassDoc.addProperty(field);
} else {
currentClassDoc.add(field);
}
}
}
super.visitDeclarationExpression(expression);
}
示例4
private ExpressionStatement makeVariableDeclarationFinal(ExpressionStatement variableDeclaration) {
if (!asBoolean(variableDeclaration)) {
return variableDeclaration;
}
if (!(variableDeclaration.getExpression() instanceof DeclarationExpression)) {
throw new IllegalArgumentException("variableDeclaration is not a declaration statement");
}
DeclarationExpression declarationExpression = (DeclarationExpression) variableDeclaration.getExpression();
if (!(declarationExpression.getLeftExpression() instanceof VariableExpression)) {
throw astBuilder.createParsingFailedException("The expression statement is not a variable delcaration statement", variableDeclaration);
}
VariableExpression variableExpression = (VariableExpression) declarationExpression.getLeftExpression();
variableExpression.setModifiers(variableExpression.getModifiers() | Opcodes.ACC_FINAL);
return variableDeclaration;
}
示例5
protected Expression transformDeclarationExpression(final DeclarationExpression de) {
visitAnnotations(de);
Expression oldLeft = de.getLeftExpression();
checkingVariableTypeInDeclaration = true;
Expression left = transform(oldLeft);
checkingVariableTypeInDeclaration = false;
if (left instanceof ClassExpression) {
ClassExpression ce = (ClassExpression) left;
addError("you tried to assign a value to the class " + ce.getType().getName(), oldLeft);
return de;
}
Expression right = transform(de.getRightExpression());
if (right == de.getRightExpression()) {
fixDeclaringClass(de);
return de;
}
DeclarationExpression newDeclExpr = new DeclarationExpression(left, de.getOperation(), right);
newDeclExpr.setDeclaringClass(de.getDeclaringClass());
newDeclExpr.addAnnotations(de.getAnnotations());
newDeclExpr.copyNodeMetaData(de);
fixDeclaringClass(newDeclExpr);
return newDeclExpr;
}
示例6
private void setScriptURIOnDeclaration(final DeclarationExpression de, final AnnotationNode node) {
if (de.isMultipleAssignmentDeclaration()) {
addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de);
return;
}
if (!(de.getRightExpression() instanceof EmptyExpression)) {
addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de);
return;
}
URI uri = getSourceURI(node);
if (uri == null) {
addError("Unable to get the URI for the source of this script!", de);
} else {
// Set the RHS to '= URI.create("string for this URI")'.
// That may throw an IllegalArgumentExpression wrapping the URISyntaxException.
de.setRightExpression(getExpression(uri));
}
}
示例7
private void changeBaseScriptTypeFromDeclaration(final DeclarationExpression de, final AnnotationNode node) {
if (de.isMultipleAssignmentDeclaration()) {
addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de);
return;
}
if (!(de.getRightExpression() instanceof EmptyExpression)) {
addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de);
return;
}
Expression value = node.getMember("value");
if (value != null) {
addError("Annotation " + MY_TYPE_NAME + " cannot have member 'value' if used on a declaration.", value);
return;
}
ClassNode cNode = de.getDeclaringClass();
ClassNode baseScriptType = de.getVariableExpression().getType().getPlainNodeReference();
de.setRightExpression(new VariableExpression("this"));
changeBaseScriptType(de, cNode, baseScriptType);
}
示例8
public void visit(ASTNode[] nodes, SourceUnit source) {
this.source = source;
if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
internalError("Expecting [AnnotationNode, AnnotatedClass] but got: " + Arrays.asList(nodes));
}
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(node.getClassNode())) {
internalError("Transformation called from wrong annotation: " + node.getClassNode().getName());
}
final boolean autoFlag = determineAutoFlag(node.getMember("auto"));
final Expression classNames = node.getMember("value");
final Pattern cnPattern = determineClassNamePattern(node.getMember("pattern"));
if (parent instanceof ClassNode) {
newifyClass((ClassNode) parent, autoFlag, determineClasses(classNames, false), cnPattern);
} else if (parent instanceof MethodNode || parent instanceof FieldNode) {
newifyMethodOrField(parent, autoFlag, determineClasses(classNames, false), cnPattern);
} else if (parent instanceof DeclarationExpression) {
newifyDeclaration((DeclarationExpression) parent, autoFlag, determineClasses(classNames, true), cnPattern);
}
}
示例9
private void newifyDeclaration(DeclarationExpression de, boolean autoFlag, ListExpression list, final Pattern cnPattern) {
ClassNode cNode = de.getDeclaringClass();
candidate = de;
final ListExpression oldClassesToNewify = classesToNewify;
final boolean oldAuto = auto;
final Pattern oldCnPattern = classNamePattern;
classesToNewify = list;
auto = autoFlag;
classNamePattern = cnPattern;
super.visitClass(cNode);
classesToNewify = oldClassesToNewify;
auto = oldAuto;
classNamePattern = oldCnPattern;
}
示例10
public static ClassNode[] parseClassNodesFromString(final String option, final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final MethodNode mn, final ASTNode usage) {
try {
ModuleNode moduleNode = ParserPlugin.buildAST("Dummy<" + option + "> dummy;", compilationUnit.getConfiguration(), compilationUnit.getClassLoader(), null);
DeclarationExpression dummyDeclaration = (DeclarationExpression) ((ExpressionStatement) moduleNode.getStatementBlock().getStatements().get(0)).getExpression();
// the returned node is DummyNode<Param1, Param2, Param3, ...)
ClassNode dummyNode = dummyDeclaration.getLeftExpression().getType();
GenericsType[] dummyNodeGenericsTypes = dummyNode.getGenericsTypes();
if (dummyNodeGenericsTypes == null) {
return null;
}
ClassNode[] signature = new ClassNode[dummyNodeGenericsTypes.length];
for (int i = 0, n = dummyNodeGenericsTypes.length; i < n; i += 1) {
final GenericsType genericsType = dummyNodeGenericsTypes[i];
signature[i] = resolveClassNode(sourceUnit, compilationUnit, mn, usage, genericsType.getType());
}
return signature;
} catch (Exception | LinkageError e) {
sourceUnit.addError(new IncorrectTypeHintException(mn, e, usage.getLineNumber(), usage.getColumnNumber()));
}
return null;
}
示例11
@Override
public void visitDeclarationExpression(DeclarationExpression expression) {
super.visitDeclarationExpression(expression);
if (expression.isMultipleAssignmentDeclaration()) return;
checkInvalidDeclarationModifier(expression, ACC_ABSTRACT, "abstract");
checkInvalidDeclarationModifier(expression, ACC_NATIVE, "native");
checkInvalidDeclarationModifier(expression, ACC_PRIVATE, "private");
checkInvalidDeclarationModifier(expression, ACC_PROTECTED, "protected");
checkInvalidDeclarationModifier(expression, ACC_PUBLIC, "public");
checkInvalidDeclarationModifier(expression, ACC_STATIC, "static");
checkInvalidDeclarationModifier(expression, ACC_STRICT, "strictfp");
checkInvalidDeclarationModifier(expression, ACC_SYNCHRONIZED, "synchronized");
checkInvalidDeclarationModifier(expression, ACC_TRANSIENT, "transient");
checkInvalidDeclarationModifier(expression, ACC_VOLATILE, "volatile");
if (expression.getVariableExpression().getOriginType().equals(VOID_TYPE)) {
addError("The variable '" + expression.getVariableExpression().getName() + "' has invalid type void", expression);
}
}
示例12
@Override
public void visitBinaryExpression(final BinaryExpression expression) {
boolean assignment = StaticTypeCheckingSupport.isAssignment(expression.getOperation().getType());
boolean isDeclaration = expression instanceof DeclarationExpression;
Expression leftExpression = expression.getLeftExpression();
Expression rightExpression = expression.getRightExpression();
if (isDeclaration) {
recordFinalVars(leftExpression);
}
// visit RHS first for expressions like a = b = 0
inAssignmentRHS = assignment;
rightExpression.visit(this);
inAssignmentRHS = false;
leftExpression.visit(this);
if (assignment) {
recordAssignments(expression, isDeclaration, leftExpression, rightExpression);
}
}
示例13
@Override
public void visitDeclarationExpression(final DeclarationExpression expression) {
Expression rightExpression = expression.getRightExpression();
rightExpression.visit(this);
ClassNode leftType = typeChooser.resolveType(expression.getLeftExpression(), node);
ClassNode rightType = optimizeDivWithIntOrLongTarget(rightExpression, leftType);
if (rightType == null) rightType = typeChooser.resolveType(rightExpression, node);
if (isPrimitiveType(leftType) && isPrimitiveType(rightType)) {
// if right is a constant, then we optimize only if it makes a block complete, so we set a maybe
if (rightExpression instanceof ConstantExpression) {
opt.chainCanOptimize(true);
} else {
opt.chainShouldOptimize(true);
}
addMeta(expression).type = Optional.ofNullable(typeChooser.resolveType(expression, node)).orElse(leftType);
opt.chainInvolvedType(leftType);
opt.chainInvolvedType(rightType);
}
}
示例14
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source);
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
if (MAVEN_TYPE.equals( node.getClassNode()) || GRADLE_TYPE.equals( node.getClassNode() ))
{
type = ( MAVEN_TYPE.equals( node.getClassNode()) ) ? Type.MAVEN : Type.GRADLE;
if ( parent instanceof DeclarationExpression )
{
changeBaseScriptTypeFromDeclaration( (DeclarationExpression) parent, node );
}
else if ( parent instanceof ImportNode || parent instanceof PackageNode )
{
changeBaseScriptTypeFromPackageOrImport( source, parent, node );
}
else if ( parent instanceof ClassNode )
{
changeBaseScriptTypeFromClass( (ClassNode) parent );
}
}
}
示例15
@Test
public void should_not_add_to_unknonwn_variables_a_variable_declared_but_not_in_the_process_scope() throws Exception {
final BonitaScriptGroovyCompilationUnit groovyCompilationUnit = mock(BonitaScriptGroovyCompilationUnit.class, RETURNS_DEEP_STUBS);
final List<Statement> statements = new ArrayList<Statement>();
statements.add(new ExpressionStatement(
new DeclarationExpression(new VariableExpression("declaredVar"), Token.NULL, new VariableExpression("something"))));
statements.add(new ReturnStatement(new VariableExpression("declaredVar")));
final VariableScope variableScope = new VariableScope();
variableScope.putDeclaredVariable(new VariableExpression("declaredVar"));
final BlockStatement blockStatement = new BlockStatement(statements, variableScope);
when(groovyCompilationUnit.getModuleNode().getStatementBlock()).thenReturn(blockStatement);
final UnknownElementsIndexer unknownElementsIndexer = new UnknownElementsIndexer(groovyCompilationUnit);
unknownElementsIndexer.run(new NullProgressMonitor());
assertThat(unknownElementsIndexer.getUnknownVaraibles()).isEmpty();
}
示例16
@Test
public void should_add_to_overriden_variables_a_variable_declared_and_already_in_the_process_scope() throws Exception {
final BonitaScriptGroovyCompilationUnit groovyCompilationUnit = mock(BonitaScriptGroovyCompilationUnit.class, RETURNS_DEEP_STUBS);
Map<String, ScriptVariable> context = new HashMap<String, ScriptVariable>();
context.put("declaredVar", null);
when(groovyCompilationUnit.getContext()).thenReturn(context);
final List<Statement> statements = new ArrayList<Statement>();
statements.add(new ExpressionStatement(
new DeclarationExpression(new VariableExpression("declaredVar"), Token.NULL, new VariableExpression("something"))));
statements.add(new ReturnStatement(new VariableExpression("declaredVar")));
final VariableScope variableScope = new VariableScope();
variableScope.putDeclaredVariable(new VariableExpression("declaredVar"));
final BlockStatement blockStatement = new BlockStatement(statements, variableScope);
when(groovyCompilationUnit.getModuleNode().getStatementBlock()).thenReturn(blockStatement);
final UnknownElementsIndexer unknownElementsIndexer = new UnknownElementsIndexer(groovyCompilationUnit);
unknownElementsIndexer.run(new NullProgressMonitor());
assertThat(unknownElementsIndexer.getOverridenVariables()).containsExactly(entry("declaredVar", new Position(0)));
}
示例17
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source);
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(node.getClassNode())) return;
if (parent instanceof DeclarationExpression) {
changeBaseScriptTypeFromDeclaration(source, (DeclarationExpression) parent, node);
} else if (parent instanceof ImportNode || parent instanceof PackageNode) {
changeBaseScriptTypeFromPackageOrImport(source, parent, node);
} else if (parent instanceof ClassNode) {
changeBaseScriptTypeFromClass(source, (ClassNode) parent, node);
}
}
示例18
private static OffsetRange getDeclarationExpressionRange(DeclarationExpression expression, BaseDocument doc, int cursorOffset) {
OffsetRange range;
if (!expression.isMultipleAssignmentDeclaration()) {
range = getVariableRange(expression.getVariableExpression(), doc, cursorOffset);
} else {
range = getRange(expression.getTupleExpression(), doc, cursorOffset);
}
return range;
}
示例19
@Override
public void visitDeclarationExpression(DeclarationExpression expression) {
ClassNode visitedType;
if (!expression.isMultipleAssignmentDeclaration()) {
visitedType = expression.getVariableExpression().getType();
} else {
visitedType = expression.getTupleExpression().getType();
}
if (FindTypeUtils.isCaretOnClassNode(path, doc, cursorOffset)) {
addOccurrences(visitedType, (ClassNode) FindTypeUtils.findCurrentNode(path, doc, cursorOffset));
}
super.visitDeclarationExpression(expression);
}
示例20
@Override
public void visitMethod(MethodNode methodNode) {
VariableScope variableScope = methodNode.getVariableScope();
if (FindTypeUtils.isCaretOnClassNode(path, doc, cursorOffset)) {
addMethodOccurrences(methodNode, (ClassNode) FindTypeUtils.findCurrentNode(path, doc, cursorOffset));
} else {
if (leaf instanceof Variable) {
String name = ((Variable) leaf).getName();
// This check is here because we can have method parameter with the same
// name hidding property/field and we don't want to show occurences of these
if (variableScope != null && variableScope.getDeclaredVariable(name) != null) {
return;
}
} else if (leaf instanceof MethodNode) {
if (Methods.isSameMethod(methodNode, (MethodNode) leaf)) {
occurrences.add(methodNode);
}
} else if (leaf instanceof DeclarationExpression) {
VariableExpression variable = ((DeclarationExpression) leaf).getVariableExpression();
if (!variable.isDynamicTyped() && !methodNode.isDynamicReturnType()) {
addMethodOccurrences(methodNode, variable.getType());
}
} else if (leaf instanceof ConstantExpression && leafParent instanceof MethodCallExpression) {
MethodCallExpression methodCallExpression = (MethodCallExpression) leafParent;
if (Methods.isSameMethod(methodNode, methodCallExpression)) {
occurrences.add(methodNode);
}
}
}
super.visitMethod(methodNode);
}
示例21
private String getFqNameForNode(ASTNode node) {
if (node instanceof DeclarationExpression) {
return ((BinaryExpression) node).getLeftExpression().getType().getName();
} else if (node instanceof Expression) {
return ((Expression) node).getType().getName();
} else if (node instanceof PropertyNode) {
return ((PropertyNode) node).getField().getType().getName();
} else if (node instanceof FieldNode) {
return ((FieldNode) node).getType().getName();
} else if (node instanceof Parameter) {
return ((Parameter) node).getType().getName();
}
return "";
}
示例22
private void extractModelTypesFromStatement(final Statement code, final Map<String, ClassNode> model) {
if (code instanceof BlockStatement) {
BlockStatement block = (BlockStatement) code;
for (Statement statement : block.getStatements()) {
extractModelTypesFromStatement(statement, model);
}
} else if (code instanceof ExpressionStatement) {
Expression expression = ((ExpressionStatement) code).getExpression();
if (expression instanceof DeclarationExpression) {
VariableExpression var = ((DeclarationExpression) expression).getVariableExpression();
model.put(var.getName(), var.getOriginType());
}
}
}
示例23
@Override
public Expression transform(final Expression exp) {
if (exp == null) return null;
Expression ret;
if (exp instanceof VariableExpression) {
ret = transformVariableExpression((VariableExpression) exp);
} else if (exp.getClass() == PropertyExpression.class) {
ret = transformPropertyExpression((PropertyExpression) exp);
} else if (exp instanceof DeclarationExpression) {
ret = transformDeclarationExpression((DeclarationExpression) exp);
} else if (exp instanceof BinaryExpression) {
ret = transformBinaryExpression((BinaryExpression) exp);
} else if (exp instanceof MethodCallExpression) {
ret = transformMethodCallExpression((MethodCallExpression) exp);
} else if (exp instanceof ClosureExpression) {
ret = transformClosureExpression((ClosureExpression) exp);
} else if (exp instanceof ConstructorCallExpression) {
ret = transformConstructorCallExpression((ConstructorCallExpression) exp);
} else if (exp instanceof AnnotationConstantExpression) {
ret = transformAnnotationConstantExpression((AnnotationConstantExpression) exp);
} else {
resolveOrFail(exp.getType(), exp);
ret = exp.transformExpression(this);
}
if (ret != null && ret != exp) {
ret.setSourcePosition(exp);
}
return ret;
}
示例24
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source);
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(node.getClassNode())) return;
if (parent instanceof DeclarationExpression) {
setScriptURIOnDeclaration((DeclarationExpression) parent, node);
} else if (parent instanceof FieldNode) {
setScriptURIOnField((FieldNode) parent, node);
} else {
addError("Expected to find the annotation " + MY_TYPE_NAME + " on an declaration statement.", parent);
}
}
示例25
private void process(ASTNode[] nodes, final ClassCodeVisitorSupport visitor) {
candidate = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(node.getClassNode())) return;
if (candidate instanceof ClassNode) {
processClass((ClassNode) candidate, visitor);
} else if (candidate instanceof MethodNode) {
processConstructorOrMethod((MethodNode) candidate, visitor);
} else if (candidate instanceof FieldNode) {
processField((FieldNode) candidate, visitor);
} else if (candidate instanceof DeclarationExpression) {
processLocalVariable((DeclarationExpression) candidate, visitor);
}
}
示例26
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source);
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(node.getClassNode())) return;
if (parent instanceof DeclarationExpression) {
changeBaseScriptTypeFromDeclaration((DeclarationExpression) parent, node);
} else if (parent instanceof ImportNode || parent instanceof PackageNode) {
changeBaseScriptTypeFromPackageOrImport(source, parent, node);
} else if (parent instanceof ClassNode) {
changeBaseScriptTypeFromClass((ClassNode) parent, node);
}
}
示例27
private static DeclarationExpression optimizeConstantInitialization(final BinaryExpression originalDeclaration, final Token operation, final ConstantExpression constant, final Expression leftExpression, final ClassNode declarationType) {
Expression cexp = constX(convertConstant((Number) constant.getValue(), ClassHelper.getWrapper(declarationType)), true);
cexp.setType(declarationType);
cexp.setSourcePosition(constant);
DeclarationExpression result = new DeclarationExpression(
leftExpression,
operation,
cexp
);
result.setSourcePosition(originalDeclaration);
result.copyNodeMetaData(originalDeclaration);
return result;
}
示例28
@Override
public Expression transform(Expression expr) {
if (expr == null) return null;
if (expr instanceof DeclarationExpression) {
DeclarationExpression de = (DeclarationExpression) expr;
if (de.getLeftExpression() == candidate.getLeftExpression()) {
if (insideScriptBody) {
// TODO make EmptyExpression work
// partially works but not if only thing in script
// return EmptyExpression.INSTANCE;
return nullX();
}
addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script body.", expr);
return expr;
}
} else if (insideScriptBody && expr instanceof VariableExpression && currentClosure != null) {
VariableExpression ve = (VariableExpression) expr;
if (ve.getName().equals(variableName)) {
adjustToClassVar(ve);
return ve;
}
} else if (currentAIC != null && expr instanceof ArgumentListExpression) {
// if a match is found, the compiler will have already set up aic constructor to hav
// an argument which isn't needed since we'll be accessing the field; we must undo it
Expression skip = null;
List<Expression> origArgList = ((ArgumentListExpression) expr).getExpressions();
for (int i = 0; i < origArgList.size(); i++) {
Expression arg = origArgList.get(i);
if (matchesCandidate(arg)) {
skip = arg;
adjustConstructorAndFields(i, currentAIC.getType());
break;
}
}
if (skip != null) {
return adjustedArgList(skip, origArgList);
}
}
return expr.transformExpression(this);
}
示例29
public void addResource(ExpressionStatement resourceStatement) {
Expression resourceExpression = resourceStatement.getExpression();
if (!(resourceExpression instanceof DeclarationExpression || resourceExpression instanceof VariableExpression)) {
throw new GroovyBugError("resourceStatement should be a variable declaration statement or a variable");
}
resourceExpression.putNodeMetaData(IS_RESOURCE, Boolean.TRUE);
resourceStatements.add(resourceStatement);
}
示例30
@Override
public void visitDeclarationExpression(final DeclarationExpression expression) {
visitAnnotations(expression);
// visit right side first to prevent the use of a variable before its declaration
expression.getRightExpression().visit(this);
if (expression.isMultipleAssignmentDeclaration()) {
TupleExpression list = expression.getTupleExpression();
for (Expression listExpression : list.getExpressions()) {
declare((VariableExpression) listExpression);
}
} else {
declare(expression.getVariableExpression());
}
}