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


Java ClassHelper类代码示例

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


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

示例1: handleUnresolvedVariableExpression

import org.codehaus.groovy.ast.ClassHelper; //导入依赖的package包/类
@Override
public boolean handleUnresolvedVariableExpression(final VariableExpression vexp) {

    if ("resource".equals(vexp.getName())) {
        makeDynamic(vexp, ClassHelper.makeCached(ResourceHandler.class));
        setHandled(true);
        return true;
    }
    if ("subject".equals(vexp.getName())) {
        makeDynamic(vexp, ClassHelper.makeCached(SubjectHandler.class));
        setHandled(true);
        return true;
    }
    if ("match".equals(vexp.getName())) {
        makeDynamic(vexp, ClassHelper.makeCached(AttributeMatcher.class));
        setHandled(true);
        return true;
    }

    return false;
}
 
开发者ID:eclipse,项目名称:keti,代码行数:22,代码来源:GroovySecureExtension.java

示例2: visitBlockStatement

import org.codehaus.groovy.ast.ClassHelper; //导入依赖的package包/类
@Override
public void visitBlockStatement(BlockStatement block) {
	if (block.isEmpty() || this.xformed) {
		return;
	}
	ClosureExpression closure = beans(block);
	if (closure != null) {
		// Add a marker interface to the current script
		this.classNode.addInterface(ClassHelper.make(SOURCE_INTERFACE));
		// Implement the interface by adding a public read-only property with the
		// same name as the method in the interface (getBeans). Make it return the
		// closure.
		this.classNode.addProperty(
				new PropertyNode(BEANS, Modifier.PUBLIC | Modifier.FINAL,
						ClassHelper.CLOSURE_TYPE.getPlainNodeReference(),
						this.classNode, closure, null, null));
		// Only do this once per class
		this.xformed = true;
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:GroovyBeansTransformation.java

示例3: eval

import org.codehaus.groovy.ast.ClassHelper; //导入依赖的package包/类
@Override
public Object eval(String script, ScriptContext ctx) throws ScriptException {
    COMPILE_OPTIONS.remove();
    Map<String, ClassNode> variableTypes = new HashMap<>();
    for (Map.Entry<String, Object> entry : ctx.getBindings(ScriptContext.ENGINE_SCOPE).entrySet()) {
        variableTypes.put(entry.getKey(),
                ClassHelper.make(entry.getValue().getClass()));
    }

    variableTypes.put("execution", ClassHelper.make(clazz));
    Map<String, Object> options = new HashMap<>();
    options.put(VAR_TYPES, variableTypes);
    COMPILE_OPTIONS.set(options);
    Object ret = super.eval(script, ctx);
    return ret;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:17,代码来源:GroovyStaticScriptEngine.java

示例4: getClassLoadingTypeDescription

import org.codehaus.groovy.ast.ClassHelper; //导入依赖的package包/类
/**
 * array types are special:
 * eg.: String[]: classname: [Ljava.lang.String;
 * Object:   classname: java.lang.Object
 * int[] :   classname: [I
 * unlike getTypeDescription '.' is not replaced by '/'.
 * it seems that makes problems for
 * the class loading if '.' is replaced by '/'
 *
 * @return the ASM type description for class loading
 */
public static String getClassLoadingTypeDescription(ClassNode c) {
    StringBuilder buf = new StringBuilder();
    boolean array = false;
    while (true) {
        if (c.isArray()) {
            buf.append('[');
            c = c.getComponentType();
            array = true;
        } else {
            if (ClassHelper.isPrimitiveType(c)) {
                buf.append(getTypeDescription(c));
            } else {
                if (array) buf.append('L');
                buf.append(c.getName());
                if (array) buf.append(';');
            }
            return buf.toString();
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:32,代码来源:BytecodeHelper.java

示例5: visit

import org.codehaus.groovy.ast.ClassHelper; //导入依赖的package包/类
@Override
public void visit(final GroovyCodeVisitor visitor) {
    receiver.visit(visitor);
    if (visitor instanceof AsmClassGenerator) {
        ClassNode topOperand = controller.getOperandStack().getTopOperand();
        ClassNode type = getType();
        if (ClassHelper.GSTRING_TYPE.equals(topOperand) && ClassHelper.STRING_TYPE.equals(type)) {
            // perform regular type conversion
            controller.getOperandStack().doGroovyCast(type);
            return;
        }
        if (ClassHelper.isPrimitiveType(topOperand) && !ClassHelper.isPrimitiveType(type)) {
            controller.getOperandStack().box();
        } else if (!ClassHelper.isPrimitiveType(topOperand) && ClassHelper.isPrimitiveType(type)) {
            controller.getOperandStack().doGroovyCast(type);
        }
        if (StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf(topOperand, type)) return;
        controller.getMethodVisitor().visitTypeInsn(CHECKCAST, type.isArray() ?
                BytecodeHelper.getTypeDescription(type) :
                BytecodeHelper.getClassInternalName(type.getName()));
        controller.getOperandStack().replace(type);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:StaticInvocationWriter.java

示例6: optimizeConstantInitialization

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

示例7: execute

import org.codehaus.groovy.ast.ClassHelper; //导入依赖的package包/类
public void execute() {
    for (FieldNode fNode : transformation.annotatedClass.getFields()) {
        AnnotationNode defaultAnnotation = getAnnotation(fNode, DEFAULT_ANNOTATION);

        if (defaultAnnotation != null) {
            Statement getterCode = createDefaultValueFor(fNode, defaultAnnotation);
            MethodNode getter = transformation.annotatedClass.getGetterMethod("get" + Verifier.capitalize(fNode.getName()));

            getter.setCode(getterCode);

            if (ClassHelper.boolean_TYPE == fNode.getType() || ClassHelper.Boolean_TYPE == fNode.getType()) {
                MethodNode secondGetter = transformation.annotatedClass.getGetterMethod("is" + Verifier.capitalize(fNode.getName()));
                secondGetter.setCode(getterCode);
            }
        }
    }
}
 
开发者ID:klum-dsl,项目名称:klum-ast,代码行数:18,代码来源:DefaultMethods.java

示例8: makeType

import org.codehaus.groovy.ast.ClassHelper; //导入依赖的package包/类
protected ClassNode makeType(AST typeNode) {
    ClassNode answer = ClassHelper.DYNAMIC_TYPE;
    AST node = typeNode.getFirstChild();
    if (node != null) {
        if (isType(INDEX_OP, node) || isType(ARRAY_DECLARATOR, node)) {
            answer = makeType(node).makeArray();
        } else {
            checkTypeArgs(node, false);
            answer = ClassHelper.make(qualifiedName(node));
            if (answer.isUsingGenerics()) {
                ClassNode newAnswer = ClassHelper.makeWithoutCaching(answer.getName());
                newAnswer.setRedirect(answer);
                answer = newAnswer;
            }
        }
        configureAST(answer, node);
    }
    return answer;
}
 
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:AntlrParserPlugin.java

示例9: despreadList

import org.codehaus.groovy.ast.ClassHelper; //导入依赖的package包/类
public void despreadList(List expressions, boolean wrap) {
    ArrayList spreadIndexes = new ArrayList();
    ArrayList spreadExpressions = new ArrayList();
    ArrayList normalArguments = new ArrayList();
    for (int i = 0; i < expressions.size(); i++) {
        Object expr = expressions.get(i);
        if (!(expr instanceof SpreadExpression)) {
            normalArguments.add(expr);
        } else {
            spreadIndexes.add(new ConstantExpression(Integer.valueOf(i - spreadExpressions.size()),true));
            spreadExpressions.add(((SpreadExpression) expr).getExpression());
        }
    }

    //load normal arguments as array
    visitTupleExpression(new ArgumentListExpression(normalArguments), wrap);
    //load spread expressions as array
    (new TupleExpression(spreadExpressions)).visit(this);
    //load insertion index
    (new ArrayExpression(ClassHelper.int_TYPE, spreadIndexes, null)).visit(this);
    controller.getOperandStack().remove(1);
    despreadList.call(controller.getMethodVisitor());
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:AsmClassGenerator.java

示例10: convertFromFloat

import org.codehaus.groovy.ast.ClassHelper; //导入依赖的package包/类
private boolean convertFromFloat(ClassNode target) {
    MethodVisitor mv = controller.getMethodVisitor();
    if (target==ClassHelper.int_TYPE){
        mv.visitInsn(F2I);
        return true;
    } else if ( target==ClassHelper.char_TYPE ||
                target==ClassHelper.byte_TYPE ||
                target==ClassHelper.short_TYPE)
    {
        mv.visitInsn(F2I);
        return convertFromInt(target);
    } else if (target==ClassHelper.long_TYPE){
        mv.visitInsn(F2L);
        return true;
    } else if (target==ClassHelper.double_TYPE){
        mv.visitInsn(F2D);
        return true;
    } 
    return false;
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:OperandStack.java

示例11: makeEnumNode

import org.codehaus.groovy.ast.ClassHelper; //导入依赖的package包/类
public static ClassNode makeEnumNode(String name, int modifiers, ClassNode[] interfaces, ClassNode outerClass) {
    modifiers = modifiers | Opcodes.ACC_FINAL | Opcodes.ACC_ENUM;
    ClassNode enumClass;
    if (outerClass==null) {
        enumClass = new ClassNode(name,modifiers,null,interfaces,MixinNode.EMPTY_ARRAY);
    } else {
        name = outerClass.getName() + "$" + name;
        modifiers |= Opcodes.ACC_STATIC;
        enumClass = new InnerClassNode(outerClass,name,modifiers,null,interfaces,MixinNode.EMPTY_ARRAY);
    }
    
    // set super class and generics info
    // "enum X" -> class X extends Enum<X>
    GenericsType gt = new GenericsType(enumClass);
    ClassNode superClass = ClassHelper.makeWithoutCaching("java.lang.Enum");
    superClass.setGenericsTypes(new GenericsType[]{gt});
    enumClass.setSuperClass(superClass);
    superClass.setRedirect(ClassHelper.Enum_Type);
    
    return enumClass;
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:EnumHelper.java

示例12: isKnownImmutableClass

import org.codehaus.groovy.ast.ClassHelper; //导入依赖的package包/类
private static boolean isKnownImmutableClass(ClassNode fieldType, List<String> knownImmutableClasses) {
    if (inImmutableList(fieldType.getName()) || knownImmutableClasses.contains(fieldType.getName()))
        return true;
    if (!fieldType.isResolved())
        return false;
    if ("java.util.Optional".equals(fieldType.getName()) && fieldType.getGenericsTypes() != null && fieldType.getGenericsTypes().length == 1) {
        GenericsType optionalType = fieldType.getGenericsTypes()[0];
        if (optionalType.isResolved() && !optionalType.isPlaceholder() && !optionalType.isWildcard()) {
            String name = optionalType.getType().getName();
            if (inImmutableList(name) || knownImmutableClasses.contains(name)) return true;
            if (optionalType.getType().isEnum() || !optionalType.getType().getAnnotations(MY_TYPE).isEmpty()) return true;
        }
    }
    return fieldType.isEnum() ||
            ClassHelper.isPrimitiveType(fieldType) ||
            !fieldType.getAnnotations(MY_TYPE).isEmpty();
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:ImmutableASTTransformation.java

示例13: loadStaticField

import org.codehaus.groovy.ast.ClassHelper; //导入依赖的package包/类
/**
 * @param fldExp
 */
public void loadStaticField(FieldExpression fldExp) {
    MethodVisitor mv = controller.getMethodVisitor();
    FieldNode field = fldExp.getField();
    boolean holder = field.isHolder() && !controller.isInClosureConstructor();
    ClassNode type = field.getType();

    String ownerName = (field.getOwner().equals(controller.getClassNode()))
            ? controller.getInternalClassName()
            : BytecodeHelper.getClassInternalName(field.getOwner());
    if (holder) {
        mv.visitFieldInsn(GETSTATIC, ownerName, fldExp.getFieldName(), BytecodeHelper.getTypeDescription(type));
        mv.visitMethodInsn(INVOKEVIRTUAL, "groovy/lang/Reference", "get", "()Ljava/lang/Object;", false);
        controller.getOperandStack().push(ClassHelper.OBJECT_TYPE);
    } else {
        mv.visitFieldInsn(GETSTATIC, ownerName, fldExp.getFieldName(), BytecodeHelper.getTypeDescription(type));
        controller.getOperandStack().push(field.getType());
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:AsmClassGenerator.java

示例14: convertFromInt

import org.codehaus.groovy.ast.ClassHelper; //导入依赖的package包/类
private boolean convertFromInt(ClassNode target) {
    int convertCode;
    if (target==ClassHelper.char_TYPE){
        convertCode = I2C;
    } else if (target==ClassHelper.byte_TYPE){
        convertCode = I2B;
    } else if (target==ClassHelper.short_TYPE){
        convertCode = I2S;
    } else if (target==ClassHelper.long_TYPE){
        convertCode = I2L;
    } else if (target==ClassHelper.float_TYPE){
        convertCode = I2F;
    } else if (target==ClassHelper.double_TYPE){
        convertCode = I2D;
    } else {
        return false;
    }
    controller.getMethodVisitor().visitInsn(convertCode);
    return true;
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:OperandStack.java

示例15: createInitMethod

import org.codehaus.groovy.ast.ClassHelper; //导入依赖的package包/类
private static MethodNode createInitMethod(final boolean isStatic, final ClassNode cNode, final ClassNode helper) {
    MethodNode initializer = new MethodNode(
            isStatic?Traits.STATIC_INIT_METHOD:Traits.INIT_METHOD,
            ACC_STATIC | ACC_PUBLIC | ACC_SYNTHETIC,
            ClassHelper.VOID_TYPE,
            new Parameter[]{createSelfParameter(cNode, isStatic)},
            ClassNode.EMPTY_ARRAY,
            new BlockStatement()
    );
    helper.addMethod(initializer);

    // Cannot add static compilation of init method because of GROOVY-7217, see example 2 of test case
    //AnnotationNode an = new AnnotationNode(TraitComposer.COMPILESTATIC_CLASSNODE);
    //initializer.addAnnotation(an);
    //cNode.addTransform(StaticCompileTransformation.class, an);

    return initializer;
}
 
开发者ID:apache,项目名称:groovy,代码行数:19,代码来源:TraitASTTransformation.java


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