Search in sources :

Example 1 with CtExtendedModifier

use of spoon.support.reflect.CtExtendedModifier in project spoon by INRIA.

the class JDTTreeBuilder method visit.

@Override
public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope scope) {
    CtConstructor<Object> c = factory.Core().createConstructor();
    if (constructorDeclaration.binding != null) {
        c.setExtendedModifiers(getModifiers(constructorDeclaration.binding.modifiers, true, true));
    }
    for (CtExtendedModifier extendedModifier : getModifiers(constructorDeclaration.modifiers, false, true)) {
        // avoid to keep implicit AND explicit modifier of the same kind.
        c.addModifier(extendedModifier.getKind());
    }
    context.enter(c, constructorDeclaration);
    // Create block
    context.enter(factory.Core().createBlock(), constructorDeclaration);
    context.exit(constructorDeclaration);
    return true;
}
Also used : CtExtendedModifier(spoon.support.reflect.CtExtendedModifier)

Example 2 with CtExtendedModifier

use of spoon.support.reflect.CtExtendedModifier in project spoon by INRIA.

the class JDTTreeBuilder method visit.

@Override
public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) {
    CtField<Object> field;
    if (fieldDeclaration.type != null) {
        field = factory.Core().createField();
    } else {
        field = factory.Core().createEnumValue();
        if (fieldDeclaration.binding != null) {
            field.setType(references.getTypeReference(fieldDeclaration.binding.type));
        }
    }
    field.setSimpleName(CharOperation.charToString(fieldDeclaration.name));
    Set<CtExtendedModifier> modifierSet = new HashSet<>();
    if (fieldDeclaration.binding != null) {
        field.setExtendedModifiers(getModifiers(fieldDeclaration.binding.modifiers, true, false));
    }
    for (CtExtendedModifier extendedModifier : getModifiers(fieldDeclaration.modifiers, false, false)) {
        // avoid to keep implicit AND explicit modifier of the same kind.
        field.addModifier(extendedModifier.getKind());
    }
    context.enter(field, fieldDeclaration);
    return true;
}
Also used : CtExtendedModifier(spoon.support.reflect.CtExtendedModifier) HashSet(java.util.HashSet)

Example 3 with CtExtendedModifier

use of spoon.support.reflect.CtExtendedModifier in project spoon by INRIA.

the class ElementPrinterHelper method writeModifiers.

/**
 *  writes the modifiers of this modifiable in a specific order
 */
public void writeModifiers(CtModifiable modifiable) {
    // write the modifiers according to the convention on order
    // visibility: public, private, protected
    List<String> firstPosition = new ArrayList<>();
    // keywords: static, abstract
    List<String> secondPosition = new ArrayList<>();
    // all other things
    List<String> thirdPosition = new ArrayList<>();
    for (CtExtendedModifier extendedModifier : modifiable.getExtendedModifiers()) {
        if (!extendedModifier.isImplicit()) {
            ModifierKind modifierKind = extendedModifier.getKind();
            if (modifierKind == ModifierKind.PUBLIC || modifierKind == ModifierKind.PRIVATE || modifierKind == ModifierKind.PROTECTED) {
                firstPosition.add(modifierKind.toString());
            } else if (modifierKind == ModifierKind.ABSTRACT || modifierKind == ModifierKind.STATIC) {
                secondPosition.add(modifierKind.toString());
            } else {
                thirdPosition.add(modifierKind.toString());
            }
        }
    }
    for (String s : firstPosition) {
        printer.writeKeyword(s).writeSpace();
    }
    for (String s : secondPosition) {
        printer.writeKeyword(s).writeSpace();
    }
    for (String s : thirdPosition) {
        printer.writeKeyword(s).writeSpace();
    }
}
Also used : ArrayList(java.util.ArrayList) ModifierKind(spoon.reflect.declaration.ModifierKind) CtExtendedModifier(spoon.support.reflect.CtExtendedModifier)

Example 4 with CtExtendedModifier

use of spoon.support.reflect.CtExtendedModifier in project spoon by INRIA.

the class JDTTreeBuilder method visit.

@Override
public boolean visit(LocalDeclaration localDeclaration, BlockScope scope) {
    CtLocalVariable<Object> v = factory.Core().createLocalVariable();
    v.setSimpleName(CharOperation.charToString(localDeclaration.name));
    if (localDeclaration.binding != null) {
        v.setExtendedModifiers(getModifiers(localDeclaration.binding.modifiers, true, false));
    }
    for (CtExtendedModifier extendedModifier : getModifiers(localDeclaration.modifiers, false, false)) {
        // avoid to keep implicit AND explicit modifier of the same kind.
        v.addModifier(extendedModifier.getKind());
    }
    context.enter(v, localDeclaration);
    return true;
}
Also used : CtExtendedModifier(spoon.support.reflect.CtExtendedModifier)

Example 5 with CtExtendedModifier

use of spoon.support.reflect.CtExtendedModifier in project spoon by INRIA.

the class JDTTreeBuilder method visit.

@Override
public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
    CtMethod<Object> m = factory.Core().createMethod();
    m.setSimpleName(CharOperation.charToString(methodDeclaration.selector));
    if (methodDeclaration.binding != null) {
        m.setExtendedModifiers(getModifiers(methodDeclaration.binding.modifiers, true, true));
    }
    for (CtExtendedModifier extendedModifier : getModifiers(methodDeclaration.modifiers, false, true)) {
        // avoid to keep implicit AND explicit modifier of the same kind.
        m.addModifier(extendedModifier.getKind());
    }
    m.setDefaultMethod(methodDeclaration.isDefaultMethod());
    context.enter(m, methodDeclaration);
    // Create block
    if (!methodDeclaration.isAbstract() && (methodDeclaration.modifiers & ClassFileConstants.AccNative) == 0) {
        context.enter(getFactory().Core().createBlock(), methodDeclaration);
        context.exit(methodDeclaration);
    }
    // We consider the receiver as a standard argument (i.e. as a parameter)
    Receiver receiver = methodDeclaration.receiver;
    if (receiver != null) {
        receiver.traverse(this, methodDeclaration.scope);
    }
    return true;
}
Also used : Receiver(org.eclipse.jdt.internal.compiler.ast.Receiver) CtExtendedModifier(spoon.support.reflect.CtExtendedModifier)

Aggregations

CtExtendedModifier (spoon.support.reflect.CtExtendedModifier)9 Test (org.junit.Test)2 Launcher (spoon.Launcher)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Argument (org.eclipse.jdt.internal.compiler.ast.Argument)1 CompilationUnitDeclaration (org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration)1 Receiver (org.eclipse.jdt.internal.compiler.ast.Receiver)1 UnionTypeReference (org.eclipse.jdt.internal.compiler.ast.UnionTypeReference)1 BaseTypeBinding (org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding)1 BinaryTypeBinding (org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding)1 LocalTypeBinding (org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding)1 MissingTypeBinding (org.eclipse.jdt.internal.compiler.lookup.MissingTypeBinding)1 ParameterizedTypeBinding (org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding)1 PolyTypeBinding (org.eclipse.jdt.internal.compiler.lookup.PolyTypeBinding)1 RawTypeBinding (org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding)1 SourceTypeBinding (org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding)1 TypeBinding (org.eclipse.jdt.internal.compiler.lookup.TypeBinding)1 CtCatch (spoon.reflect.code.CtCatch)1