本文整理汇总了Java中org.codehaus.groovy.ast.expr.VariableExpression.getName方法的典型用法代码示例。如果您正苦于以下问题:Java VariableExpression.getName方法的具体用法?Java VariableExpression.getName怎么用?Java VariableExpression.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.expr.VariableExpression
的用法示例。
在下文中一共展示了VariableExpression.getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tryTransformDelegateToProperty
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private static Expression tryTransformDelegateToProperty(VariableExpression expr) {
// we need to transform variable expressions that go to a delegate
// to a property expression, as ACG would loose the information
// in processClassVariable before it reaches any makeCall, that could
// handle it
Object val = expr.getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER);
if (val == null) return null;
VariableExpression implicitThis = new VariableExpression("this");
PropertyExpression pexp = new PropertyExpression(implicitThis, expr.getName());
pexp.copyNodeMetaData(expr);
pexp.setImplicitThis(true);
pexp.getProperty().setSourcePosition(expr);
ClassNode owner = expr.getNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER);
if (owner != null) {
implicitThis.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, owner);
implicitThis.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, val);
}
return pexp;
}
示例2: tryTransformPrivateFieldAccess
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private static Expression tryTransformPrivateFieldAccess(VariableExpression expr) {
FieldNode field = expr.getNodeMetaData(StaticTypesMarker.PV_FIELDS_ACCESS);
if (field == null) {
field = expr.getNodeMetaData(StaticTypesMarker.PV_FIELDS_MUTATION);
}
if (field != null) {
// access to a private field from a section of code that normally doesn't have access to it, like a
// closure or an inner class
VariableExpression receiver = new VariableExpression("this");
PropertyExpression pexp = new PropertyExpression(
receiver,
expr.getName()
);
pexp.setImplicitThis(true);
pexp.getProperty().setSourcePosition(expr);
// put the receiver inferred type so that the class writer knows that it will have to call a bridge method
receiver.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, field.getDeclaringClass());
// add inferred type information
pexp.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, field.getOriginType());
return pexp;
}
return null;
}
示例3: processClassVariable
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private void processClassVariable(VariableExpression expression) {
if (passingParams && controller.isInScriptBody()) {
//TODO: check if this part is actually used
MethodVisitor mv = controller.getMethodVisitor();
// let's create a ScriptReference to pass into the closure
mv.visitTypeInsn(NEW, "org/codehaus/groovy/runtime/ScriptReference");
mv.visitInsn(DUP);
loadThisOrOwner();
mv.visitLdcInsn(expression.getName());
mv.visitMethodInsn(INVOKESPECIAL, "org/codehaus/groovy/runtime/ScriptReference", "<init>", "(Lgroovy/lang/Script;Ljava/lang/String;)V", false);
} else {
PropertyExpression pexp = new PropertyExpression(new VariableExpression("this"), expression.getName());
pexp.getObjectExpression().setSourcePosition(expression);
pexp.getProperty().setSourcePosition(expression);
pexp.setImplicitThis(true);
visitPropertyExpression(pexp);
}
}
示例4: correctAccessedVariable
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private static void correctAccessedVariable(final InnerClassNode closureClass, ClosureExpression ce) {
CodeVisitorSupport visitor = new CodeVisitorSupport() {
@Override
public void visitVariableExpression(VariableExpression expression) {
Variable v = expression.getAccessedVariable();
if (v==null) return;
if (!(v instanceof FieldNode)) return;
String name = expression.getName();
FieldNode fn = closureClass.getDeclaredField(name);
if (fn != null) { // only overwrite if we find something more specific
expression.setAccessedVariable(fn);
}
}
};
visitor.visitClosureExpression(ce);
}
示例5: createFieldDeclarationListStatement
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的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;
}
示例6: usesSuper
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private static boolean usesSuper(PropertyExpression pe) {
Expression expression = pe.getObjectExpression();
if (expression instanceof VariableExpression) {
VariableExpression varExp = (VariableExpression) expression;
String variable = varExp.getName();
return variable.equals("super");
}
return false;
}
示例7: visitVariableExpression
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
/**
* Visits a bare (unqualified) variable expression.
*/
public void visitVariableExpression(VariableExpression expression) {
String variableName = expression.getName();
//-----------------------------------------------------------------------
// SPECIAL CASES
// "this" for static methods is the Class instance
ClassNode classNode = controller.getClassNode();
//if (controller.isInClosure()) classNode = controller.getOutermostClass();
if (variableName.equals("this")) {
if (controller.isStaticMethod() || (!controller.getCompileStack().isImplicitThis() && controller.isStaticContext())) {
if (controller.isInClosure()) classNode = controller.getOutermostClass();
visitClassExpression(new ClassExpression(classNode));
} else {
loadThis(expression);
}
return;
}
// "super" also requires special handling
if (variableName.equals("super")) {
if (controller.isStaticMethod()) {
visitClassExpression(new ClassExpression(classNode.getSuperClass()));
} else {
loadThis(expression);
}
return;
}
BytecodeVariable variable = controller.getCompileStack().getVariable(variableName, false);
if (variable == null) {
processClassVariable(expression);
} else {
controller.getOperandStack().loadOrStoreVariable(variable, expression.isUseReferenceDirectly());
}
if (!controller.getCompileStack().isLHS()) controller.getAssertionWriter().record(expression);
}
示例8: visitVariableExpression
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
public void visitVariableExpression(VariableExpression expression) {
String name = expression.getName();
Variable v = checkVariableNameForDeclaration(name, expression);
if (v == null) return;
expression.setAccessedVariable(v);
checkVariableContextAccess(v, expression);
}
示例9: usesSuper
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private static boolean usesSuper(MethodCallExpression call) {
Expression expression = call.getObjectExpression();
if (expression instanceof VariableExpression) {
VariableExpression varExp = (VariableExpression) expression;
String variable = varExp.getName();
return variable.equals("super");
}
return false;
}
示例10: getConstructorArgumentType
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private static ClassNode getConstructorArgumentType(Expression arg, ConstructorNode node) {
if (!(arg instanceof VariableExpression)) return arg.getType();
VariableExpression vexp = (VariableExpression) arg;
String name = vexp.getName();
for (Parameter param : node.getParameters()) {
if (param.getName().equals(name)) {
return param.getType();
}
}
return vexp.getType();
}
示例11: visit
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
sourceUnit = source;
if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
throw new GroovyBugError("Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes));
}
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(node.getClassNode())) return;
final ClassNode declaringClass = parent.getDeclaringClass();
if (parent instanceof DeclarationExpression) {
DeclarationExpression de = (DeclarationExpression) parent;
ClassNode cNode = de.getDeclaringClass();
if (!cNode.isScript()) {
addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script.", parent);
return;
}
candidate = de;
// GROOVY-4548: temp fix to stop CCE until proper support is added
if (de.isMultipleAssignmentDeclaration()) {
addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", parent);
return;
}
VariableExpression ve = de.getVariableExpression();
variableName = ve.getName();
// set owner null here, it will be updated by addField
final int modifiers = ve.getModifiers() | Modifier.VOLATILE | Modifier.PUBLIC;
fieldNode = new FieldNode(variableName, modifiers, ve.getType(), null, de.getRightExpression());
fieldNode.setSourcePosition(de);
fieldNode.addAnnotation(node);
fieldNode.setInitialValueExpression(new FieldExpression(fieldNode));
cNode.addField(fieldNode);
// GROOVY-4833 : annotations that are not Groovy transforms should be transferred to the generated field
// GROOVY-6112 : also copy acceptable Groovy transforms
final List<AnnotationNode> annotations = de.getAnnotations();
for (AnnotationNode annotation : annotations) {
// GROOVY-6337 HACK: in case newly created field is @Lazy
if (annotation.getClassNode().equals(LAZY_TYPE)) {
PrivateAccessor.invokeStatic(LazyASTTransformation.class, "visitField", annotation, fieldNode);
// LazyASTTransformation.visitField(annotation, fieldNode);
}
// if(annotation.getClassNode().equals(MY_TYPE)) {
// final Map<String, Expression> members = annotation.getMembers();
// final Expression expr = members.remove("value");
// if(expr!=null) {
// final String exprValue = expr.getText();
// System.err.println("EXPR:" + exprValue);
// }
// }
final ClassNode annotationClassNode = annotation.getClassNode();
if (notTransform(annotationClassNode) || acceptableTransform(annotation)) {
fieldNode.addAnnotation(annotation);
}
}
super.visitClass(cNode);
// GROOVY-5207 So that Closures can see newly added fields
// (not super efficient for a very large class with many @Fields but we chose simplicity
// and understandability of this solution over more complex but efficient alternatives)
VariableScopeVisitor scopeVisitor = new VariableScopeVisitor(source);
scopeVisitor.visitClass(cNode);
}
}
示例12: transform
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
@Override
public Expression transform(final Expression exp) {
if (exp instanceof BinaryExpression) {
return transformBinaryExpression((BinaryExpression) exp);
}
if (exp instanceof MethodCallExpression) {
return transformMethodCall((MethodCallExpression) exp);
}
if (exp instanceof ClosureExpression) {
ClosureExpression cl = (ClosureExpression) exp;
cl.getCode().visit(this);
return cl;
}
if (exp instanceof VariableExpression) {
VariableExpression var = (VariableExpression) exp;
if (var.getAccessedVariable() instanceof DynamicVariable) {
MethodCallExpression callGetModel = new MethodCallExpression(
new VariableExpression("this"),
"getModel",
ArgumentListExpression.EMPTY_ARGUMENTS
);
callGetModel.setImplicitThis(true);
callGetModel.setSourcePosition(exp);
String varName = var.getName();
if ("model".equals(varName) || "unescaped".equals(varName)) {
return callGetModel;
}
MethodCallExpression mce = new MethodCallExpression(
callGetModel,
"get",
new ArgumentListExpression(new ConstantExpression(varName))
);
mce.setSourcePosition(exp);
mce.setImplicitThis(false);
MethodCallExpression yield = new MethodCallExpression(
new VariableExpression("this"),
"tryEscape",
new ArgumentListExpression(mce)
);
yield.setImplicitThis(true);
yield.setSourcePosition(exp);
yield.putNodeMetaData(TARGET_VARIABLE, varName);
return autoEscape?yield:mce;
}
}
return super.transform(exp);
}
示例13: visitVariableExpression
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
@Override
public void visitVariableExpression(VariableExpression expression) {
throw new GroovyRuntimeException("DataSet currently doesn't support arbitrary variables, only literals: found attempted reference to variable '" + expression.getName() + "'");
}
示例14: lookupClassName
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
private static String lookupClassName(PropertyExpression pe) {
boolean doInitialClassTest=true;
String name = "";
// this loop builds a name from right to left each name part
// separated by "."
for (Expression it = pe; it != null; it = ((PropertyExpression) it).getObjectExpression()) {
if (it instanceof VariableExpression) {
VariableExpression ve = (VariableExpression) it;
// stop at super and this
if (ve.isSuperExpression() || ve.isThisExpression()) {
return null;
}
String varName = ve.getName();
if (doInitialClassTest) {
// we are at the first name part. This is the right most part.
// If this part is in lower case, then we do not need a class
// check. other parts of the property expression will be tested
// by a different method call to this method, so foo.Bar.bar
// can still be resolved to the class foo.Bar and the static
// field bar.
if (!testVanillaNameForClass(varName)) return null;
doInitialClassTest = false;
name = varName;
} else {
name = varName + "." + name;
}
break;
}
// anything other than PropertyExpressions or
// VariableExpressions will stop resolving
else if (it.getClass() != PropertyExpression.class) {
return null;
} else {
PropertyExpression current = (PropertyExpression) it;
String propertyPart = current.getPropertyAsString();
// the class property stops resolving, dynamic property names too
if (propertyPart == null || propertyPart.equals("class")) {
return null;
}
if (doInitialClassTest) {
// we are at the first name part. This is the right most part.
// If this part is in lower case, then we do not need a class
// check. other parts of the property expression will be tested
// by a different method call to this method, so foo.Bar.bar
// can still be resolved to the class foo.Bar and the static
// field bar.
if (!testVanillaNameForClass(propertyPart)) return null;
doInitialClassTest= false;
name = propertyPart;
} else {
name = propertyPart + "." + name;
}
}
}
if (name.length() == 0) return null;
return name;
}
示例15: transformVariableExpression
import org.codehaus.groovy.ast.expr.VariableExpression; //导入方法依赖的package包/类
protected Expression transformVariableExpression(VariableExpression ve) {
visitAnnotations(ve);
Variable v = ve.getAccessedVariable();
if(!(v instanceof DynamicVariable) && !checkingVariableTypeInDeclaration) {
/*
* GROOVY-4009: when a normal variable is simply being used, there is no need to try to
* resolve its type. Variable type resolve should proceed only if the variable is being declared.
*/
return ve;
}
if (v instanceof DynamicVariable){
String name = ve.getName();
ClassNode t = ClassHelper.make(name);
// asking isResolved here allows to check if a primitive
// type name like "int" was used to make t. In such a case
// we have nothing left to do.
boolean isClass = t.isResolved();
if (!isClass) {
// It was no primitive type, so next we see if the name,
// which is a vanilla name, starts with a lower case letter.
// In that case we change it to a LowerCaseClass to let the
// compiler skip the resolving at several places in this class.
if (Character.isLowerCase(name.charAt(0))) {
t = new LowerCaseClass(name);
}
isClass = resolve(t);
if(!isClass) isClass = resolveToNestedOfCurrent(t);
}
if (isClass) {
// the name is a type so remove it from the scoping
// as it is only a classvariable, it is only in
// referencedClassVariables, but must be removed
// for each parentscope too
for (VariableScope scope = currentScope; scope != null && !scope.isRoot(); scope = scope.getParent()) {
if (scope.isRoot()) break;
if (scope.removeReferencedClassVariable(ve.getName()) == null) break;
}
ClassExpression ce = new ClassExpression(t);
ce.setSourcePosition(ve);
return ce;
}
}
resolveOrFail(ve.getType(), ve);
ClassNode origin = ve.getOriginType();
if (origin!=ve.getType()) resolveOrFail(origin, ve);
return ve;
}