outBuffer.append(controller.getClassNode().toString()).append("#").append(node.getName()); outBuffer.append(" with signature ").append(node.getTypeDescriptor()); outBuffer.append(" in ").append(sourceFile).append(":").append(node.getLineNumber()); if (writer != null) { outBuffer.append("\nLast known generated bytecode in last generated method or constructor:\n");
private static SyntaxException createException(ClassNode trait, ClassNode targetNode, MethodNode forwarder, MethodNode existingMethod) { String middle; ASTNode errorTarget; if (existingMethod.getLineNumber() == -1) { // came from a trait errorTarget = targetNode; List<AnnotationNode> allAnnos = existingMethod.getAnnotations(Traits.TRAITBRIDGE_CLASSNODE); AnnotationNode bridgeAnno = allAnnos == null ? null : allAnnos.get(0); String fromTrait = null; if (bridgeAnno != null) { Expression traitClass = bridgeAnno.getMember("traitClass"); if (traitClass instanceof ClassExpression) { ClassExpression ce = (ClassExpression) traitClass; fromTrait = ce.getType().getNameWithoutPackage(); } } middle = "in '" + targetNode.getNameWithoutPackage(); if (fromTrait != null) { middle += "' from trait '" + fromTrait; } } else { errorTarget = existingMethod; middle = "declared in '" + targetNode.getNameWithoutPackage(); } String message = "The static '" + forwarder.getName() + "' method " + middle + "' conflicts with the instance method having the same signature from trait '" + trait.getNameWithoutPackage() + "'"; return new SyntaxException(message, errorTarget); }
private void addFeatureMetadata(FeatureMethod feature) { AnnotationNode ann = new AnnotationNode(nodeCache.FeatureMetadata); ann.setMember(FeatureMetadata.NAME, new ConstantExpression(feature.getName())); ann.setMember(FeatureMetadata.ORDINAL, new ConstantExpression(feature.getOrdinal())); ann.setMember(FeatureMetadata.LINE, new ConstantExpression(feature.getAst().getLineNumber())); ann.setMember(FeatureMetadata.BLOCKS, blockAnnElems = new ListExpression()); ListExpression paramNames = new ListExpression(); for (Parameter param : feature.getAst().getParameters()) paramNames.addExpression(new ConstantExpression(param.getName())); ann.setMember(FeatureMetadata.PARAMETER_NAMES, paramNames); feature.getAst().addAnnotation(ann); }
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())); return null;
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; }
/** * * @param method a potential controller action method * @return true if the method should be configured as a controller action, false otherwise */ protected boolean methodShouldBeConfiguredAsControllerAction(final MethodNode method) { int minLineNumber = 0; if (isInheritedFromTrait(method) && hasAnnotation(method, Action.class) && hasParameters(method)) { removeAnnotation(method, Action.class); //Trait methods have a line number of -1 --minLineNumber; } return !method.isStatic() && method.isPublic() && !method.isAbstract() && method.getAnnotations(ACTION_ANNOTATION_NODE.getClassNode()).isEmpty() && method.getAnnotations(new ClassNode(ControllerMethod.class)).isEmpty() && method.getLineNumber() >= minLineNumber && !method.getName().startsWith("$") && !method.getReturnType().getName().equals(VOID_TYPE) && !isExceptionHandlingMethod(method); }
for (Entry<String, MethodNode> methodEntry : declaredMethodsMap.entrySet()) { final MethodNode value = methodEntry.getValue(); if (!value.isStatic() && value.isPublic() && classNode.equals(value.getDeclaringClass()) && value.getLineNumber() > 0) { Parameter[] parameters = value.getParameters(); if (parameters == null || parameters.length == 0) {