@Override public Class getTypeClass() { return super.getTypeClass(); }
@Override public Class getTypeClass() { return compileTimeClassNode.getTypeClass(); }
private static Annotation getTransformClassAnnotation(ClassNode annotatedType) { if (!annotatedType.isResolved()) return null; for (Annotation ann : annotatedType.getTypeClass().getAnnotations()) { // because compiler clients are free to choose any GroovyClassLoader for // resolving ClassNodeS such as annotatedType, we have to compare by name, // and cannot cast the return value to GroovyASTTransformationClass if (ann.annotationType().getName().equals(GroovyASTTransformationClass.class.getName())) { return ann; } } return null; }
private void setGenericsTypes(ClassNode cn) { TypeVariable[] tvs = cn.getTypeClass().getTypeParameters(); GenericsType[] gts = configureTypeVariable(tvs); cn.setGenericsTypes(gts); }
/** * box top level operand */ @Deprecated public static boolean box(MethodVisitor mv, ClassNode type) { if (type.isPrimaryClassNode()) return false; return box(mv, type.getTypeClass()); }
protected static List<PropertyInfo> getPropertyInfoFromBeanInfo(ClassNode cNode, List<String> includes, List<String> excludes, boolean allNames) { final List<PropertyInfo> result = new ArrayList<PropertyInfo>(); try { BeanInfo beanInfo = Introspector.getBeanInfo(cNode.getTypeClass()); for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) { if (shouldSkipUndefinedAware(descriptor.getName(), excludes, includes, allNames)) continue; // skip hidden and read-only props if (descriptor.isHidden() || descriptor.getWriteMethod() == null) continue; result.add(new PropertyInfo(descriptor.getName(), ClassHelper.make(descriptor.getPropertyType()))); } } catch (IntrospectionException ignore) { } return result; }
/** * get the time stamp of a class * NOTE: copied from GroovyClassLoader */ private static long getTimeStamp(ClassNode cls) { if (!(cls instanceof DecompiledClassNode)) { return Verifier.getTimestamp(cls.getTypeClass()); } return ((DecompiledClassNode) cls).getCompilationTimeStamp(); }
/** * Returns the concrete class this classnode relates to. However, this method * is inherently unsafe as it may return null depending on the compile phase you are * using. AST transformations should never use this method directly, but rather obtain * a new class node using {@link #getPlainNodeReference()}. * @return the class this classnode relates to. May return null. */ public Class getTypeClass(){ if (clazz != null) return clazz; if (redirect != null) return redirect.getTypeClass(); ClassNode component = redirect().componentType; if (component!=null && component.isResolved()){ return Array.newInstance(component.getTypeClass(), 0).getClass(); } throw new GroovyBugError("ClassNode#getTypeClass for "+getName()+" is called before the type class is set "); }
private static List<AnnotationNode> getTargetListFromClass(ClassNode alias) { alias = getSerializeClass(alias); Class<?> c = alias.getTypeClass(); Object[][] data; try { Method m = c.getMethod("value"); data = (Object[][]) m.invoke(null); } catch (Exception e) { throw new GroovyBugError(e); } return makeListOfAnnotations(data); }
private static boolean hasClosureMember(AnnotationNode annotation) { Map<String, Expression> members = annotation.getMembers(); for (Map.Entry<String, Expression> member : members.entrySet()) { if (member.getValue() instanceof ClosureExpression) return true; if (member.getValue() instanceof ClassExpression) { ClassExpression classExpression = (ClassExpression) member.getValue(); Class<?> typeClass = classExpression.getType().isResolved() ? classExpression.getType().redirect().getTypeClass() : null; if (typeClass != null && GeneratedClosure.class.isAssignableFrom(typeClass)) return true; } } return false; }
public static void unbox(MethodVisitor mv, ClassNode type) { if (type.isPrimaryClassNode()) return; unbox(mv, type.getTypeClass()); }
private static Expression providedOrDefaultInitialValue(FieldNode fNode) { Expression initialExp = fNode.getInitialExpression() != null ? fNode.getInitialExpression() : ConstantExpression.NULL; final ClassNode paramType = fNode.getType(); if (ClassHelper.isPrimitiveType(paramType) && initialExp.equals(ConstantExpression.NULL)) { initialExp = primitivesInitialValues.get(paramType.getTypeClass()); } return initialExp; }
public void configureClassNode(CompileUnit compileUnit, ClassNode classNode) { try { Class clazz = classNode.getTypeClass(); Field[] fields = clazz.getDeclaredFields(); for (Field f : fields) { if (sc != null) classNode.setUnresolvedSuperClass(makeClassNode(compileUnit, clazz.getGenericSuperclass(), sc)); makeInterfaceTypes(compileUnit, classNode, clazz); setAnnotationMetaData(classNode.getTypeClass().getAnnotations(), classNode); setAnnotationMetaData(classNode.getTypeClass().getPackage().getAnnotations(), packageNode);
final ClassLoader classLoader = trait.getTypeClass().getClassLoader(); String helperClassName = Traits.helperClassName(trait); helperClassNode = ClassHelper.make(Class.forName(helperClassName, false, classLoader));
public void visitAnnotations(AnnotatedNode node) { List<AnnotationNode> annotations = node.getAnnotations(); if (annotations.isEmpty()) return; Map<String, AnnotationNode> tmpAnnotations = new HashMap<String, AnnotationNode>(); ClassNode annType; for (AnnotationNode an : annotations) { // skip built-in properties if (an.isBuiltIn()) continue; annType = an.getClassNode(); resolveOrFail(annType, ", unable to find class for annotation", an); for (Map.Entry<String, Expression> member : an.getMembers().entrySet()) { Expression newValue = transform(member.getValue()); Expression adjusted = transformInlineConstants(newValue); member.setValue(adjusted); checkAnnotationMemberValue(adjusted); } if (annType.isResolved()) { Class annTypeClass = annType.getTypeClass(); Retention retAnn = (Retention) annTypeClass.getAnnotation(Retention.class); if (retAnn != null && retAnn.value().equals(RetentionPolicy.RUNTIME) && !isRepeatable(annTypeClass)) { // remember runtime/non-repeatable annos (auto collecting of Repeatable annotations is handled elsewhere) AnnotationNode anyPrevAnnNode = tmpAnnotations.put(annTypeClass.getName(), an); if (anyPrevAnnNode != null) { addError("Cannot specify duplicate annotation on the same member : " + annType.getName(), an); } } } } }
public static String getClassInternalName(ClassNode t) { if (t.isPrimaryClassNode() || t instanceof DecompiledClassNode) { if (t.isArray()) return "[L"+getClassInternalName(t.getComponentType())+";"; return getClassInternalName(t.getName()); } return getClassInternalName(t.getTypeClass()); }
if (cn == null && declaringClass.isResolved()) { Class typeClass = declaringClass.getTypeClass(); typeClass = typeClass.getEnclosingClass(); if (typeClass != null) {
private Expression createDefaultValueInitializer(DeclarationExpression expr) { TupleExpression tupleExpr = ObjectUtil.asInstance(expr.getLeftExpression(), TupleExpression.class); if (tupleExpr == null) { return EmptyExpression.INSTANCE; } assert expr.isMultipleAssignmentDeclaration(); // initializing to empty list only works when none of the element types is primitive, // so create a proper list expression ListExpression listExpr = new ListExpression(); for (Expression elementExpr : tupleExpr.getExpressions()) { Variable variable = (Variable) elementExpr; listExpr.addExpression(new ConstantExpression( ReflectionUtil.getDefaultValue(variable.getOriginType().getTypeClass()))); } return listExpr; }
Field field = type.redirect().getTypeClass().getField(pe.getPropertyAsString()); if (field != null && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) { ConstantExpression ce3 = new ConstantExpression(field.get(null), true);
/** * box top level operand */ public static boolean box(MethodVisitor mv, ClassNode type) { if (type.isPrimaryClassNode()) return false; return box(mv, type.getTypeClass()); }