/** * this method actually does not compile a class. It's only * a marker that this type has to be compiled by the CompilationUnit * at the end of a parse step no node should be be left. */ public void addClassNodeToCompile(ClassNode node, SourceUnit location) { classesToCompile.put(node.getName(), node); classNameToSource.put(node.getName(), location); }
public Spec(ClassNode code) { super(null, code); setName(code.getName()); }
public String getName() { if (redirect()!=this) return super.getName(); return className; } public boolean hasPackageName() {
public static AnnotationNode getAnnotation(ASTNode node, Class<?> annotationType) { if (!(node instanceof AnnotatedNode)) return null; AnnotatedNode annotated = (AnnotatedNode)node; @SuppressWarnings("unchecked") List<AnnotationNode> annotations = annotated.getAnnotations(); for (AnnotationNode a : annotations) if (a.getClassNode().getName().equals(annotationType.getName())) return a; return null; }
public int compare(final ClassNode o1, final ClassNode o2) { int interfaceCountForO1 = o1.getInterfaces().length; int interfaceCountForO2 = o2.getInterfaces().length; if (interfaceCountForO1 > interfaceCountForO2) return -1; if (interfaceCountForO1 < interfaceCountForO2) return 1; int methodCountForO1 = o1.getMethods().size(); int methodCountForO2 = o2.getMethods().size(); if (methodCountForO1 > methodCountForO2) return -1; if (methodCountForO1 < methodCountForO2) return 1; return o1.getName().compareTo(o2.getName()); } };
public static boolean isWildcardRef(Expression expr) { VariableExpression varExpr = ObjectUtil.asInstance(expr, VariableExpression.class); if (varExpr == null || !varExpr.getName().equals(Wildcard.INSTANCE.toString())) return false; Variable accessedVar = varExpr.getAccessedVariable(); if (!(accessedVar instanceof FieldNode)) return false; return ((FieldNode) accessedVar).getOwner().getName().equals(Specification.class.getName()); }
public GenericsType(ClassNode type, ClassNode[] upperBounds, ClassNode lowerBound) { this.type = type; this.name = type.isGenericsPlaceHolder() ? type.getUnresolvedName() : type.getName(); this.upperBounds = upperBounds; this.lowerBound = lowerBound; placeholder = type.isGenericsPlaceHolder(); resolved = false; }
protected void visitEnumExpression(String attrName, PropertyExpression propExpr, ClassNode attrType) { if (!propExpr.getObjectExpression().getType().isDerivedFrom(attrType)) { addError("Attribute '" + attrName + "' should have type '" + attrType.getName() + "' (Enum), but found " + propExpr.getObjectExpression().getType().getName(), propExpr); } }
private static boolean checkIsConditionBlock(MethodCallExpression methodCallExpr) { ClassNode targetType = methodCallExpr.getObjectExpression().getType(); String methodName = methodCallExpr.getMethodAsString(); List<MethodNode> methods = targetType.getMethods(methodName); for (MethodNode method : methods) { for (AnnotationNode annotation : method.getAnnotations()) { if (annotation.getClassNode().getName().equals(ConditionBlock.class.getName())) return true; } } return false; } }
protected Class loadClass(ClassNode classNode) { classNode.setModule(module); Class fooClass = loader.defineClass(classNode, classNode.getName() + ".groovy", "groovy.testSupport"); return fooClass; }
/** * @return the ClassNode of the super class of this type */ public ClassNode getSuperClass() { if (!lazyInitDone && !isResolved()) { throw new GroovyBugError("ClassNode#getSuperClass for "+getName()+" called before class resolving"); } ClassNode sn = redirect().getUnresolvedSuperClass(); if (sn!=null) sn=sn.redirect(); return sn; }
void processSpec(ClassNode clazz, ErrorReporter errorReporter, SourceLookup sourceLookup) { try { Spec spec = new SpecParser(errorReporter).build(clazz); spec.accept(new SpecRewriter(nodeCache, sourceLookup, errorReporter)); spec.accept(new SpecAnnotator(nodeCache)); } catch (Exception e) { errorReporter.error( "Unexpected error during compilation of spec '%s'. Maybe you have used invalid Spock syntax? Anyway, please file a bug report at http://issues.spockframework.org.", e, clazz.getName()); } } }
public void testPrimitiveOriginType() { VariableExpression boolExpression = new VariableExpression("fo",ClassHelper.boolean_TYPE); VariableExpression intExpression = new VariableExpression("foo", ClassHelper.int_TYPE); assertEquals(boolExpression.getOriginType().getName(),"boolean"); assertEquals(intExpression.getOriginType().getName(),"int"); }
public void testNonPrimitiveOriginType() { VariableExpression boolExpression = new VariableExpression("foo",ClassHelper.Boolean_TYPE); VariableExpression intExpression = new VariableExpression("foo", ClassHelper.Integer_TYPE); assertEquals(boolExpression.getOriginType().getName(),"java.lang.Boolean"); assertEquals(intExpression.getOriginType().getName(),"java.lang.Integer"); }
public void testPrimitiveOriginTypeConstructorParameter() { Parameter boolParameter = new Parameter(ClassHelper.boolean_TYPE,"foo"); Parameter intParameter = new Parameter(ClassHelper.int_TYPE,"foo"); VariableExpression newBoolExpression = new VariableExpression(boolParameter); VariableExpression newIntExpression = new VariableExpression(intParameter); assertEquals(newBoolExpression.getOriginType().getName(),"boolean"); assertEquals(newIntExpression.getOriginType().getName(),"int"); }
public void testPrimitiveOriginTypeConstructorVariableExpression() { VariableExpression boolExpression = new VariableExpression("foo",ClassHelper.boolean_TYPE); VariableExpression intExpression = new VariableExpression("foo", ClassHelper.int_TYPE); VariableExpression newBoolExpression = new VariableExpression(boolExpression); VariableExpression newIntExpression = new VariableExpression(intExpression); assertEquals(newBoolExpression.getOriginType().getName(),"boolean"); assertEquals(newIntExpression.getOriginType().getName(),"int"); }
public void visitConstructorCallExpression(ConstructorCallExpression call) { onLineNumber(call, "visitConstructorCallExpression: \"" + call.getType().getName() + "\":"); if (call.isSpecialCall()) { controller.getInvocationWriter().writeSpecialConstructorCall(call); return; } controller.getInvocationWriter().writeInvokeConstructor(call); controller.getAssertionWriter().record(call); }
public void checkReturnType(ClassNode attrType, ASTNode node) { if (attrType.isArray()) { checkReturnType(attrType.getComponentType(), node); } else if (ClassHelper.isPrimitiveType(attrType)) { } else if (ClassHelper.STRING_TYPE.equals(attrType)) { } else if (ClassHelper.CLASS_Type.equals(attrType)) { } else if (attrType.isDerivedFrom(ClassHelper.Enum_Type)) { } else if (isValidAnnotationClass(attrType)) { } else { addError("Unexpected return type " + attrType.getName(), node); } }
public void testStatementClass_FAILS() throws Exception { if (notYetImplemented()) return; ModuleNode module = parse("x = [1, 2, 3]; println(x)", "Cheese.groovy"); assertTrue("Should have statements", !module.getStatementBlock().isEmpty()); List classes = module.getClasses(); assertEquals("Number of classes", 1, classes.size()); ClassNode classNode = (ClassNode) classes.get(0); assertEquals("Class name", "Cheese", classNode.getName()); } }