private static void removeSyntheticMethodIfOne(List<MethodNode> toBeRemoved, MethodNode one, MethodNode two) { if (one.isSynthetic() && !two.isSynthetic()) { toBeRemoved.add(one); } else if (two.isSynthetic() && !one.isSynthetic()) { toBeRemoved.add(two); } }
public static boolean isSynthetic(MethodNode method) { return method.isSynthetic() || (method.getModifiers() & Opcodes.ACC_SYNTHETIC) != 0; }
private boolean isSynthetic(MethodNode existingMethodNode) { return existingMethodNode.isSynthetic() || hasSyntheticModifier(existingMethodNode); }
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 static List<ClassNode[]> extractSignaturesFromMethods(final ClassNode cn) { List<MethodNode> methods = cn.getAllDeclaredMethods(); List<ClassNode[]> signatures = new LinkedList<ClassNode[]>(); for (MethodNode method : methods) { if (!method.isSynthetic() && method.isAbstract()) { extractParametersFromMethod(signatures, method); } } return signatures; }
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", mn); } else { throw new RuntimeParserException("The method " + mn.getText() + " duplicates another method of the same signature", mn); } } descriptors.add(mySig); } }
private void processConstructorOrMethod(MethodNode mNode, ClassCodeVisitorSupport visitor) { if (!isEnabled(mNode)) return; if (mNode.isSynthetic()) return; Parameter[] origParams = mNode.getParameters(); for (Parameter p : origParams) { p.setModifiers(p.getModifiers() | Modifier.FINAL); } visitor.visitMethod(mNode); }
public MethodNode getGetterMethod(String getterName, boolean searchSuperClasses) { MethodNode getterMethod = null; boolean booleanReturnOnly = getterName.startsWith("is"); for (MethodNode method : getDeclaredMethods(getterName)) { if (getterName.equals(method.getName()) && ClassHelper.VOID_TYPE!=method.getReturnType() && method.getParameters().length == 0 && (!booleanReturnOnly || ClassHelper.Boolean_TYPE.equals(ClassHelper.getWrapper(method.getReturnType())))) { // GROOVY-7363: There can be multiple matches for a getter returning a generic parameter type, due to // the generation of a bridge method. The real getter is really the non-bridge, non-synthetic one as it // has the most specific and exact return type of the two. Picking the bridge method results in loss of // type information, as it down-casts the return type to the lower bound of the generic parameter. if (getterMethod == null || getterMethod.isSynthetic()) { getterMethod = method; } } } if (getterMethod != null) return getterMethod; if (searchSuperClasses) { ClassNode parent = getSuperClass(); if (parent != null) return parent.getGetterMethod(getterName); } return null; }
methods.addAll(classNode.getMethods()); for (MethodNode method : methods) { if (isEnum && method.isSynthetic()) {
private void printMethod(PrintWriter out, ClassNode clazz, MethodNode methodNode) { if (methodNode.getName().equals("<clinit>")) return; if (methodNode.isPrivate() || !Utilities.isJavaIdentifier(methodNode.getName())) return; if (methodNode.isSynthetic() && methodNode.getName().equals("$getStaticMetaClass")) return;
checkMethodDefinitionAllowed(clNode); for (MethodNode methodNode : clNode.getMethods()) { if (!methodNode.isSynthetic() && methodNode.getCode() != null) { methodNode.getCode().visit(visitor);
private MethodNode copyMethod(MethodNode method, String newName) { // can't hurt to set return type to void MethodNode newMethod = new MethodNode(newName, method.getModifiers(), ClassHelper.VOID_TYPE, method.getParameters(), method.getExceptions(), method.getCode()); newMethod.addAnnotations(method.getAnnotations()); newMethod.setSynthetic(method.isSynthetic()); newMethod.setDeclaringClass(method.getDeclaringClass()); newMethod.setSourcePosition(method); newMethod.setVariableScope(method.getVariableScope()); newMethod.setGenericsTypes(method.getGenericsTypes()); newMethod.setAnnotationDefault(method.hasAnnotationDefault()); return newMethod; }
boolean declared = methodNode.getDeclaringClass() == cNode; if (declared) { if (!methodNode.isSynthetic() && (methodNode.isProtected() || methodNode.getModifiers()==0)) { unit.addError(new SyntaxException("Cannot have protected/package private method in a trait (" + cNode.getName() + "#" + methodNode.getTypeDescriptor() + ")", methodNode.getLineNumber(), methodNode.getColumnNumber()));
/** * Decides whether the given <tt>method</tt> is a candidate for a pre-condition. * * @param type the current {@link org.codehaus.groovy.ast.ClassNode} * @param method the {@link org.codehaus.groovy.ast.MethodNode} to check for pre-condition compliance * @return whether the given {@link org.codehaus.groovy.ast.MethodNode} is a candidate for pre-conditions */ public static boolean isPreconditionCandidate(final ClassNode type, final MethodNode method) { if (method.isSynthetic() || method.isAbstract()) return false; if (method.getDeclaringClass() != type) return false; return true; }
public static boolean isAddableMethod(MethodNode declaredMethod) { ClassNode groovyMethods = GROOVY_OBJECT_CLASS_NODE; String methodName = declaredMethod.getName(); return !declaredMethod.isSynthetic() && !methodName.contains("$") && Modifier.isPublic(declaredMethod.getModifiers()) && !Modifier.isAbstract(declaredMethod.getModifiers()) && !hasSimilarMethod(declaredMethod, groovyMethods); }
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; }
private static boolean isCandidateMethod(MethodNode declaredMethod) { ClassNode groovyMethods = GROOVY_OBJECT_CLASS_NODE; String methodName = declaredMethod.getName(); return !declaredMethod.isSynthetic() && !methodName.contains("$") && Modifier.isPublic(declaredMethod.getModifiers()) && !groovyMethods.hasMethod(declaredMethod.getName(), declaredMethod.getParameters()); }
private static boolean isVisible(ASTElement element) { // FIXME perhaps we should store synthetic atributte in AstElement if ((element.getKind() == ElementKind.METHOD)) { ASTMethod method = (ASTMethod) element; ASTNode node = method.getNode(); return !(node instanceof MethodNode) || (!((MethodNode) node).isSynthetic() && ((MethodNode) node).getLineNumber() >= 0); } return true; }
public static boolean isAddableMethod(MethodNode declaredMethod) { ClassNode groovyMethods = GROOVY_OBJECT_CLASS_NODE; String methodName = declaredMethod.getName(); return !declaredMethod.isSynthetic() && !methodName.contains("$") && Modifier.isPublic(declaredMethod.getModifiers()) && !Modifier.isAbstract(declaredMethod.getModifiers()) && !groovyMethods.hasMethod(declaredMethod.getName(), declaredMethod.getParameters()); }
/** * Decides whether the given <tt>method</tt> is a candidate for class invariants. * * @param type the current {@link org.codehaus.groovy.ast.ClassNode} * @param method the {@link org.codehaus.groovy.ast.MethodNode} to check for class invariant compliance * @return whether the given {@link org.codehaus.groovy.ast.MethodNode} is a candidate for class invariants */ public static boolean isClassInvariantCandidate(final ClassNode type, final MethodNode method) { if (method.isSynthetic() || method.isAbstract() || method.isStatic() || !method.isPublic()) return false; if (method.getDeclaringClass() != type) return false; return true; }