Skip to content

Commit

Permalink
Handling of SYNTHETIC and BRIDGE modifiers was added.
Browse files Browse the repository at this point in the history
Issue: #212
Issue: #87

Signed-off-by: Alexander Fedorenchik <alexander.fedorenchik@gmail.com>
  • Loading branch information
alexfedorenchik authored and codecholeric committed Oct 20, 2019
1 parent 45a808b commit 571a26d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public enum JavaModifier {
@PublicAPI(usage = ACCESS)
SYNCHRONIZED(EnumSet.of(ApplicableType.METHOD), Opcodes.ACC_SYNCHRONIZED),
@PublicAPI(usage = ACCESS)
NATIVE(EnumSet.of(ApplicableType.METHOD), Opcodes.ACC_NATIVE);
NATIVE(EnumSet.of(ApplicableType.METHOD), Opcodes.ACC_NATIVE),
@PublicAPI(usage = ACCESS)
BRIDGE(EnumSet.of(ApplicableType.METHOD), Opcodes.ACC_BRIDGE),
@PublicAPI(usage = ACCESS)
SYNTHETIC(EnumSet.allOf(ApplicableType.class), Opcodes.ACC_SYNTHETIC);

private final Set<ApplicableType> applicableTo;
private final int asmAccessFlag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
import com.tngtech.archunit.core.importer.testexamples.simpleimport.InterfaceToImport;
import com.tngtech.archunit.core.importer.testexamples.simplenames.SimpleNameExamples;
import com.tngtech.archunit.core.importer.testexamples.specialtargets.ClassCallingSpecialTarget;
import com.tngtech.archunit.core.importer.testexamples.syntheticimport.ClassWithSynthetics;
import com.tngtech.archunit.testutil.LogTestRule;
import com.tngtech.archunit.testutil.OutsideOfClassPathRule;
import com.tngtech.java.junit.dataprovider.DataProvider;
Expand All @@ -194,11 +195,13 @@
import static com.tngtech.archunit.core.domain.JavaConstructor.CONSTRUCTOR_NAME;
import static com.tngtech.archunit.core.domain.JavaFieldAccess.AccessType.GET;
import static com.tngtech.archunit.core.domain.JavaFieldAccess.AccessType.SET;
import static com.tngtech.archunit.core.domain.JavaModifier.BRIDGE;
import static com.tngtech.archunit.core.domain.JavaModifier.FINAL;
import static com.tngtech.archunit.core.domain.JavaModifier.PRIVATE;
import static com.tngtech.archunit.core.domain.JavaModifier.PROTECTED;
import static com.tngtech.archunit.core.domain.JavaModifier.PUBLIC;
import static com.tngtech.archunit.core.domain.JavaModifier.STATIC;
import static com.tngtech.archunit.core.domain.JavaModifier.SYNTHETIC;
import static com.tngtech.archunit.core.domain.JavaModifier.TRANSIENT;
import static com.tngtech.archunit.core.domain.JavaModifier.VOLATILE;
import static com.tngtech.archunit.core.domain.JavaStaticInitializer.STATIC_INITIALIZER_NAME;
Expand Down Expand Up @@ -384,6 +387,20 @@ public void handles_static_modifier_of_nested_classes() throws Exception {
assertThat(classes.get(ClassWithNestedClass.StaticNestedInterface.class).getModifiers()).as("modifiers of ClassWithNestedClass.StaticNestedInterface").contains(STATIC);
}

@Test
public void handles_synthetic_modifiers() throws Exception {
JavaClasses classes = classesIn("testexamples/syntheticimport").classes;

assertThat(classes.get(ClassWithSynthetics.ClassWithSyntheticField.class).getFields().size()).isEqualTo(1);
assertThat(classes.get(ClassWithSynthetics.ClassWithSyntheticField.class).getFields().toArray(new JavaField[]{})[0].getModifiers()).as("modifiers of field in ClassWithSynthetics.ClassWithSyntheticField").contains(SYNTHETIC);

assertThat(classes.get(ClassWithSynthetics.ClassWithSyntheticMethod.class).getMethods().size()).isEqualTo(1);
assertThat(classes.get(ClassWithSynthetics.ClassWithSyntheticMethod.class).getMethods().toArray(new JavaMethod[]{})[0].getModifiers()).as("modifiers of method in ClassWithSynthetics.ClassWithSyntheticMethod").contains(SYNTHETIC);

assertThat(classes.get(ClassWithSynthetics.class).getMethod("compare", Object.class, Object.class).getModifiers()).as("modifiers of bridge method in ClassWithSynthetics").contains(BRIDGE);
assertThat(classes.get(ClassWithSynthetics.class).getMethod("compare", Object.class, Object.class).getModifiers()).as("modifiers of bridge method in ClassWithSynthetics").contains(SYNTHETIC);
}

@Test
public void imports_jdk_classes() {
JavaClasses classes = new ClassFileImporter().importClasses(File.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.tngtech.archunit.core.importer.testexamples.syntheticimport;

import java.util.Comparator;

public class ClassWithSynthetics implements Comparator<String> {
public class ClassWithSyntheticField {
}

public class ClassWithSyntheticMethod {
private String nestedField;
}

public String getNestedField() {
return new ClassWithSyntheticMethod().nestedField;
}

@Override
public int compare(String o1, String o2) {
return 0;
}
}

0 comments on commit 571a26d

Please sign in to comment.