/** * Creates a ClassNode using a given class. * A new ClassNode object is only created if the class * is not one of the predefined ones * * @param c class used to created the ClassNode * @return ClassNode instance created from the given class */ public static ClassNode make(Class c) { return make(c, true); }
private static ClassNode configureClass(Class c) { if (c.isPrimitive()) { return ClassHelper.make(c); } else { return ClassHelper.makeWithoutCaching(c, false); } }
public static FieldNode newStatic(Class theClass, String name) throws SecurityException, NoSuchFieldException { Field field = theClass.getField(name); ClassNode fldType = ClassHelper.make(field.getType()); return new FieldNode(name, ACC_PUBLIC | ACC_STATIC, fldType, ClassHelper.make(theClass), null); }
public static ClassNode make(Class c, boolean includeGenerics) { for (int i = 0; i < classes.length; i++) { if (c == classes[i]) return types[i]; } if (c.isArray()) { ClassNode cn = make(c.getComponentType(), includeGenerics); return cn.makeArray(); } return makeWithoutCaching(c, includeGenerics); }
private static GenericsType[] unsetGenTypes(int numFields) { GenericsType[] gtypes = new GenericsType[numFields]; for (int i = 0; i < gtypes.length; i++) { gtypes[i] = new GenericsType(ClassHelper.make(UNSET.class)); } return gtypes; }
public ImportCustomizer addStaticImport(final String alias, final String className, final String fieldName) { imports.add(new Import(ImportCustomizer.ImportType.staticImport, alias, ClassHelper.make(className), fieldName)); return this; }
private static GenericsType[] setGenTypes(int numFields) { GenericsType[] gtypes = new GenericsType[numFields]; for (int i = 0; i < gtypes.length; i++) { gtypes[i] = new GenericsType(ClassHelper.make(SET.class)); } return gtypes; }
public ImportCustomizer addStaticImport(final String className, final String fieldName) { final ClassNode node = ClassHelper.make(className); imports.add(new Import(ImportType.staticImport, fieldName, node, fieldName)); return this; }
private void addImport(final String className) { final ClassNode node = ClassHelper.make(className); imports.add(new Import(ImportType.regular, node.getNameWithoutPackage(), node)); }
public static ClassNode makeClassSafeWithGenerics(Class klass, ClassNode genericsType) { GenericsType[] genericsTypes = new GenericsType[1]; genericsTypes[0] = new GenericsType(genericsType); return makeClassSafeWithGenerics(ClassHelper.make(klass), genericsTypes); }
public static ListExpression classList2args(List<String> args) { ListExpression result = new ListExpression(); for (Object o : args) { result.addExpression(new ClassExpression(ClassHelper.make(o.toString()))); } return result; }
private ClassNode resolveNonArrayType(Type type) { String className = type.getClassName(); if (type.getSort() != Type.OBJECT) { return ClassHelper.make(className); } return resolveClass(className); }
protected void setupTransform(AnnotationNode node) { checkOnMethodStart = getBooleanAnnotationParameter(node, CHECK_METHOD_START_MEMBER, true); applyToAllMembers = getBooleanAnnotationParameter(node, APPLY_TO_ALL_MEMBERS, true); applyToAllClasses = applyToAllMembers && getBooleanAnnotationParameter(node, APPLY_TO_ALL_CLASSES, true); thrownExceptionType = getClassAnnotationParameter(node, THROWN_EXCEPTION_TYPE, ClassHelper.make(InterruptedException.class)); }
public void visitCatchStatement(CatchStatement cs) { if (!(cs.getExceptionType().isDerivedFrom(ClassHelper.make(Throwable.class)))) { addError("Catch statement parameter type is not a subclass of Throwable.", cs); } super.visitCatchStatement(cs); }
@Override public boolean handleUnresolvedVariableExpression(final VariableExpression vexp) { // <2> if ("robot".equals(vexp.getName())) { storeType(vexp, ClassHelper.make(Robot.class)); setHandled(true); return true; } return false; }
public void visitCatchStatement(CatchStatement cs) { resolveOrFail(cs.getExceptionType(), cs); if (cs.getExceptionType() == ClassHelper.DYNAMIC_TYPE) { cs.getVariable().setType(ClassHelper.make(Exception.class)); } super.visitCatchStatement(cs); }
@Override public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) throws CompilationFailedException { if (classNode.isScriptBody()) { classNode.setSuperClass(ClassHelper.make(config.getBaseTemplateClass())); createConstructor(classNode); transformRunMethod(classNode, source); VariableScopeVisitor visitor = new VariableScopeVisitor(source); visitor.visitClass(classNode); } }
private static boolean matchWithOrWithourBoxing(final ClassNode argType, final Class aClass) { final boolean match; ClassNode type = ClassHelper.make(aClass); if (ClassHelper.isPrimitiveType(type) && !ClassHelper.isPrimitiveType(argType)) { type = ClassHelper.getWrapper(type); } else if (ClassHelper.isPrimitiveType(argType) && !ClassHelper.isPrimitiveType(type)) { type = ClassHelper.getUnwrapper(type); } match = argType.equals(type); return match; }
@Override public void visitRangeExpression(final RangeExpression expression) { super.visitRangeExpression(expression); ClassNode fromType = getWrapper(getType(expression.getFrom())); ClassNode toType = getWrapper(getType(expression.getTo())); if (Integer_TYPE.equals(fromType) && Integer_TYPE.equals(toType)) { storeType(expression, ClassHelper.make(IntRange.class)); } else { ClassNode rangeType = ClassHelper.make(Range.class).getPlainNodeReference(); rangeType.setGenericsTypes(new GenericsType[]{new GenericsType(WideningCategories.lowestUpperBound(fromType, toType))}); storeType(expression, rangeType); } }
private static void createWriteExternal(ClassNode cNode, List<String> excludes, List<FieldNode> list) { final BlockStatement body = new BlockStatement(); Parameter out = param(OBJECTOUTPUT_TYPE, "out"); for (FieldNode fNode : list) { if (excludes != null && excludes.contains(fNode.getName())) continue; if ((fNode.getModifiers() & ACC_TRANSIENT) != 0) continue; MethodCallExpression writeObject = callX(varX(out), "write" + suffixForField(fNode), varX(fNode)); writeObject.setImplicitThis(false); body.addStatement(stmt(writeObject)); } ClassNode[] exceptions = {make(IOException.class)}; addGeneratedMethod(cNode, "writeExternal", ACC_PUBLIC, ClassHelper.VOID_TYPE, params(out), exceptions, body); }