本文整理汇总了Java中org.codehaus.groovy.ast.expr.DeclarationExpression类的典型用法代码示例。如果您正苦于以下问题:Java DeclarationExpression类的具体用法?Java DeclarationExpression怎么用?Java DeclarationExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DeclarationExpression类属于org.codehaus.groovy.ast.expr包,在下文中一共展示了DeclarationExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeBaseScriptTypeFromDeclaration
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
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;
}
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(source, de, cNode, baseScriptType, node);
}
示例2: transformationOfAnnotationOnLocalVariable
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的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
示例3: makeVariableDeclarationFinal
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
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;
}
示例4: visitVariableDeclarator
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
@Override
public DeclarationExpression visitVariableDeclarator(VariableDeclaratorContext ctx) {
ClassNode variableType = ctx.getNodeMetaData(VARIABLE_DECLARATION_VARIABLE_TYPE);
Objects.requireNonNull(variableType, "variableType should not be null");
org.codehaus.groovy.syntax.Token token;
if (asBoolean(ctx.ASSIGN())) {
token = createGroovyTokenByType(ctx.ASSIGN().getSymbol(), Types.ASSIGN);
} else {
token = new org.codehaus.groovy.syntax.Token(Types.ASSIGN, ASSIGN_STR, ctx.start.getLine(), 1);
}
return configureAST(
new DeclarationExpression(
configureAST(
new VariableExpression(
this.visitVariableDeclaratorId(ctx.variableDeclaratorId()).getName(),
variableType
),
ctx.variableDeclaratorId()),
token,
this.visitVariableInitializer(ctx.variableInitializer())),
ctx);
}
示例5: transform
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
public Expression transform(Expression exp) {
if (exp == null) return null;
Expression ret = null;
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;
}
示例6: transformDeclarationExpression
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
protected Expression transformDeclarationExpression(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());
fixDeclaringClass(newDeclExpr);
newDeclExpr.setSourcePosition(de);
newDeclExpr.addAnnotations(de.getAnnotations());
return newDeclExpr;
}
示例7: setScriptURIOnDeclaration
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
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));
}
}
示例8: changeBaseScriptTypeFromDeclaration
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
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);
}
示例9: optimizeConstantInitialization
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
private static DeclarationExpression optimizeConstantInitialization(
final BinaryExpression originalDeclaration,
final Token operation,
final ConstantExpression constant,
final Expression leftExpression,
final ClassNode declarationType) {
ConstantExpression cexp = new ConstantExpression(
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;
}
示例10: visit
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
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());
}
boolean autoFlag = determineAutoFlag(node.getMember("auto"));
Expression value = node.getMember("value");
if (parent instanceof ClassNode) {
newifyClass((ClassNode) parent, autoFlag, determineClasses(value, false));
} else if (parent instanceof MethodNode || parent instanceof FieldNode) {
newifyMethodOrField(parent, autoFlag, determineClasses(value, false));
} else if (parent instanceof DeclarationExpression) {
newifyDeclaration((DeclarationExpression) parent, autoFlag, determineClasses(value, true));
}
}
示例11: visitDeclarationExpression
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
@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: visitBinaryExpression
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
@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
inAssignment = assignment;
rightExpression.visit(this);
inAssignment = false;
leftExpression.visit(this);
if (assignment) {
recordAssignments(expression, isDeclaration, leftExpression, rightExpression);
}
}
示例13: visitDeclarationExpression
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
@Override
public void visitDeclarationExpression(DeclarationExpression expression) {
Expression right = expression.getRightExpression();
right.visit(this);
ClassNode leftType = typeChooser.resolveType(expression.getLeftExpression(), node);
Expression rightExpression = expression.getRightExpression();
ClassNode rightType = optimizeDivWithIntOrLongTarget(rightExpression, leftType);
if (rightType==null) rightType = typeChooser.resolveType(expression.getRightExpression(), 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 (right instanceof ConstantExpression) {
opt.chainCanOptimize(true);
} else {
opt.chainShouldOptimize(true);
}
StatementMeta meta = addMeta(expression);
ClassNode declarationType = typeChooser.resolveType(expression, node);
meta.type = declarationType!=null?declarationType:leftType;
opt.chainInvolvedType(leftType);
opt.chainInvolvedType(rightType);
}
}
示例14: visit
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
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);
}
}
示例15: completeFutureByResults
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
protected void completeFutureByResults(CompletableFuture<EGradleBuildscriptResult> future, List<ASTNode> result) {
for (ASTNode node : result) {
BlockStatement bs = (BlockStatement) node;
for (org.codehaus.groovy.ast.stmt.Statement st : bs.getStatements()) {
if (st instanceof ReturnStatement) {
ReturnStatement rs = (ReturnStatement) st;
Expression expression = rs.getExpression();
if (expression instanceof DeclarationExpression) {
DeclarationExpression de = (DeclarationExpression) expression;
String name = de.getVariableExpression().getName();
if (! "buildscript".equals(name)){
continue;
}
Expression right = de.getRightExpression();
if (right instanceof ClosureExpression) {
ClosureExpression ce = (ClosureExpression) right;
Statement buildCode = ce.getCode();
future.complete(new EGradleBuildscriptResult(buildCode));
return;
}else{
future.complete(new EGradleBuildscriptResult(new EGradleBuildScriptException("Did not found expected buildscript closure ,but:"+right)));
return;
}
}
}
}
}
}