Java Code Examples for org.codehaus.groovy.ast.MethodNode#isScriptBody()

The following examples show how to use org.codehaus.groovy.ast.MethodNode#isScriptBody() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Verifier.java    From groovy with Apache License 2.0 6 votes vote down vote up
private static void checkForDuplicateMethods(ClassNode cn) {
    Set<String> descriptors = new HashSet<String>();
    for (MethodNode mn : cn.getMethods()) {
        if (mn.isSynthetic()) continue;
        String mySig = methodDescriptorWithoutReturnType(mn);
        if (descriptors.contains(mySig)) {
            if (mn.isScriptBody() || mySig.equals(scriptBodySignatureWithoutReturnType(cn))) {
                throw new RuntimeParserException("The method " + mn.getText() +
                        " is a duplicate of the one declared for this script's body code", sourceOf(mn));
            } else {
                throw new RuntimeParserException("The method " + mn.getText() +
                        " duplicates another method of the same signature", sourceOf(mn));
            }
        }
        descriptors.add(mySig);
    }
}
 
Example 2
Source File: FieldASTTransformation.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
public void visitMethod(MethodNode node) {
    boolean oldInsideScriptBody = insideScriptBody;
    if (node.isScriptBody()) insideScriptBody = true;
    super.visitMethod(node);
    insideScriptBody = oldInsideScriptBody;
}
 
Example 3
Source File: Verifier.java    From groovy with Apache License 2.0 4 votes vote down vote up
private static String scriptBodySignatureWithoutReturnType(ClassNode cn) {
    for (MethodNode mn : cn.getMethods()) {
        if (mn.isScriptBody()) return methodDescriptorWithoutReturnType(mn);
    }
    return null;
}