diff --git a/src/main/java/spoon/reflect/declaration/CtModifiable.java b/src/main/java/spoon/reflect/declaration/CtModifiable.java index 054c407dad3..f2fd43f1af1 100644 --- a/src/main/java/spoon/reflect/declaration/CtModifiable.java +++ b/src/main/java/spoon/reflect/declaration/CtModifiable.java @@ -117,4 +117,34 @@ public interface CtModifiable extends CtElement { */ @DerivedProperty boolean isAbstract(); + + /** + * Returns true if it contains a transient modifier (see {@link #hasModifier(ModifierKind)}) + */ + @DerivedProperty + boolean isTransient(); + + /** + * Returns true if it contains a volatile modifier (see {@link #hasModifier(ModifierKind)}) + */ + @DerivedProperty + boolean isVolatile(); + + /** + * Returns true if it contains a synchronized modifier (see {@link #hasModifier(ModifierKind)}) + */ + @DerivedProperty + boolean isSynchronized(); + + /** + * Returns true if it contains a native modifier (see {@link #hasModifier(ModifierKind)}) + */ + @DerivedProperty + boolean isNative(); + + /** + * Returns true if it contains a strictfp modifier (see {@link #hasModifier(ModifierKind)}) + */ + @DerivedProperty + boolean isStrictfp(); } diff --git a/src/main/java/spoon/support/reflect/CtModifierHandler.java b/src/main/java/spoon/support/reflect/CtModifierHandler.java index 79539912c5c..1e2e679a655 100644 --- a/src/main/java/spoon/support/reflect/CtModifierHandler.java +++ b/src/main/java/spoon/support/reflect/CtModifierHandler.java @@ -155,6 +155,26 @@ public boolean isFinal() { return getModifiers().contains(ModifierKind.FINAL); } + public boolean isTransient() { + return getModifiers().contains(ModifierKind.TRANSIENT); + } + + public boolean isVolatile() { + return getModifiers().contains(ModifierKind.VOLATILE); + } + + public boolean isSynchronized() { + return getModifiers().contains(ModifierKind.SYNCHRONIZED); + } + + public boolean isNative() { + return getModifiers().contains(ModifierKind.NATIVE); + } + + public boolean isStrictfp() { + return getModifiers().contains(ModifierKind.STRICTFP); + } + @Override public int hashCode() { return getModifiers().hashCode(); diff --git a/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java b/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java index d31edfe231a..210d943411f 100644 --- a/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java @@ -263,4 +263,29 @@ public boolean isStatic() { public boolean isAbstract() { return this.modifierHandler.isAbstract(); } + + @Override + public boolean isTransient() { + return this.modifierHandler.isTransient(); + } + + @Override + public boolean isVolatile() { + return this.modifierHandler.isVolatile(); + } + + @Override + public boolean isSynchronized() { + return this.modifierHandler.isSynchronized(); + } + + @Override + public boolean isNative() { + return this.modifierHandler.isNative(); + } + + @Override + public boolean isStrictfp() { + return this.modifierHandler.isStrictfp(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java b/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java index 435fbc83599..96612eae8e1 100644 --- a/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java @@ -240,4 +240,29 @@ public boolean isStatic() { public boolean isAbstract() { return this.modifierHandler.isAbstract(); } + + @Override + public boolean isTransient() { + return this.modifierHandler.isTransient(); + } + + @Override + public boolean isVolatile() { + return this.modifierHandler.isVolatile(); + } + + @Override + public boolean isSynchronized() { + return this.modifierHandler.isSynchronized(); + } + + @Override + public boolean isNative() { + return this.modifierHandler.isNative(); + } + + @Override + public boolean isStrictfp() { + return this.modifierHandler.isStrictfp(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java b/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java index 7915b4e5730..2dac721021c 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java @@ -208,4 +208,29 @@ public boolean isStatic() { public boolean isAbstract() { return this.modifierHandler.isAbstract(); } + + @Override + public boolean isTransient() { + return this.modifierHandler.isTransient(); + } + + @Override + public boolean isVolatile() { + return this.modifierHandler.isVolatile(); + } + + @Override + public boolean isSynchronized() { + return this.modifierHandler.isSynchronized(); + } + + @Override + public boolean isNative() { + return this.modifierHandler.isNative(); + } + + @Override + public boolean isStrictfp() { + return this.modifierHandler.isStrictfp(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java b/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java index e60c47c579a..a2f6b2f52ee 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java @@ -224,4 +224,29 @@ public boolean isStatic() { public boolean isAbstract() { return this.modifierHandler.isAbstract(); } + + @Override + public boolean isTransient() { + return this.modifierHandler.isTransient(); + } + + @Override + public boolean isVolatile() { + return this.modifierHandler.isVolatile(); + } + + @Override + public boolean isSynchronized() { + return this.modifierHandler.isSynchronized(); + } + + @Override + public boolean isNative() { + return this.modifierHandler.isNative(); + } + + @Override + public boolean isStrictfp() { + return this.modifierHandler.isStrictfp(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java b/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java index 67b4ae09d35..ce501202ec8 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java @@ -211,6 +211,31 @@ public boolean isAbstract() { return this.modifierHandler.isAbstract(); } + @Override + public boolean isTransient() { + return this.modifierHandler.isTransient(); + } + + @Override + public boolean isVolatile() { + return this.modifierHandler.isVolatile(); + } + + @Override + public boolean isSynchronized() { + return this.modifierHandler.isSynchronized(); + } + + @Override + public boolean isNative() { + return this.modifierHandler.isNative(); + } + + @Override + public boolean isStrictfp() { + return this.modifierHandler.isStrictfp(); + } + @Override public boolean isPartOfJointDeclaration() { if (this.getPosition() instanceof NoSourcePosition) { diff --git a/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java b/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java index a2f2085433d..820e365febd 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java @@ -263,6 +263,31 @@ public boolean isAbstract() { return this.modifierHandler.isAbstract(); } + @Override + public boolean isTransient() { + return this.modifierHandler.isTransient(); + } + + @Override + public boolean isVolatile() { + return this.modifierHandler.isVolatile(); + } + + @Override + public boolean isSynchronized() { + return this.modifierHandler.isSynchronized(); + } + + @Override + public boolean isNative() { + return this.modifierHandler.isNative(); + } + + @Override + public boolean isStrictfp() { + return this.modifierHandler.isStrictfp(); + } + @Override public CtMethod copyMethod() { return Refactoring.copyMethod(this); diff --git a/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java b/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java index 1cb0de48161..c8b057025be 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java @@ -224,4 +224,29 @@ public boolean isStatic() { public boolean isAbstract() { return this.modifierHandler.isAbstract(); } + + @Override + public boolean isTransient() { + return this.modifierHandler.isTransient(); + } + + @Override + public boolean isVolatile() { + return this.modifierHandler.isVolatile(); + } + + @Override + public boolean isSynchronized() { + return this.modifierHandler.isSynchronized(); + } + + @Override + public boolean isNative() { + return this.modifierHandler.isNative(); + } + + @Override + public boolean isStrictfp() { + return this.modifierHandler.isStrictfp(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java index ab507e8ebbc..32fb609f2cf 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java @@ -985,6 +985,31 @@ public boolean isAbstract() { return this.modifierHandler.isAbstract(); } + @Override + public boolean isTransient() { + return this.modifierHandler.isTransient(); + } + + @Override + public boolean isSynchronized() { + return this.modifierHandler.isSynchronized(); + } + + @Override + public boolean isNative() { + return this.modifierHandler.isNative(); + } + + @Override + public boolean isStrictfp() { + return this.modifierHandler.isStrictfp(); + } + + @Override + public boolean isVolatile() { + return this.modifierHandler.isVolatile(); + } + @Override public CtType copyType() { return Refactoring.copyType(this); diff --git a/src/test/java/spoon/test/modifiers/ModifiersTest.java b/src/test/java/spoon/test/modifiers/ModifiersTest.java index da22ffa52b2..5241c6ccf5f 100644 --- a/src/test/java/spoon/test/modifiers/ModifiersTest.java +++ b/src/test/java/spoon/test/modifiers/ModifiersTest.java @@ -115,25 +115,33 @@ public void testGetModifiersHelpers() { CtType abstractClass = spoon.getFactory().Type().get(AbstractClass.class); - checkCtModifiableHelpersAssertion(abstractClass, true, false, false, true, false, false); + checkCtModifiableHelpersAssertion(abstractClass, true, false, false, true, false, false, false, false, false, false, false); - assertEquals(4, abstractClass.getFields().size()); + assertEquals(6, abstractClass.getFields().size()); for (CtField field : abstractClass.getFields()) { switch (field.getSimpleName()) { case "privateField": - checkCtModifiableHelpersAssertion(field, false, false, true, false, false, false); + checkCtModifiableHelpersAssertion(field, false, false, true, false, false, false, false, false, false, false, false); break; case "protectedField": - checkCtModifiableHelpersAssertion(field, false, true, false, false, false, false); + checkCtModifiableHelpersAssertion(field, false, true, false, false, false, false, false, false, false, false, false); break; case "privateStaticField": - checkCtModifiableHelpersAssertion(field, false, false, true, false, false, true); + checkCtModifiableHelpersAssertion(field, false, false, true, false, false, true, false, false, false, false, false); break; case "publicFinalField": - checkCtModifiableHelpersAssertion(field, true, false, false, false, true, false); + checkCtModifiableHelpersAssertion(field, true, false, false, false, true, false, false, false, false, false, false); + break; + + case "transientField": + checkCtModifiableHelpersAssertion(field, false, false, false, false, false, false, true, false, false, false, false); + break; + + case "volatileField": + checkCtModifiableHelpersAssertion(field, false, false, false, false, false, false, false, true, false, false, false); break; default: @@ -141,24 +149,36 @@ public void testGetModifiersHelpers() { } } - assertEquals(4, abstractClass.getMethods().size()); + assertEquals(7, abstractClass.getMethods().size()); for (CtMethod method : abstractClass.getMethods()) { switch (method.getSimpleName()) { case "method": - checkCtModifiableHelpersAssertion(method, true, false, false, false, true, true); + checkCtModifiableHelpersAssertion(method, true, false, false, false, true, true, false, false, false, false, false); break; case "onlyStatic": - checkCtModifiableHelpersAssertion(method, true, false, false, false, false, true); + checkCtModifiableHelpersAssertion(method, true, false, false, false, false, true, false, false, false, false, false); break; case "otherMethod": - checkCtModifiableHelpersAssertion(method, false, true, false, true, false, false); + checkCtModifiableHelpersAssertion(method, false, true, false, true, false, false, false, false, false, false, false); break; case "anotherOne": - checkCtModifiableHelpersAssertion(method, false, false, false, true, false, false); + checkCtModifiableHelpersAssertion(method, false, false, false, true, false, false, false, false, false, false, false); + break; + + case "synchronizedMethod": + checkCtModifiableHelpersAssertion(method, false, true, false, false, false, false, false, false, true, false, false); + break; + + case "nativeMethod": + checkCtModifiableHelpersAssertion(method, false, true, false, false, false, false, false, false, false, true, false); + break; + + case "strictfpMethod": + checkCtModifiableHelpersAssertion(method, false, true, false, false, false, false, false, false, false, false, true); break; default: @@ -167,17 +187,17 @@ public void testGetModifiersHelpers() { } CtType concreteClass = spoon.getFactory().Type().get("spoon.test.modifiers.testclasses.ConcreteClass"); - checkCtModifiableHelpersAssertion(concreteClass, false, false, false, false, true, false); + checkCtModifiableHelpersAssertion(concreteClass, false, false, false, false, true, false, false, false, false, false, false); assertEquals(2, concreteClass.getFields().size()); for (CtField field : concreteClass.getFields()) { switch (field.getSimpleName()) { case "className": - checkCtModifiableHelpersAssertion(field, true, false, false, false, true, true); + checkCtModifiableHelpersAssertion(field, true, false, false, false, true, true, false, false, false, false, false); break; case "test": - checkCtModifiableHelpersAssertion(field, false, false, true, false, false, true); + checkCtModifiableHelpersAssertion(field, false, false, true, false, false, true, false, false, false, false, false); break; default: @@ -189,11 +209,11 @@ public void testGetModifiersHelpers() { for (CtMethod method : concreteClass.getMethods()) { switch (method.getSimpleName()) { case "otherMethod": - checkCtModifiableHelpersAssertion(method, false, true, false, false, false, false); + checkCtModifiableHelpersAssertion(method, false, true, false, false, false, false, false, false, false, false, false); break; case "anotherOne": - checkCtModifiableHelpersAssertion(method, false, false, false, false, true, false); + checkCtModifiableHelpersAssertion(method, false, false, false, false, true, false, false, false, false, false, false); break; default: @@ -202,22 +222,27 @@ public void testGetModifiersHelpers() { } } - private void checkCtModifiableHelpersAssertion(CtModifiable element, boolean isPublic, boolean isProtected, boolean isPrivate, boolean isAbstract, boolean isFinal, boolean isStatic) { + private void checkCtModifiableHelpersAssertion(CtModifiable element, boolean isPublic, boolean isProtected, boolean isPrivate, boolean isAbstract, boolean isFinal, boolean isStatic, boolean isTransient, boolean isVolatile, boolean isSynchronized, boolean isNative, boolean isStrictfp) { assertEquals("isPublic for "+element+" is wrong", isPublic, element.isPublic()); assertEquals("isProtected for "+element+" is wrong", isProtected, element.isProtected()); assertEquals("isPrivate for "+element+" is wrong", isPrivate, element.isPrivate()); assertEquals("isAbstract for "+element+" is wrong", isAbstract, element.isAbstract()); assertEquals("isFinal for "+element+" is wrong", isFinal, element.isFinal()); assertEquals("isStatic for "+element+" is wrong", isStatic, element.isStatic()); + assertEquals("isTransient for "+element+" is wrong", isTransient, element.isTransient()); + assertEquals("isVolatile for "+element+" is wrong", isVolatile, element.isVolatile()); + assertEquals("isSynchronized for "+element+" is wrong", isSynchronized, element.isSynchronized()); + assertEquals("isNative for "+element+" is wrong", isNative, element.isNative()); + assertEquals("isStrictfp for "+element+" is wrong", isStrictfp, element.isStrictfp()); } - + @Test public void testClearModifiersByEmptySet() throws Exception { //contract: it is possible to remove modifiers by setModifiers(emptySet) CtType ctClass = ModelUtils.buildClass(StaticMethod.class); assertTrue(ctClass.hasModifier(ModifierKind.PUBLIC)); assertEquals(1, ctClass.getModifiers().size()); - + ctClass.setModifiers(Collections.emptySet()); assertFalse(ctClass.hasModifier(ModifierKind.PUBLIC)); assertEquals(0, ctClass.getModifiers().size()); diff --git a/src/test/java/spoon/test/modifiers/testclasses/AbstractClass.java b/src/test/java/spoon/test/modifiers/testclasses/AbstractClass.java index 3b1dae69082..c0cfde01c8a 100644 --- a/src/test/java/spoon/test/modifiers/testclasses/AbstractClass.java +++ b/src/test/java/spoon/test/modifiers/testclasses/AbstractClass.java @@ -21,4 +21,18 @@ public static int onlyStatic() { protected abstract void otherMethod(); abstract int anotherOne(); + + transient int transientField; + + volatile int volatileField; + + protected synchronized int synchronizedMethod() { + return 42; + } + + protected native void nativeMethod(); + + protected strictfp int strictfpMethod() { + return 42; + } }