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;
}
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;
}
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();
}
}
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;
}
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;
}
Aggregations