本文整理汇总了Java中org.codehaus.groovy.ast.expr.DeclarationExpression类的典型用法代码示例。如果您正苦于以下问题:Java DeclarationExpression类的具体用法?Java DeclarationExpression怎么用?Java DeclarationExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DeclarationExpression类属于org.codehaus.groovy.ast.expr包,在下文中一共展示了DeclarationExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:remkop,项目名称:picocli,代码行数:23,代码来源:PicocliScriptASTTransformation.java
示例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;
}
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:TryWithResourcesASTTransformation.java
示例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);
}
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:AstBuilder.java
示例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;
}
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:ResolveVisitor.java
示例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;
}
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:ResolveVisitor.java
示例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));
}
}
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:SourceURIASTTransformation.java
示例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);
}
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:BaseScriptASTTransformation.java
示例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;
}
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:BinaryExpressionTransformer.java
示例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));
}
}
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:NewifyASTTransformation.java
示例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);
}
}
开发者ID:apache,项目名称:groovy,代码行数:19,代码来源:ClassCompletionVerifier.java
示例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);
}
}
开发者ID:apache,项目名称:groovy,代码行数:19,代码来源:FinalVariableAnalyzer.java
示例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);
}
}
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:OptimizingStatementWriter.java
示例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);
}
}
开发者ID:remkop,项目名称:picocli,代码行数:15,代码来源:PicocliScriptASTTransformation.java
示例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;
}
}
}
}
}
}
开发者ID:de-jcup,项目名称:egradle,代码行数:30,代码来源:GradleBuildScriptResultBuilder.java
示例16: transform
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
@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 new ConstantExpression(null);
}
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)) {
// we may only check the variable name because the Groovy compiler
// already fails if a variable with the same name already exists in the scope.
// this means that a closure cannot shadow a class variable
ve.setAccessedVariable(fieldNode);
final VariableScope variableScope = currentClosure.getVariableScope();
final Iterator<Variable> iterator = variableScope.getReferencedLocalVariablesIterator();
while (iterator.hasNext()) {
Variable next = iterator.next();
if (next.getName().equals(variableName)) iterator.remove();
}
variableScope.putReferencedClassVariable(fieldNode);
return ve;
}
}
return expr.transformExpression(this);
}
开发者ID:nickman,项目名称:HeliosStreams,代码行数:35,代码来源:VolatileFieldASTTransformation.java
示例17: extractModelTypesFromStatement
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
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());
}
}
}
开发者ID:apache,项目名称:groovy,代码行数:15,代码来源:MarkupBuilderCodeTransformer.java
示例18: createMultiAssignmentDeclarationListStatement
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
private DeclarationListStatement createMultiAssignmentDeclarationListStatement(VariableDeclarationContext ctx, ModifierManager modifierManager) {
/*
if (!modifierManager.contains(DEF)) {
throw createParsingFailedException("keyword def is required to declare tuple, e.g. def (int a, int b) = [1, 2]", ctx);
}
*/
return configureAST(
new DeclarationListStatement(
configureAST(
modifierManager.attachAnnotations(
new DeclarationExpression(
new ArgumentListExpression(
this.visitTypeNamePairs(ctx.typeNamePairs()).stream()
.peek(e -> modifierManager.processVariableExpression((VariableExpression) e))
.collect(Collectors.toList())
),
this.createGroovyTokenByType(ctx.ASSIGN().getSymbol(), Types.ASSIGN),
this.visitVariableInitializer(ctx.variableInitializer())
)
),
ctx
)
),
ctx
);
}
开发者ID:apache,项目名称:groovy,代码行数:28,代码来源:AstBuilder.java
示例19: createFieldDeclarationListStatement
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
private DeclarationListStatement createFieldDeclarationListStatement(VariableDeclarationContext ctx, ModifierManager modifierManager, ClassNode variableType, List<DeclarationExpression> declarationExpressionList, ClassNode classNode) {
for (int i = 0, n = declarationExpressionList.size(); i < n; i++) {
DeclarationExpression declarationExpression = declarationExpressionList.get(i);
VariableExpression variableExpression = (VariableExpression) declarationExpression.getLeftExpression();
String fieldName = variableExpression.getName();
int modifiers = modifierManager.getClassMemberModifiersOpValue();
Expression initialValue = EmptyExpression.INSTANCE.equals(declarationExpression.getRightExpression()) ? null : declarationExpression.getRightExpression();
Object defaultValue = findDefaultValueByType(variableType);
if (classNode.isInterface()) {
if (!asBoolean(initialValue)) {
initialValue = !asBoolean(defaultValue) ? null : new ConstantExpression(defaultValue);
}
modifiers |= Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL;
}
if (isFieldDeclaration(modifierManager, classNode)) {
declareField(ctx, modifierManager, variableType, classNode, i, variableExpression, fieldName, modifiers, initialValue);
} else {
declareProperty(ctx, modifierManager, variableType, classNode, i, variableExpression, fieldName, modifiers, initialValue);
}
}
return null;
}
开发者ID:apache,项目名称:groovy,代码行数:30,代码来源:AstBuilder.java
示例20: visitVariableDeclarators
import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入依赖的package包/类
@Override
public List<DeclarationExpression> visitVariableDeclarators(VariableDeclaratorsContext ctx) {
ClassNode variableType = ctx.getNodeMetaData(VARIABLE_DECLARATION_VARIABLE_TYPE);
Objects.requireNonNull(variableType, "variableType should not be null");
return ctx.variableDeclarator().stream()
.map(e -> {
e.putNodeMetaData(VARIABLE_DECLARATION_VARIABLE_TYPE, variableType);
return this.visitVariableDeclarator(e);
// return this.configureAST(this.visitVariableDeclarator(e), ctx);
})
.collect(Collectors.toList());
}
开发者ID:apache,项目名称:groovy,代码行数:14,代码来源:AstBuilder.java
注:本文中的org.codehaus.groovy.ast.expr.DeclarationExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论