当前位置: 首页>>代码示例>>Java>>正文


Java ClassExpression类代码示例

本文整理汇总了Java中org.codehaus.groovy.ast.expr.ClassExpression的典型用法代码示例。如果您正苦于以下问题:Java ClassExpression类的具体用法?Java ClassExpression怎么用?Java ClassExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClassExpression类属于org.codehaus.groovy.ast.expr包,在下文中一共展示了ClassExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: changeBaseScriptTypeFromPackageOrImport

import org.codehaus.groovy.ast.expr.ClassExpression; //导入依赖的package包/类
private void changeBaseScriptTypeFromPackageOrImport(final SourceUnit source, final AnnotatedNode parent, final AnnotationNode node) {
    Expression value = node.getMember("value");
    ClassNode scriptType;
    if (value == null) {
        scriptType = BASE_SCRIPT_TYPE;
    } else {
        if (!(value instanceof ClassExpression)) {
            addError("Annotation " + MY_TYPE_NAME + " member 'value' should be a class literal.", value);
            return;
        }
        scriptType = value.getType();
    }
    List<ClassNode> classes = source.getAST().getClasses();
    for (ClassNode classNode : classes) {
        if (classNode.isScriptBody()) {
            changeBaseScriptType(source, parent, classNode, scriptType, node);
        }
    }
}
 
开发者ID:remkop,项目名称:picocli,代码行数:20,代码来源:PicocliScriptASTTransformation.java

示例2: transformInlineConstants

import org.codehaus.groovy.ast.expr.ClassExpression; //导入依赖的package包/类
private Expression transformInlineConstants(Expression exp) {
    if (exp instanceof PropertyExpression) {
        PropertyExpression pe = (PropertyExpression) exp;
        if (pe.getObjectExpression() instanceof ClassExpression) {
            ClassExpression ce = (ClassExpression) pe.getObjectExpression();
            ClassNode type = ce.getType();
            if (type.isEnum()) return exp;
            Expression constant = findConstant(getField(type, pe.getPropertyAsString()));
            if (constant != null) return constant;
        }
    } else if (exp instanceof ListExpression) {
        ListExpression le = (ListExpression) exp;
        ListExpression result = new ListExpression();
        for (Expression e : le.getExpressions()) {
            result.addExpression(transformInlineConstants(e));
        }
        return result;
    }

    return exp;
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:StaticImportVisitor.java

示例3: transformDeclarationExpression

import org.codehaus.groovy.ast.expr.ClassExpression; //导入依赖的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

示例4: extractStaticReceiver

import org.codehaus.groovy.ast.expr.ClassExpression; //导入依赖的package包/类
/**
 * Given a method call, first checks that it's a static method call, and if it is, returns the
 * class node for the receiver. For example, with the following code:
 * <code></code>Person.findAll { ... }</code>, it would return the class node for <i>Person</i>.
 * If it's not a static method call, returns null.
 * @param call a method call
 * @return null if it's not a static method call, or the class node for the receiver instead.
 */
public ClassNode extractStaticReceiver(MethodCall call) {
    if (call instanceof StaticMethodCallExpression) {
        return ((StaticMethodCallExpression) call).getOwnerType();
    } else if (call instanceof MethodCallExpression) {
        Expression objectExpr = ((MethodCallExpression) call).getObjectExpression();
        if (objectExpr instanceof ClassExpression && ClassHelper.CLASS_Type.equals(objectExpr.getType())) {
            GenericsType[] genericsTypes = objectExpr.getType().getGenericsTypes();
            if (genericsTypes!=null && genericsTypes.length==1) {
                return genericsTypes[0].getType();
            }
        }
        if (objectExpr instanceof ClassExpression) {
            return objectExpr.getType();
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:groovy,代码行数:26,代码来源:TypeCheckingExtension.java

示例5: inferClosureParameterTypes

import org.codehaus.groovy.ast.expr.ClassExpression; //导入依赖的package包/类
/**
 * This method is responsible for performing type inference on closure argument types whenever code like this is
 * found: <code>foo.collect { it.toUpperCase() }</code>.
 * In this case, the type checker tries to find if the <code>collect</code> method has its {@link Closure} argument
 * annotated with {@link groovy.transform.stc.ClosureParams}. If yes, then additional type inference can be performed
 * and the type of <code>it</code> may be inferred.
 *
 * @param receiver
 * @param arguments
 * @param expression a closure expression for which the argument types should be inferred
 * @param param the parameter where to look for a {@link groovy.transform.stc.ClosureParams} annotation.
 * @param selectedMethod the method accepting a closure
 */
protected void inferClosureParameterTypes(final ClassNode receiver, final Expression arguments, final ClosureExpression expression, final Parameter param, final MethodNode selectedMethod) {
    List<AnnotationNode> annotations = param.getAnnotations(CLOSUREPARAMS_CLASSNODE);
    if (annotations!=null && !annotations.isEmpty()) {
        for (AnnotationNode annotation : annotations) {
            Expression hintClass = annotation.getMember("value");
            Expression options = annotation.getMember("options");
            Expression resolverClass = annotation.getMember("conflictResolutionStrategy");
            if (hintClass instanceof ClassExpression) {
                doInferClosureParameterTypes(receiver, arguments, expression, selectedMethod, hintClass, resolverClass, options);
            }
        }
    } else if (isSAMType(param.getOriginType())) {
        // SAM coercion
        inferSAMType(param, receiver, selectedMethod, InvocationWriter.makeArgumentList(arguments), expression);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:30,代码来源:StaticTypeCheckingVisitor.java

示例6: extractTarget

import org.codehaus.groovy.ast.expr.ClassExpression; //导入依赖的package包/类
private static groovy.transform.PackageScopeTarget extractTarget(PropertyExpression expr) {
    Expression oe = expr.getObjectExpression();
    if (oe instanceof ClassExpression) {
        ClassExpression ce = (ClassExpression) oe;
        if (ce.getType().getName().equals("groovy.transform.PackageScopeTarget")) {
            Expression prop = expr.getProperty();
            if (prop instanceof ConstantExpression) {
                String propName = (String) ((ConstantExpression) prop).getValue();
                try {
                    return PackageScopeTarget.valueOf(propName);
                } catch(IllegalArgumentException iae) {
                    /* ignore */
                }
            }
        }
    }
    throw new GroovyBugError("Internal error during " + MY_TYPE_NAME
            + " processing. Annotation parameters must be of type: " + TARGET_CLASS_NAME + ".");
}
 
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:PackageScopeASTTransformation.java

示例7: getKnownImmutableClasses

import org.codehaus.groovy.ast.expr.ClassExpression; //导入依赖的package包/类
private List<String> getKnownImmutableClasses(AnnotationNode node) {
    final List<String> immutableClasses = new ArrayList<String>();

    final Expression expression = node.getMember(MEMBER_KNOWN_IMMUTABLE_CLASSES);
    if (expression == null) return immutableClasses;

    if (!(expression instanceof ListExpression)) {
        addError("Use the Groovy list notation [el1, el2] to specify known immutable classes via \"" + MEMBER_KNOWN_IMMUTABLE_CLASSES + "\"", node);
        return immutableClasses;
    }

    final ListExpression listExpression = (ListExpression) expression;
    for (Expression listItemExpression : listExpression.getExpressions()) {
        if (listItemExpression instanceof ClassExpression) {
            immutableClasses.add(listItemExpression.getType().getName());
        }
    }

    return immutableClasses;
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:ImmutableASTTransformation.java

示例8: validateEnumConstant

import org.codehaus.groovy.ast.expr.ClassExpression; //导入依赖的package包/类
private boolean validateEnumConstant(Expression exp) {
    if (exp instanceof PropertyExpression) {
        PropertyExpression pe = (PropertyExpression) exp;
        String name = pe.getPropertyAsString();
        if (pe.getObjectExpression() instanceof ClassExpression && name != null) {
            ClassExpression ce = (ClassExpression) pe.getObjectExpression();
            ClassNode type = ce.getType();
            if (type.isEnum()) {
                boolean ok = false;
                try {
                    FieldNode enumField = type.getDeclaredField(name);
                    ok = enumField != null && enumField.getType().equals(type);
                } catch(Exception ex) {
                    // ignore
                }
                if(!ok) {
                    addError("No enum const " + type.getName() + "." + name, pe);
                    return false;
                }
            }
        }
    }
    return true;
}
 
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:AnnotationVisitor.java

示例9: createInterfaceSyntheticStaticFields

import org.codehaus.groovy.ast.expr.ClassExpression; //导入依赖的package包/类
protected void createInterfaceSyntheticStaticFields() {
    ClassNode icl =  controller.getInterfaceClassLoadingClass();

    if (referencedClasses.isEmpty()) {
        Iterator<InnerClassNode> it = controller.getClassNode().getInnerClasses();
        while(it.hasNext()) {
            InnerClassNode inner = it.next();
            if (inner==icl) {
                it.remove();
                return;
            }
        }
        return;
    }

    addInnerClass(icl);
    for (Map.Entry<String, ClassNode> entry : referencedClasses.entrySet()) {            // generate a field node
        String staticFieldName = entry.getKey();
        ClassNode cn = entry.getValue();
        icl.addField(staticFieldName, ACC_STATIC + ACC_SYNTHETIC, ClassHelper.CLASS_Type.getPlainNodeReference(), new ClassExpression(cn));
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:AsmClassGenerator.java

示例10: resolveType

import org.codehaus.groovy.ast.expr.ClassExpression; //导入依赖的package包/类
public ClassNode resolveType(final Expression exp, final ClassNode current) {
    if (exp instanceof ClassExpression) return ClassHelper.CLASS_Type;
    OptimizingStatementWriter.StatementMeta meta = exp.getNodeMetaData(OptimizingStatementWriter.StatementMeta.class);
    ClassNode type = null;
    if (meta != null) type = meta.type;
    if (type != null) return type;
    if (exp instanceof VariableExpression) {
        VariableExpression ve = (VariableExpression) exp;
        if (ve.isClosureSharedVariable()) return ve.getType();
        type = ve.getOriginType();
        if (ve.getAccessedVariable() instanceof FieldNode) {
            FieldNode fn = (FieldNode) ve.getAccessedVariable();
            if (!fn.getDeclaringClass().equals(current)) return fn.getOriginType();
        }
    } else if (exp instanceof Variable) {
        Variable v = (Variable) exp;
        type = v.getOriginType();
    } else {
        type = exp.getType();
    }
    return type.redirect();
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:StatementMetaTypeChooser.java

示例11: makeInvokeMethodCall

import org.codehaus.groovy.ast.expr.ClassExpression; //导入依赖的package包/类
private void makeInvokeMethodCall(MethodCallExpression call, boolean useSuper, MethodCallerMultiAdapter adapter) {
    // receiver
    // we operate on GroovyObject if possible
    Expression objectExpression = call.getObjectExpression();
    // message name
    Expression messageName = new CastExpression(ClassHelper.STRING_TYPE, call.getMethod());
    if (useSuper) {
        ClassNode classNode = controller.isInClosure() ? controller.getOutermostClass() : controller.getClassNode(); // GROOVY-4035 
        ClassNode superClass = classNode.getSuperClass();
        makeCall(call, new ClassExpression(superClass),
                objectExpression, messageName,
                call.getArguments(), adapter,
                call.isSafe(), call.isSpreadSafe(),
                false
        );
    } else {
        makeCall(call, objectExpression, messageName,
                call.getArguments(), adapter,
                call.isSafe(), call.isSpreadSafe(),
                call.isImplicitThis()
        );
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:InvocationWriter.java

示例12: makeCachedCall

import org.codehaus.groovy.ast.expr.ClassExpression; //导入依赖的package包/类
protected boolean makeCachedCall(
        Expression origin, ClassExpression sender,
        Expression receiver, Expression message, Expression arguments,
        MethodCallerMultiAdapter adapter,
        boolean safe, boolean spreadSafe, boolean implicitThis,
        boolean containsSpreadExpression
) {
    // prepare call site
    if ((adapter == invokeMethod || adapter == invokeMethodOnCurrent || adapter == invokeStaticMethod) && !spreadSafe) {
        String methodName = getMethodName(message);

        if (methodName != null) {
            controller.getCallSiteWriter().makeCallSite(
                    receiver, methodName, arguments, safe, implicitThis, 
                    adapter == invokeMethodOnCurrent, 
                    adapter == invokeStaticMethod);
            return true;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:InvocationWriter.java

示例13: makeCall

import org.codehaus.groovy.ast.expr.ClassExpression; //导入依赖的package包/类
protected void makeCall(
        Expression origin, ClassExpression sender,
        Expression receiver, Expression message, Expression arguments,
        MethodCallerMultiAdapter adapter,
        boolean safe, boolean spreadSafe, boolean implicitThis
) {
    // direct method call paths
    boolean containsSpreadExpression = AsmClassGenerator.containsSpreadExpression(arguments);

    if (makeDirectCall(origin, receiver, message, arguments, adapter, implicitThis, containsSpreadExpression)) return;

    // normal path
    if (makeCachedCall(origin, sender, receiver, message, arguments, adapter, safe, spreadSafe, implicitThis, containsSpreadExpression)) return;

    // path through ScriptBytecodeAdapter
    makeUncachedCall(origin, sender, receiver, message, arguments, adapter, safe, spreadSafe, implicitThis, containsSpreadExpression);
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:InvocationWriter.java

示例14: writeNormalConstructorCall

import org.codehaus.groovy.ast.expr.ClassExpression; //导入依赖的package包/类
protected void writeNormalConstructorCall(ConstructorCallExpression call) {
    Expression arguments = call.getArguments();
    if (arguments instanceof TupleExpression) {
        TupleExpression tupleExpression = (TupleExpression) arguments;
        int size = tupleExpression.getExpressions().size();
        if (size == 0) {
            arguments = MethodCallExpression.NO_ARGUMENTS;
        }
    }

    Expression receiverClass = new ClassExpression(call.getType());
    controller.getCallSiteWriter().makeCallSite(
            receiverClass, CallSiteWriter.CONSTRUCTOR,
            arguments, false, false, false,
            false);
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:InvocationWriter.java

示例15: castToNonPrimitiveIfNecessary

import org.codehaus.groovy.ast.expr.ClassExpression; //导入依赖的package包/类
/**
 * This converts sourceType to a non primitive by using Groovy casting.
 * sourceType might be a primitive
 * This might be done using SBA#castToType
 */
public void castToNonPrimitiveIfNecessary(final ClassNode sourceType, final ClassNode targetType) {
    OperandStack os = controller.getOperandStack();
    ClassNode boxedType = os.box();
    if (WideningCategories.implementsInterfaceOrSubclassOf(boxedType, targetType)) return;
    MethodVisitor mv = controller.getMethodVisitor();
    if (ClassHelper.CLASS_Type.equals(targetType)) {
        castToClassMethod.call(mv);
    } else if (ClassHelper.STRING_TYPE.equals(targetType)) {
        castToStringMethod.call(mv);
    } else if (targetType.isDerivedFrom(ClassHelper.Enum_Type)) {
        (new ClassExpression(targetType)).visit(controller.getAcg());
        os.remove(1);
        castToEnumMethod.call(mv);
        BytecodeHelper.doCast(mv, targetType);
    } else {
        (new ClassExpression(targetType)).visit(controller.getAcg());
        os.remove(1);
        castToTypeMethod.call(mv);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:26,代码来源:InvocationWriter.java


注:本文中的org.codehaus.groovy.ast.expr.ClassExpression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。