/** * resolves a Field or Property node generics by using the current class and * the declaring class to extract the right meaning of the generics symbols * * @param an a FieldNode or PropertyNode * @param type the origin type * @return the new ClassNode with corrected generics */ private ClassNode getGenericsResolvedTypeOfFieldOrProperty(AnnotatedNode an, ClassNode type) { if (!type.isUsingGenerics()) return type; Map<GenericsTypeName, GenericsType> connections = new HashMap<GenericsTypeName, GenericsType>(); //TODO: inner classes mean a different this-type. This is ignored here! extractGenericsConnections(connections, typeCheckingContext.getEnclosingClassNode(), an.getDeclaringClass()); type = applyGenericsContext(connections, type); return type; }
public static boolean isStaticallyCompiled(AnnotatedNode node) { if (node.getNodeMetaData(STATIC_COMPILE_NODE)!=null) return (Boolean)node.getNodeMetaData(STATIC_COMPILE_NODE); if (node instanceof MethodNode) { return isStaticallyCompiled(node.getDeclaringClass()); } if (node instanceof InnerClassNode) { return isStaticallyCompiled(((InnerClassNode)node).getOuterClass()); } return false; }
public boolean isSkipMode(final AnnotatedNode node) { if (node == null) return false; for (ClassNode tca : getTypeCheckingAnnotations()) { List<AnnotationNode> annotations = node.getAnnotations(tca); if (annotations != null) { for (AnnotationNode annotation : annotations) { Expression value = annotation.getMember("value"); if (value != null) { if (value instanceof ConstantExpression) { ConstantExpression ce = (ConstantExpression) value; if (TypeCheckingMode.SKIP.toString().equals(ce.getValue().toString())) return true; } else if (value instanceof PropertyExpression) { PropertyExpression pe = (PropertyExpression) value; if (TypeCheckingMode.SKIP.toString().equals(pe.getPropertyAsString())) return true; } } } } } if (node instanceof MethodNode) { return isSkipMode(node.getDeclaringClass()); } if (isSkippedInnerClass(node)) return true; return false; }
ClassNode declaringClass = parent.getDeclaringClass(); if (parent instanceof FieldNode) { if ((((FieldNode) parent).getModifiers() & Opcodes.ACC_FINAL) != 0) { if (VetoableASTTransformation.hasVetoableAnnotation(parent.getDeclaringClass())) {
} else if (!applyToAllMembers && annotatedNode instanceof MethodNode) { this.visitMethod((MethodNode) annotatedNode); this.visitClass(annotatedNode.getDeclaringClass()); } else if (!applyToAllMembers && annotatedNode instanceof FieldNode) { this.visitField((FieldNode) annotatedNode); this.visitClass(annotatedNode.getDeclaringClass()); } else if (!applyToAllMembers && annotatedNode instanceof DeclarationExpression) { this.visitDeclarationExpression((DeclarationExpression) annotatedNode); this.visitClass(annotatedNode.getDeclaringClass()); } else {
private void addListenerToProperty(SourceUnit source, AnnotationNode node, AnnotatedNode parent) { ClassNode declaringClass = parent.getDeclaringClass(); FieldNode field = ((FieldNode) parent); String fieldName = field.getName(); for (PropertyNode propertyNode : declaringClass.getProperties()) { boolean bindable = BindableASTTransformation.hasBindableAnnotation(parent) || BindableASTTransformation.hasBindableAnnotation(parent.getDeclaringClass()); if (propertyNode.getName().equals(fieldName)) { if (field.isStatic()) { //noinspection ThrowableInstanceNeverThrown source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage( new SyntaxException("@groovy.beans.Vetoable cannot annotate a static property.", node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source)); } else { createListenerSetter(source, bindable, declaringClass, propertyNode); } return; } } //noinspection ThrowableInstanceNeverThrown source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage( new SyntaxException("@groovy.beans.Vetoable must be on a property, not a field. Try removing the private, protected, or public modifier.", node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source)); }
/** * Handles the bulk of the processing, mostly delegating to other methods. * * @param nodes the ast nodes * @param source the source unit for the nodes */ public void visit(ASTNode[] nodes, SourceUnit source) { if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) { throw new RuntimeException("Internal error: wrong types: " + nodes[0].getClass() + " / " + nodes[1].getClass()); } AnnotationNode annotation = (AnnotationNode) nodes[0]; AnnotatedNode parent = (AnnotatedNode) nodes[1]; ClassNode declaringClass = parent.getDeclaringClass(); if (parent instanceof FieldNode) { addListenerToProperty(source, annotation, declaringClass, (FieldNode) parent); } } }
/** * Handles the bulk of the processing, mostly delegating to other methods. * * @param nodes the ast nodes * @param source the source unit for the nodes */ public void visit(ASTNode[] nodes, SourceUnit source) { if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) { throw new RuntimeException("Internal error: wrong types: " + nodes[0].getClass() + " / " + nodes[1].getClass()); } AnnotationNode annotation = (AnnotationNode) nodes[0]; AnnotatedNode parent = (AnnotatedNode) nodes[1]; ClassNode declaringClass = parent.getDeclaringClass(); if (parent instanceof FieldNode) { addListenerToProperty(source, annotation, declaringClass, (FieldNode) parent); } } }
/** * Handles the bulk of the processing, mostly delegating to other methods. * * @param nodes the ast nodes * @param source the source unit for the nodes */ public void visit(ASTNode[] nodes, SourceUnit source) { if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) { throw new RuntimeException("Internal error: wrong types: " + nodes[0].getClass() + " / " + nodes[1].getClass()); } AnnotationNode annotation = (AnnotationNode) nodes[0]; AnnotatedNode parent = (AnnotatedNode) nodes[1]; ClassNode declaringClass = parent.getDeclaringClass(); if (parent instanceof FieldNode) { addListenerToProperty(source, annotation, declaringClass, (FieldNode) parent); } } }
/** * Handles the bulk of the processing, mostly delegating to other methods. * * @param nodes the ast nodes * @param source the source unit for the nodes */ public void visit(ASTNode[] nodes, SourceUnit source) { if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) { throw new RuntimeException("Internal error: wrong types: " + nodes[0].getClass() + " / " + nodes[1].getClass()); } AnnotationNode annotation = (AnnotationNode) nodes[0]; AnnotatedNode parent = (AnnotatedNode) nodes[1]; ClassNode declaringClass = parent.getDeclaringClass(); if (parent instanceof FieldNode) { addListenerToProperty(source, annotation, declaringClass, (FieldNode) parent); } } }
/** * Handles the bulk of the processing, mostly delegating to other methods. * * @param nodes the ast nodes * @param source the source unit for the nodes */ public void visit(ASTNode[] nodes, SourceUnit source) { if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) { throw new RuntimeException("Internal error: wrong types: " + nodes[0].getClass() + " / " + nodes[1].getClass()); } AnnotationNode annotation = (AnnotationNode) nodes[0]; AnnotatedNode parent = (AnnotatedNode) nodes[1]; ClassNode declaringClass = parent.getDeclaringClass(); if (parent instanceof FieldNode) { addListenerToProperty(source, annotation, declaringClass, (FieldNode) parent); } else if (parent instanceof ClassNode) { addListenerToClass(source, annotation, (ClassNode) parent); } }
/** * This ASTTransformation method is called when the compiler encounters our annotation. * * @param nodes An array of nodes. Index 0 is the annotation that triggered the call, index 1 * is the annotated node. * @param sourceUnit The SourceUnit describing the source code in which the annotation was placed. */ @Override public void visit(ASTNode[] nodes, SourceUnit sourceUnit) { if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) { throw new IllegalArgumentException("Internal error: wrong types: " + nodes[0].getClass().getName() + " / " + nodes[1].getClass().getName()); } AnnotationNode node = (AnnotationNode) nodes[0]; AnnotatedNode parent = (AnnotatedNode) nodes[1]; ClassNode declaringClass = parent.getDeclaringClass(); if (parent instanceof FieldNode) { int modifiers = ((FieldNode) parent).getModifiers(); if ((modifiers & Modifier.FINAL) != 0) { String msg = "@griffon.transform.FXObservable cannot annotate a final property."; generateSyntaxErrorMessage(sourceUnit, node, msg); } addJavaFXProperty(sourceUnit, node, declaringClass, (FieldNode) parent); } else { addJavaFXPropertyToClass(sourceUnit, node, (ClassNode) parent); } }
/** * This ASTTransformation method is called when the compiler encounters our annotation. * @param nodes An array of nodes. Index 0 is the annotation that triggered the call, index 1 * is the annotated node. * @param sourceUnit The SourceUnit describing the source code in which the annotation was placed. */ @Override public void visit(ASTNode[] nodes, SourceUnit sourceUnit) { if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) { throw new RuntimeException("Internal error: wrong types: $node.class / $parent.class"); } AnnotationNode node = (AnnotationNode) nodes[0]; AnnotatedNode parent = (AnnotatedNode) nodes[1]; ClassNode declaringClass = parent.getDeclaringClass(); if (parent instanceof FieldNode) { int modifiers = ((FieldNode) parent).getModifiers(); if ((modifiers & Opcodes.ACC_FINAL) != 0) { String msg = "@groovyfx.beans.FXBindable cannot annotate a final property."; generateSyntaxErrorMessage(sourceUnit, node, msg); } addJavaFXProperty(sourceUnit, node, declaringClass, (FieldNode) parent); } else { addJavaFXPropertyToClass(sourceUnit, node, (ClassNode) parent); } }
ClassNode declaringClass = parent.getDeclaringClass(); if (parent instanceof FieldNode) { if ((((FieldNode) parent).getModifiers() & Modifier.FINAL) != 0) { if (hasVetoableAnnotation(parent.getDeclaringClass())) {
ClassNode declaringClass = parent.getDeclaringClass(); if (parent instanceof FieldNode) { if ((((FieldNode)parent).getModifiers() & Opcodes.ACC_FINAL) != 0) { if (VetoableASTTransformation.hasVetoableAnnotation(parent.getDeclaringClass())) {
private void addListenerToProperty(SourceUnit source, AnnotationNode node, AnnotatedNode parent) { ClassNode declaringClass = parent.getDeclaringClass(); FieldNode field = ((FieldNode) parent); String fieldName = field.getName(); for (PropertyNode propertyNode : (Collection<PropertyNode>) declaringClass.getProperties()) { boolean bindable = BindableASTTransformation.hasBindableAnnotation(parent) || BindableASTTransformation.hasBindableAnnotation(parent.getDeclaringClass()); if (propertyNode.getName().equals(fieldName)) { if (field.isStatic()) { //noinspection ThrowableInstanceNeverThrown source.getErrorCollector().addErrorAndContinue( new SyntaxErrorMessage(new SyntaxException( "@groovy.beans.Vetoable cannot annotate a static property.", node.getLineNumber(), node.getColumnNumber()), source)); } else { createListenerSetter(source, node, bindable, declaringClass, propertyNode); } return; } } //noinspection ThrowableInstanceNeverThrown source.getErrorCollector().addErrorAndContinue( new SyntaxErrorMessage(new SyntaxException( "@groovy.beans.Vetoable must be on a property, not a field. Try removing the private, protected, or public modifier.", node.getLineNumber(), node.getColumnNumber()), source)); }
private void addListenerToProperty(SourceUnit source, AnnotationNode node, AnnotatedNode parent) { ClassNode declaringClass = parent.getDeclaringClass(); FieldNode field = ((FieldNode) parent); String fieldName = field.getName(); for (PropertyNode propertyNode : declaringClass.getProperties()) { boolean bindable = BindableASTTransformation.hasBindableAnnotation(parent) || BindableASTTransformation.hasBindableAnnotation(parent.getDeclaringClass()); if (propertyNode.getName().equals(fieldName)) { if (field.isStatic()) { //noinspection ThrowableInstanceNeverThrown source.getErrorCollector().addErrorAndContinue( new SyntaxErrorMessage(new SyntaxException( "@groovy.beans.Vetoable cannot annotate a static property.", node.getLineNumber(), node.getColumnNumber()), source)); } else { createListenerSetter(source, node, bindable, declaringClass, propertyNode); } return; } } //noinspection ThrowableInstanceNeverThrown source.getErrorCollector().addErrorAndContinue( new SyntaxErrorMessage(new SyntaxException( "@groovy.beans.Vetoable must be on a property, not a field. Try removing the private, protected, or public modifier.", node.getLineNumber(), node.getColumnNumber()), source)); }
private void addListenerToProperty(SourceUnit source, AnnotationNode node, AnnotatedNode parent) { ClassNode declaringClass = parent.getDeclaringClass(); FieldNode field = ((FieldNode) parent); String fieldName = field.getName(); for (PropertyNode propertyNode : (Collection<PropertyNode>) declaringClass.getProperties()) { boolean bindable = BindableASTTransformation.hasBindableAnnotation(parent) || BindableASTTransformation.hasBindableAnnotation(parent.getDeclaringClass()); if (propertyNode.getName().equals(fieldName)) { if (field.isStatic()) { //noinspection ThrowableInstanceNeverThrown source.getErrorCollector().addErrorAndContinue( new SyntaxErrorMessage(new SyntaxException( "@groovy.beans.Vetoable cannot annotate a static property.", node.getLineNumber(), node.getColumnNumber()), source)); } else { createListenerSetter(source, node, bindable, declaringClass, propertyNode); } return; } } //noinspection ThrowableInstanceNeverThrown source.getErrorCollector().addErrorAndContinue( new SyntaxErrorMessage(new SyntaxException( "@groovy.beans.Vetoable must be on a property, not a field. Try removing the private, protected, or public modifier.", node.getLineNumber(), node.getColumnNumber()), source)); }
private void addVetoableIfNeeded(SourceUnit source, AnnotationNode node, AnnotatedNode parent) { ClassNode declaringClass = parent.getDeclaringClass(); FieldNode field = ((FieldNode) parent); String fieldName = field.getName(); for (PropertyNode propertyNode : declaringClass.getProperties()) { boolean bindable = hasObservableAnnotation(parent) || hasObservableAnnotation(parent.getDeclaringClass()); if (propertyNode.getName().equals(fieldName)) { if (field.isStatic()) { source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage( new SyntaxException("@griffon.transform.Vetoable cannot annotate a static property.", node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source)); } else { createListenerSetter(source, bindable, declaringClass, propertyNode); } return; } } source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage( new SyntaxException("@griffon.transform.Vetoable must be on a property, not a field. Try removing the private, protected, or public modifier.", node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source)); }
ClassNode declaringClass = node.getDeclaringClass(); if (declaringClass.implementsInterface(GRIFFON_CONTROLLER_CNODE)) { return;