/** * @return true if we are in a script body, where all variables declared are no longer * local variables but are properties */ public boolean isInScriptBody() { if (classNode.isScriptBody()) { return true; } else { return classNode.isScript() && methodNode != null && methodNode.getName().equals("run"); } }
private static List<MethodNode> filterMethods(ClassNode owner) { List<MethodNode> result = new LinkedList<MethodNode>(); List<MethodNode> methods = owner.getMethods(); for (MethodNode method : methods) { if (method.getDeclaringClass() == owner && !method.isSynthetic()) { if ("main".equals(method.getName()) || "run".equals(method.getName()) && owner.isScriptBody()) continue; result.add(method); } } return result; }
private void changeBaseScriptTypeFromPackageOrImport(final SourceUnit source, final AnnotatedNode parent, final AnnotationNode node) { Expression value = node.getMember("value"); if (!(value instanceof ClassExpression)) { addError("Annotation " + MY_TYPE_NAME + " member 'value' should be a class literal.", value); return; } List<ClassNode> classes = source.getAST().getClasses(); for (ClassNode classNode : classes) { if (classNode.isScriptBody()) { changeBaseScriptType(parent, classNode, value.getType()); } } }
@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 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); } } }
if (node.isScriptBody() || stored.isScriptBody()) { txt += "One of the classes is an explicit generated class using the class statement, the other is a class generated from" + " the script body based on the file name. Solutions are to change the file name or to change the class name.\n";
private void changeBaseScriptType(final SourceUnit source, final AnnotatedNode parent, final ClassNode cNode, final ClassNode baseScriptType, final AnnotationNode node) { if (!cNode.isScriptBody()) { addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script.", parent); return;
private void changeBaseScriptType(final AnnotatedNode parent, final ClassNode cNode, final ClassNode baseScriptType) { if (!cNode.isScriptBody()) { addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script.", parent); return;
/** * @return true if we are in a script body, where all variables declared are no longer * local variables but are properties */ public boolean isInScriptBody() { if (classNode.isScriptBody()) { return true; } else { return classNode.isScript() && methodNode != null && methodNode.getName().equals("run"); } }
/** * @return true if we are in a script body, where all variables declared are no longer * local variables but are properties */ protected boolean isInScriptBody() { if (classNode.isScriptBody()) { return true; } else { return classNode.isScript() && methodNode != null && methodNode.getName().equals("run"); } }
/** * @return true if we are in a script body, where all variables declared are no longer * local variables but are properties */ protected boolean isInScriptBody() { if (classNode.isScriptBody()) { return true; } else { return classNode.isScript() && methodNode != null && methodNode.getName().equals("run"); } }
/** * @return true if we are in a script body, where all variables declared are no longer * local variables but are properties */ protected boolean isInScriptBody() { if (classNode.isScriptBody()) { return true; } else { return classNode.isScript() && methodNode != null && methodNode.getName().equals("run"); } }
private List<MethodNode> filterMethods(ClassNode owner) { List<MethodNode> result = new LinkedList<MethodNode>(); List<MethodNode> methods = owner.getMethods(); for (MethodNode method : methods) { if (method.getDeclaringClass() == owner && !method.isSynthetic()) { if ("main".equals(method.getName()) || "run".equals(method.getName()) && owner.isScriptBody()) continue; result.add(method); } } return result; }
/** * Checks whether the given {@link org.codehaus.groovy.ast.ClassNode} is a candidate * for applying interface contracts. * * @param type the {@link org.codehaus.groovy.ast.ClassNode} to be checked * @return whether the given <tt>type</tt> is a candidate for applying interface contract assertions */ public static boolean isInterfaceContractsCandidate(final ClassNode type) { return type != null && type.isInterface() && !type.isSynthetic() && !type.isEnum() && !type.isGenericsPlaceHolder() && !type.isScript() && !type.isScriptBody() && !isRuntimeClass(type); }
@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); } }
/** * Checks whether the given {@link org.codehaus.groovy.ast.ClassNode} is a candidate * for applying contracts. <p/> * * If the given class node has already been processed in this compilation run, this * method will return <tt>false</tt>. * * @param type the {@link org.codehaus.groovy.ast.ClassNode} to be checked * @return whether the given <tt>type</tt> is a candidate for applying contract assertions */ public static boolean isContractsCandidate(final ClassNode type) { return type != null && !type.isSynthetic() && !type.isInterface() && !type.isEnum() && !type.isGenericsPlaceHolder() && !type.isScript() && !type.isScriptBody() && !isRuntimeClass(type); }
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); } } }
if (node.isScriptBody() || stored.isScriptBody()) { txt += "One of the classes is a explicit generated class using the class statement, the other is a class generated from"+ " the script body based on the file name. Solutions are to change the file name or to change the class name.\n";
if (node.isScriptBody() || stored.isScriptBody()) { txt += "One of the classes is an explicit generated class using the class statement, the other is a class generated from" + " the script body based on the file name. Solutions are to change the file name or to change the class name.\n";
private void changeBaseScriptType(final SourceUnit source, final AnnotatedNode parent, final ClassNode cNode, final ClassNode baseScriptType, final AnnotationNode node) { if (!cNode.isScriptBody()) { addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script.", parent); return;