Search in sources :

Example 11 with Annotation

use of org.eclipse.jdt.core.dom.Annotation in project generator by mybatis.

the class JavaFileMerger method addExistsAnnotations.

@SuppressWarnings("unchecked")
private void addExistsAnnotations(BodyDeclaration node, List<Annotation> oldAnnotations) {
    Set<String> newAnnotationTypes = new HashSet<String>();
    int lastAnnotationIndex = 0;
    int idx = 0;
    for (Object modifier : node.modifiers()) {
        if (modifier instanceof Annotation) {
            Annotation newAnnotation = (Annotation) modifier;
            newAnnotationTypes.add(newAnnotation.getTypeName().getFullyQualifiedName());
            lastAnnotationIndex = idx;
        }
        idx++;
    }
    if (oldAnnotations != null) {
        for (Annotation oldAnnotation : oldAnnotations) {
            if (newAnnotationTypes.contains(oldAnnotation.getTypeName().getFullyQualifiedName()))
                continue;
            AST nodeAst = node.getAST();
            node.modifiers().add(lastAnnotationIndex++, ASTNode.copySubtree(nodeAst, oldAnnotation));
        }
    }
}
Also used : AST(org.eclipse.jdt.core.dom.AST) Annotation(org.eclipse.jdt.core.dom.Annotation) HashSet(java.util.HashSet)

Example 12 with Annotation

use of org.eclipse.jdt.core.dom.Annotation in project che by eclipse.

the class ExtractConstantRefactoring method getReplacementScope.

/*
	 * Elements returned by next() are BodyDeclaration or Annotation instances.
	 */
private Iterator<ASTNode> getReplacementScope() throws JavaModelException {
    boolean declPredecessorReached = false;
    Collection<ASTNode> scope = new ArrayList<ASTNode>();
    AbstractTypeDeclaration containingType = getContainingTypeDeclarationNode();
    if (containingType instanceof EnumDeclaration) {
        // replace in all enum constants bodies
        EnumDeclaration enumDeclaration = (EnumDeclaration) containingType;
        scope.addAll(enumDeclaration.enumConstants());
    }
    for (Iterator<IExtendedModifier> iter = containingType.modifiers().iterator(); iter.hasNext(); ) {
        IExtendedModifier modifier = iter.next();
        if (modifier instanceof Annotation) {
            scope.add((ASTNode) modifier);
        }
    }
    for (Iterator<BodyDeclaration> bodyDeclarations = containingType.bodyDeclarations().iterator(); bodyDeclarations.hasNext(); ) {
        BodyDeclaration bodyDeclaration = bodyDeclarations.next();
        if (bodyDeclaration == getNodeToInsertConstantDeclarationAfter())
            declPredecessorReached = true;
        if (insertFirst() || declPredecessorReached || !isStaticFieldOrStaticInitializer(bodyDeclaration))
            scope.add(bodyDeclaration);
    }
    return scope.iterator();
}
Also used : ArrayList(java.util.ArrayList) ASTNode(org.eclipse.jdt.core.dom.ASTNode) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration) Annotation(org.eclipse.jdt.core.dom.Annotation) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration) EnumDeclaration(org.eclipse.jdt.core.dom.EnumDeclaration) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier)

Example 13 with Annotation

use of org.eclipse.jdt.core.dom.Annotation in project Main by SpartanRefactoring.

the class ZZZ___Fixture_ModelClass method a32.

@Test
@method
public void a32() {
    for (final Annotation a : annotations()) {
        final SingleMemberAnnotation ¢ = az.singleMemberAnnotation(a);
        if (¢ == null)
            continue;
        final List<SimpleName> ns = annotees.of(¢);
        assert ns != null;
        final SimpleName n = the.firstOf(ns);
        assert n != null;
        if (!"annotation".equals(n + ""))
            continue;
        final List<? extends ASTNode> s = scope.of(n);
        assert s != null : //
        fault.dump() + "\n\t scope = " + //
        s + "\n\t ¢ = " + //
        ¢ + "\n\t n = " + //
        n + "\n\t ns = " + //
        ns + fault.done();
    }
}
Also used : Annotation(org.eclipse.jdt.core.dom.Annotation)

Example 14 with Annotation

use of org.eclipse.jdt.core.dom.Annotation in project Main by SpartanRefactoring.

the class ZZZ___Fixture_ModelClass method a33.

@Test
@method
public void a33() {
    for (final Annotation a : annotations()) {
        final SingleMemberAnnotation x = az.singleMemberAnnotation(a);
        if (x != null && (x.getTypeName() + "").equals(ScopeSize.class.getSimpleName() + "")) {
            final SimpleName n = the.firstOf(annotees.of(x));
            if (!"fenum".equals(n + ""))
                continue;
            azzert.that(x + ": " + n + "/" + definition.kind(n), scope.of(n).size(), is(value(x)));
        }
    }
}
Also used : Annotation(org.eclipse.jdt.core.dom.Annotation)

Example 15 with Annotation

use of org.eclipse.jdt.core.dom.Annotation in project Main by SpartanRefactoring.

the class ZZZ___Fixture_ModelClass method a38.

@Test
@method
public void a38() {
    for (final Annotation a : annotations()) {
        final SingleMemberAnnotation x = az.singleMemberAnnotation(a);
        if (x != null && (x.getTypeName() + "").equals(ScopeSize.class.getSimpleName() + "")) {
            final SimpleName n = the.firstOf(annotees.of(x));
            if (!DummyClass.class.getSimpleName().equals(n + ""))
                continue;
            azzert.that(x + ": " + n + "/" + definition.kind(n), scope.of(n).size(), is(value(x)));
        }
    }
}
Also used : Annotation(org.eclipse.jdt.core.dom.Annotation)

Aggregations

Annotation (org.eclipse.jdt.core.dom.Annotation)34 ASTNode (org.eclipse.jdt.core.dom.ASTNode)10 IExtendedModifier (org.eclipse.jdt.core.dom.IExtendedModifier)9 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)7 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)5 Name (org.eclipse.jdt.core.dom.Name)5 SingleMemberAnnotation (org.eclipse.jdt.core.dom.SingleMemberAnnotation)5 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)4 ArrayType (org.eclipse.jdt.core.dom.ArrayType)4 NormalAnnotation (org.eclipse.jdt.core.dom.NormalAnnotation)4 ArrayList (java.util.ArrayList)3 AST (org.eclipse.jdt.core.dom.AST)3 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)3 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)3 ParameterizedType (org.eclipse.jdt.core.dom.ParameterizedType)3 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)3 Type (org.eclipse.jdt.core.dom.Type)3 HashSet (java.util.HashSet)2 List (java.util.List)2 AbstractTypeDeclaration (org.eclipse.jdt.core.dom.AbstractTypeDeclaration)2