Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
The container registry cleanup task is now completed and the registry can be used normally.
Open sidebar
vadere
vadere
Commits
14500c4c
Commit
14500c4c
authored
Apr 27, 2018
by
Stefan Schuhbaeck
Browse files
add annotation-processing module to vadere
parent
a2882279
Changes
4
Hide whitespace changes
Inline
Side-by-side
annotationprocessing/pom.xml
0 → 100644
View file @
14500c4c
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
vadere
</artifactId>
<groupId>
org.vadere
</groupId>
<version>
0.1-SNAPSHOT
</version>
<relativePath>
../pom.xml
</relativePath>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
annotation-processing
</artifactId>
<name>
Annotation Processing
</name>
<dependencies>
<dependency>
<groupId>
com.google.auto.service
</groupId>
<artifactId>
auto-service
</artifactId>
<version>
${auto-service.version}
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>
src
</sourceDirectory>
<testSourceDirectory>
tests
</testSourceDirectory>
<resources>
<resource>
<directory>
src
</directory>
<excludes>
<exclude>
**/*.java
</exclude>
</excludes>
</resource>
<resource>
<directory>
resources
</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>
testResources
</directory>
</testResource>
<testResource>
<directory>
tests
</directory>
<excludes>
<exclude>
**/*.java
</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
${maven-compiler.version}
</version>
<configuration>
<source>
${maven-compiler.source.version}
</source>
<target>
${maven-compiler.target.version}
</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
annotationprocessing/src/org/vadere/annotation/factories/processor/DataProcessorClass.java
0 → 100644
View file @
14500c4c
package
org.vadere.annotation.factories.processor
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Target
;
@Target
(
ElementType
.
TYPE
)
public
@interface
DataProcessorClass
{
String
name
();
String
label
()
default
""
;
String
description
()
default
""
;
}
annotationprocessing/src/org/vadere/annotation/factories/processor/DataProcessorFactoryProcessor.java
0 → 100644
View file @
14500c4c
package
org.vadere.annotation.factories.processor
;
import
com.google.auto.service.AutoService
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
javax.annotation.processing.AbstractProcessor
;
import
javax.annotation.processing.Processor
;
import
javax.annotation.processing.RoundEnvironment
;
import
javax.annotation.processing.SupportedAnnotationTypes
;
import
javax.annotation.processing.SupportedSourceVersion
;
import
javax.lang.model.SourceVersion
;
import
javax.lang.model.element.Element
;
import
javax.lang.model.element.ElementKind
;
import
javax.lang.model.element.Modifier
;
import
javax.lang.model.element.TypeElement
;
import
javax.tools.JavaFileObject
;
@SupportedAnnotationTypes
(
"org.vadere.annotation.factories.processor.*"
)
@SupportedSourceVersion
(
SourceVersion
.
RELEASE_8
)
@AutoService
(
Processor
.
class
)
public
class
DataProcessorFactoryProcessor
extends
AbstractProcessor
{
@Override
public
boolean
process
(
Set
<?
extends
TypeElement
>
annotations
,
RoundEnvironment
roundEnv
)
{
for
(
TypeElement
annotation
:
annotations
){
//only no abstract classes...
Set
<?
extends
Element
>
annotatedElements
=
roundEnv
.
getElementsAnnotatedWith
(
annotation
)
.
stream
()
.
filter
(
e
->
e
.
getKind
().
isClass
()
&&
!
e
.
getKind
().
equals
(
ElementKind
.
ENUM
)
&&
!
e
.
getModifiers
().
contains
(
Modifier
.
ABSTRACT
)
)
.
collect
(
Collectors
.
toSet
());
if
(
annotatedElements
.
isEmpty
())
continue
;
try
{
writeDataProcessorFactory
(
"org.vadere.simulator.projects.dataprocessing.processor.DataProcessorFactory3"
,
annotatedElements
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
true
;
}
private
void
writeDataProcessorFactory2
(
String
className
,
Set
<?
extends
Element
>
dataProcessors
)
throws
IOException
{
String
packageName
=
null
;
int
lastDot
=
className
.
lastIndexOf
(
'.'
);
if
(
lastDot
>
0
)
packageName
=
className
.
substring
(
0
,
lastDot
);
String
clazz
=
className
.
substring
(
lastDot
+
1
);
JavaFileObject
jFile
=
processingEnv
.
getFiler
().
createSourceFile
(
clazz
);
try
(
PrintWriter
out
=
new
PrintWriter
(
jFile
.
openWriter
())){
out
.
append
(
"package "
).
append
(
packageName
).
println
(
";"
);
out
.
println
();
out
.
append
(
"public class "
).
append
(
clazz
).
println
(
" {"
);
out
.
println
();
for
(
Element
element
:
dataProcessors
)
{
TypeElement
p
=
(
TypeElement
)
element
;
out
.
append
(
" public "
).
append
(
p
.
getSimpleName
())
.
append
(
" get"
).
append
(
p
.
getSimpleName
()).
append
(
"()"
).
println
(
"{"
);
out
.
append
(
" return new "
).
append
(
p
.
getSimpleName
()).
println
(
"();"
);
out
.
append
(
" }"
).
println
();
}
out
.
println
();
out
.
println
(
"}"
);
}
}
private
void
writeDataProcessorFactory
(
String
className
,
Set
<?
extends
Element
>
dataProcessors
)
throws
IOException
{
String
packageName
=
null
;
int
lastDot
=
className
.
lastIndexOf
(
'.'
);
if
(
lastDot
>
0
)
packageName
=
className
.
substring
(
0
,
lastDot
);
String
clazz
=
className
.
substring
(
lastDot
+
1
);
JavaFileObject
jFile
=
processingEnv
.
getFiler
().
createSourceFile
(
clazz
);
try
(
PrintWriter
out
=
new
PrintWriter
(
jFile
.
openWriter
()))
{
out
.
println
(
"package org.vadere.simulator.projects.dataprocessing.processor;"
);
out
.
println
();
out
.
println
(
"import org.vadere.simulator.projects.dataprocessing.datakey.DataKey;"
);
out
.
println
();
out
.
println
(
"import java.util.HashMap;"
);
out
.
println
(
"import java.util.LinkedList;"
);
out
.
println
(
"import java.util.List;"
);
out
.
println
(
"import java.util.Map;"
);
out
.
println
(
"import java.util.function.Supplier;"
);
out
.
println
(
"import java.util.stream.Collectors;"
);
out
.
println
(
"import java.util.stream.Stream;"
);
out
.
println
();
out
.
println
();
out
.
println
(
"public class DataProcessorFactory3 {"
);
out
.
println
();
out
.
println
(
" private static DataProcessorFactory3 instance;"
);
out
.
println
();
out
.
println
(
" //performant threadsafe Singletone. Only at creation time the synchronize block is used,"
);
out
.
println
(
" //after that the if statement will allways be false."
);
out
.
println
(
" public static DataProcessorFactory3 instance(){"
);
out
.
println
(
" if(instance == null){"
);
out
.
println
(
" synchronized (DataProcessorFactory3.class){"
);
out
.
println
(
" if(instance == null){"
);
out
.
println
(
" instance = new DataProcessorFactory3();"
);
out
.
println
(
" }"
);
out
.
println
(
" }"
);
out
.
println
(
" }"
);
out
.
println
(
" return instance;"
);
out
.
println
(
" }"
);
out
.
println
();
out
.
println
(
" private DataProcessorFactory3(){"
);
// todo
// instantiate HashMap<String, ProcessorObject> installedProcessors
// and put ProcessorObjects iside
out
.
println
(
" }"
);
out
.
println
();
out
.
println
(
" //instance"
);
out
.
println
();
out
.
println
(
" private HashMap<String, ProcessorObject> installedProcessors;"
);
out
.
println
();
out
.
println
(
" public DataProcessor<?, ?> getProcessor(String clazz){"
);
out
.
println
(
" installedProcessors = new HashMap<>();"
);
out
.
println
(
" if(installedProcessors.containsKey(clazz)){"
);
out
.
println
(
" return installedProcessors.get(clazz).supplier.get();"
);
out
.
println
(
" }else {"
);
out
.
println
(
" return null;"
);
out
.
println
(
" }"
);
out
.
println
(
" }"
);
out
.
println
();
out
.
println
(
" public List<String> getListOfProcessors(){"
);
out
.
println
(
" return new LinkedList<>(installedProcessors.keySet());"
);
out
.
println
(
" }"
);
out
.
println
();
out
.
println
(
" // return a map based on the key of installedProcessors and the corresponding labels."
);
out
.
println
(
" public Map<String, String> getLabels(){"
);
out
.
println
(
" return installedProcessors.entrySet().stream().collect("
);
out
.
println
(
" Collectors.toMap(entry-> entry.getKey(), entry -> entry.getValue().getLable(entry.getKey())));"
);
out
.
println
(
" }"
);
out
.
println
();
for
(
Element
element
:
dataProcessors
)
{
TypeElement
p
=
(
TypeElement
)
element
;
out
.
append
(
" public "
).
append
(
p
.
getSimpleName
())
.
append
(
" get"
).
append
(
p
.
getSimpleName
()).
append
(
"()"
).
println
(
"{"
);
out
.
append
(
" return new "
).
append
(
p
.
getSimpleName
()).
println
(
"();"
);
out
.
append
(
" }"
).
println
();
out
.
println
();
}
out
.
println
(
" private class ProcessorObject{"
);
out
.
println
(
" Supplier<DataProcessor<?, ?>> supplier;"
);
out
.
println
(
" String label;"
);
out
.
println
(
" String description;"
);
out
.
println
();
out
.
println
(
" public ProcessorObject(String label, Supplier<DataProcessor<?, ?>> supplier){"
);
out
.
println
(
" this(label, supplier, \"\");"
);
out
.
println
(
" }"
);
out
.
println
();
out
.
println
(
" public ProcessorObject(String label, Supplier<DataProcessor<?, ?>> supplier, String description){"
);
out
.
println
(
" this.label = label;"
);
out
.
println
(
" this.supplier = supplier;"
);
out
.
println
(
" this.description = description;"
);
out
.
println
(
" }"
);
out
.
println
();
out
.
println
(
" //return label or name if label is empty string."
);
out
.
println
(
" public String getLable(String name){"
);
out
.
println
(
" return label.equals(\"\") ? name : label;"
);
out
.
println
(
" }"
);
out
.
println
();
out
.
println
(
" }"
);
out
.
println
(
"}"
);
out
.
println
();
}
}
}
pom.xml
View file @
14500c4c
...
...
@@ -21,6 +21,7 @@
<module>
./VadereSimulator
</module>
<module>
./VadereState
</module>
<module>
./VadereUtils
</module>
<module>
./annotationprocessing
</module>
</modules>
<!-- global dependencies! -->
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment