Skip to content

Commit

Permalink
add first implementations of some annotation processing
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenartur committed Oct 15, 2024
1 parent 8f25476 commit 344fa98
Show file tree
Hide file tree
Showing 50 changed files with 1,993 additions and 26 deletions.
18 changes: 18 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<module>sandbox_jface_cleanup</module>
<module>sandbox_jface_cleanup_feature</module>
<module>sandbox_jface_cleanup_test</module>
<module>sandbox_junit_cleanup</module>
<module>sandbox_junit_cleanup_feature</module>
<module>sandbox_junit_cleanup_test</module>
<module>sandbox_usage_view</module>
<module>sandbox_usage_view_feature</module>
<module>sandbox_product</module>
Expand Down Expand Up @@ -322,6 +325,21 @@
<artifactId>sandbox_jface_cleanup_test</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.sandbox</groupId>
<artifactId>sandbox_junit_cleanup</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.sandbox</groupId>
<artifactId>sandbox_junit_cleanup_feature</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.sandbox</groupId>
<artifactId>sandbox_junit_cleanup_test</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.sandbox</groupId>
<artifactId>sandbox_usage_view</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public class HelperVisitor<E extends HelperVisitorProvider<V, T, E>,V,T> {
*
*/
public static final String METHODNAME = "methodname"; //$NON-NLS-1$
/**
*
*/
public static final String ANNOTATIONNAME = "annotationname"; //$NON-NLS-1$

/**
*
Expand Down Expand Up @@ -637,6 +641,18 @@ public BiPredicate<? extends ASTNode, E> addMarkerAnnotation(BiPredicate<MarkerA
return predicatemap.put(VisitorEnum.MarkerAnnotation, bs);
}

/**
* @param name
* @param bs
* @return old BiPredicate assigned for nodetype
*/
public BiPredicate<? extends ASTNode, E> addMarkerAnnotation(String name, BiPredicate<MarkerAnnotation, E> bs) {
predicatedata.put(VisitorEnum.MarkerAnnotation, Map.ofEntries(
new AbstractMap.SimpleEntry<>(ANNOTATIONNAME, name)
));
return predicatemap.put(VisitorEnum.MarkerAnnotation, bs);
}

/**
*
* @param bs
Expand Down Expand Up @@ -765,6 +781,17 @@ public BiPredicate<? extends ASTNode, E> addNormalAnnotation(BiPredicate<NormalA
return predicatemap.put(VisitorEnum.NormalAnnotation, bs);
}

/**
* @param name
* @param bs
* @return
*/
public BiPredicate<? extends ASTNode, E> addNormalAnnotation(String name, BiPredicate<NormalAnnotation, E> bs) {
predicatedata.put(VisitorEnum.NormalAnnotation, Map.ofEntries(
new AbstractMap.SimpleEntry<>(ANNOTATIONNAME, name)
));
return predicatemap.put(VisitorEnum.NormalAnnotation, bs);
}
/**
*
* @param bs
Expand Down Expand Up @@ -945,7 +972,19 @@ public BiPredicate<? extends ASTNode, E> addSimpleType(BiPredicate<SimpleType, E
public BiPredicate<? extends ASTNode, E> addSingleMemberAnnotation(BiPredicate<SingleMemberAnnotation, E> bs) {
return predicatemap.put(VisitorEnum.SingleMemberAnnotation, bs);
}


/**
* @param name
* @param bs
* @return old BiPredicate assigned for nodetype
*/
public BiPredicate<? extends ASTNode, E> addSingleMemberAnnotation(String name, BiPredicate<SingleMemberAnnotation, E> bs) {
predicatedata.put(VisitorEnum.SingleMemberAnnotation, Map.ofEntries(
new AbstractMap.SimpleEntry<>(ANNOTATIONNAME, name)
));
return predicatemap.put(VisitorEnum.SingleMemberAnnotation, bs);
}

/**
*
* @param bs
Expand Down Expand Up @@ -4184,6 +4223,23 @@ public static <V, T> void callMarkerAnnotationVisitor(ASTNode node, ReferenceHol
hv.build(node);
}

/**
* @param <V>
* @param <T>
* @param name
* @param node
* @param dataholder
* @param nodesprocessed
* @param bs
*/
public static <V, T> void callMarkerAnnotationVisitor(String name, ASTNode node, ReferenceHolder<V, T> dataholder, Set<ASTNode> nodesprocessed,
BiPredicate<MarkerAnnotation, ReferenceHolder<V, T>> bs) {

HelperVisitor<ReferenceHolder<V, T>,V,T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
hv.addMarkerAnnotation(name, bs);
hv.build(node);
}

/**
*
* @param <V>
Expand Down Expand Up @@ -4407,6 +4463,23 @@ public static <V, T> void callNormalAnnotationVisitor(ASTNode node, ReferenceHol
hv.build(node);
}

/**
* @param <V>
* @param <T>
* @param name
* @param node
* @param dataholder
* @param nodesprocessed
* @param bs
*/
public static <V, T> void callNormalAnnotationVisitor(String name, ASTNode node, ReferenceHolder<V, T> dataholder, Set<ASTNode> nodesprocessed,
BiPredicate<NormalAnnotation, ReferenceHolder<V, T>> bs) {

HelperVisitor<ReferenceHolder<V, T>,V,T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
hv.addNormalAnnotation(name, bs);
hv.build(node);
}

/**
*
* @param <V>
Expand Down Expand Up @@ -4733,6 +4806,23 @@ public static <V, T> void callSingleMemberAnnotationVisitor(ASTNode node, Refere
hv.build(node);
}

/**
* @param <V>
* @param <T>
* @param name
* @param node
* @param dataholder
* @param nodesprocessed
* @param bs
*/
public static <V, T> void callSingleMemberAnnotationVisitor(String name, ASTNode node, ReferenceHolder<V, T> dataholder, Set<ASTNode> nodesprocessed,
BiPredicate<SingleMemberAnnotation, ReferenceHolder<V, T>> bs) {

HelperVisitor<ReferenceHolder<V, T>,V,T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
hv.addSingleMemberAnnotation(name, bs);
hv.build(node);
}

/**
*
* @param <V>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,21 @@ public boolean visit(LineComment node) {
@Override
public boolean visit(MarkerAnnotation node) {
if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.MarkerAnnotation)) {
return ((BiPredicate<MarkerAnnotation, E>) (this.helperVisitor.predicatemap.get(VisitorEnum.MarkerAnnotation)))
.test(node, this.helperVisitor.dataholder);
Map<String, Object> map=(Map<String, Object>) this.helperVisitor.getSupplierData().get(VisitorEnum.MarkerAnnotation);
if(map != null) {
String data=(String) map.get(HelperVisitor.ANNOTATIONNAME);
ITypeBinding binding = node.resolveTypeBinding();
String fullyQualifiedName;
if (binding != null) {
fullyQualifiedName = binding.getQualifiedName();
}else {
fullyQualifiedName = node.getTypeName().getFullyQualifiedName();
}
if ((data!= null) && !fullyQualifiedName.equals(data)) {
return true;
}
}
return ((BiPredicate<MarkerAnnotation, E>) (this.helperVisitor.predicatemap.get(VisitorEnum.MarkerAnnotation))).test(node, this.helperVisitor.dataholder);
}
return true;
}
Expand Down Expand Up @@ -577,8 +590,21 @@ public boolean visit(NameQualifiedType node) {
@Override
public boolean visit(NormalAnnotation node) {
if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.NormalAnnotation)) {
return ((BiPredicate<NormalAnnotation, E>) (this.helperVisitor.predicatemap.get(VisitorEnum.NormalAnnotation)))
.test(node, this.helperVisitor.dataholder);
Map<String, Object> map=(Map<String, Object>) this.helperVisitor.getSupplierData().get(VisitorEnum.NormalAnnotation);
if(map != null) {
String data=(String) map.get(HelperVisitor.ANNOTATIONNAME);
ITypeBinding binding = node.resolveTypeBinding();
String fullyQualifiedName;
if (binding != null) {
fullyQualifiedName = binding.getQualifiedName();
}else {
fullyQualifiedName = node.getTypeName().getFullyQualifiedName();
}
if ((data!= null) && !fullyQualifiedName.equals(data)) {
return true;
}
}
return ((BiPredicate<NormalAnnotation, E>) (this.helperVisitor.predicatemap.get(VisitorEnum.NormalAnnotation))).test(node, this.helperVisitor.dataholder);
}
return true;
}
Expand Down Expand Up @@ -757,8 +783,21 @@ public boolean visit(SimpleType node) {
@Override
public boolean visit(SingleMemberAnnotation node) {
if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.SingleMemberAnnotation)) {
return ((BiPredicate<SingleMemberAnnotation, E>) (this.helperVisitor.predicatemap
.get(VisitorEnum.SingleMemberAnnotation))).test(node, this.helperVisitor.dataholder);
Map<String, Object> map=(Map<String, Object>) this.helperVisitor.getSupplierData().get(VisitorEnum.SingleMemberAnnotation);
if(map != null) {
String data=(String) map.get(HelperVisitor.ANNOTATIONNAME);
ITypeBinding binding = node.resolveTypeBinding();
String fullyQualifiedName;
if (binding != null) {
fullyQualifiedName = binding.getQualifiedName();
}else {
fullyQualifiedName = node.getTypeName().getFullyQualifiedName();
}
if ((data!= null) && !fullyQualifiedName.equals(data)) {
return true;
}
}
return ((BiPredicate<SingleMemberAnnotation, E>) (this.helperVisitor.predicatemap.get(VisitorEnum.SingleMemberAnnotation))).test(node, this.helperVisitor.dataholder);

Check warning

Code scanning / PMD

Useless parentheses. Warning

Useless parentheses.
}
return true;
}
Expand Down Expand Up @@ -1378,6 +1417,20 @@ public void endVisit(LineComment node) {
@Override
public void endVisit(MarkerAnnotation node) {
if (this.helperVisitor.consumermap.containsKey(VisitorEnum.MarkerAnnotation)) {
Map<String, Object> map=(Map<String, Object>) this.helperVisitor.getConsumerData().get(VisitorEnum.MarkerAnnotation);
if(map != null) {
String data=(String) map.get(HelperVisitor.ANNOTATIONNAME);
ITypeBinding binding = node.resolveTypeBinding();
String fullyQualifiedName;
if (binding != null) {
fullyQualifiedName = binding.getQualifiedName();
}else {
fullyQualifiedName = node.getTypeName().getFullyQualifiedName();
}
if ((data!= null) && !fullyQualifiedName.equals(data)) {
return;
}
}
((BiConsumer<MarkerAnnotation, E>) (this.helperVisitor.consumermap.get(VisitorEnum.MarkerAnnotation))).accept(node,
this.helperVisitor.dataholder);
}
Expand Down Expand Up @@ -1476,6 +1529,20 @@ public void endVisit(NameQualifiedType node) {
@Override
public void endVisit(NormalAnnotation node) {
if (this.helperVisitor.consumermap.containsKey(VisitorEnum.NormalAnnotation)) {
Map<String, Object> map=(Map<String, Object>) this.helperVisitor.getConsumerData().get(VisitorEnum.NormalAnnotation);
if(map != null) {
String data=(String) map.get(HelperVisitor.ANNOTATIONNAME);
ITypeBinding binding = node.resolveTypeBinding();
String fullyQualifiedName;
if (binding != null) {
fullyQualifiedName = binding.getQualifiedName();
}else {
fullyQualifiedName = node.getTypeName().getFullyQualifiedName();
}
if ((data!= null) && !fullyQualifiedName.equals(data)) {
return;
}
}
((BiConsumer<NormalAnnotation, E>) (this.helperVisitor.consumermap.get(VisitorEnum.NormalAnnotation))).accept(node,
this.helperVisitor.dataholder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public class MYCleanUpConstants {
*
*/
public static final String XML_CLEANUP= "cleanup.xmlcleanup"; //$NON-NLS-1$
/**
*
*/
public static final String JUNIT_CLEANUP= "cleanup.junitcleanup"; //$NON-NLS-1$
/**
*
*/
Expand Down
9 changes: 9 additions & 0 deletions sandbox_jface_cleanup/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
21 changes: 21 additions & 0 deletions sandbox_junit_cleanup/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions sandbox_junit_cleanup/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
34 changes: 34 additions & 0 deletions sandbox_junit_cleanup/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>sandbox_junit_cleanup</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
26 changes: 26 additions & 0 deletions sandbox_junit_cleanup/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: junit_cleanup
Bundle-SymbolicName: sandbox_junit_cleanup;singleton:=true
Bundle-Version: 1.1.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.filebuffers,
org.eclipse.core.filesystem,
org.eclipse.core.resources,
org.eclipse.core.expressions,
org.eclipse.jdt.core,
org.eclipse.jdt.ui,
org.eclipse.ltk.core.refactoring,
org.eclipse.text,
org.eclipse.swt,
org.eclipse.jface,
org.eclipse.ui.workbench,
org.eclipse.jdt.core.manipulation,
sandbox_common
Bundle-ActivationPolicy: lazy
Eclipse-RegisterBuddy: org.eclipse.jdt.core.manipulation
Import-Package: org.sandbox.jdt.internal.common,
org.sandbox.jdt.internal.corext.fix2
Eclipse-BuddyPolicy: global
Automatic-Module-Name: sandbox.junit.cleanup
5 changes: 5 additions & 0 deletions sandbox_junit_cleanup/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src/
bin.includes = META-INF/,\
.,\
plugin.xml,\
build.properties
Loading

0 comments on commit 344fa98

Please sign in to comment.