Skip to content

Commit

Permalink
cleanups and some refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
mtf90 committed Dec 26, 2023
1 parent 504ade1 commit 2fbca95
Show file tree
Hide file tree
Showing 34 changed files with 434 additions and 438 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ limitations under the License.
<property name="format" value="^\s*\*\s*@author" />
<property name="minimum" value="0" />
<property name="maximum" value="0" />
<property name="message" value="Do not use the @author tag directly. Accredit contributions either via the changelog or as &lt;contributor&gt;s in the pom.xml." />
<property name="message" value="Do not use the @author tag directly. Attribute contributions either via the changelog or as &lt;contributor&gt;s in the pom.xml." />
</module>

<module name="Header">
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
61 changes: 18 additions & 43 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,16 @@ limitations under the License.
<tidy-pom.version>1.2.0</tidy-pom.version>

<!-- dependency versions -->
<ap-commons.version>0.0.2</ap-commons.version>
<brics.version>1.12-4</brics.version>
<checkstyle.version>9.3</checkstyle.version>
<compile-testing.version>0.21.0</compile-testing.version>
<extra-enforcer-rules.version>1.7.0</extra-enforcer-rules.version>
<javapoet.version>1.13.0</javapoet.version>
<metainf-services.version>1.8</metainf-services.version>
<testng.version>7.5.1</testng.version>
<truth.version>1.1.3</truth.version>
</properties>

<dependencies>
<dependency>
<groupId>com.github.misberner.ap-commons</groupId>
<artifactId>ap-commons</artifactId>
<version>${ap-commons.version}</version>
</dependency>

<dependency>
<groupId>com.squareup</groupId>
<artifactId>javapoet</artifactId>
Expand All @@ -127,20 +120,20 @@ limitations under the License.
<version>${brics.version}</version>
</dependency>

<dependency>
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>
<version>${metainf-services.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.google.testing.compile</groupId>
<artifactId>compile-testing</artifactId>
<version>${compile-testing.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>${truth.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand Down Expand Up @@ -175,6 +168,12 @@ limitations under the License.
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<proc>none</proc>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<configuration>
Expand Down Expand Up @@ -279,9 +278,9 @@ limitations under the License.
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle-plugin.version}</version>
<configuration>
<configLocation>${project.resources[0].directory}/automatalib-learnlib-checkstyle.xml</configLocation>
<headerLocation>${project.resources[0].directory}/license-header-java.txt</headerLocation>
<suppressionsLocation>${project.resources[0].directory}/checkstyle-suppressions.xml</suppressionsLocation>
<configLocation>${project.basedir}/config/build-tools-checkstyle.xml</configLocation>
<headerLocation>${project.basedir}/config/license-header-java.txt</headerLocation>
<suppressionsLocation>${project.basedir}/config/checkstyle-suppressions.xml</suppressionsLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<linkXRef>false</linkXRef>
</configuration>
Expand All @@ -295,7 +294,7 @@ limitations under the License.
<printFailingErrors>true</printFailingErrors>
<linkXRef>false</linkXRef>
<rulesets>
<ruleset>${project.resources[0].directory}/pmd-ruleset.xml</ruleset>
<ruleset>${project.basedir}/config/pmd-ruleset.xml</ruleset>
</rulesets>
<excludeRoots>
<excludeRoot>target/generated-sources</excludeRoot>
Expand Down Expand Up @@ -511,29 +510,5 @@ limitations under the License.
</plugins>
</build>
</profile>
<profile>
<id>compile-testing-compatibility</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
@{argLine}
--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
10 changes: 4 additions & 6 deletions src/main/java/de/learnlib/tooling/annotation/Generated.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,16 @@
public @interface Generated {

/**
* The generator element MUST have the name of the code generator. The name is the fully qualified name of the code
* generator.
* The the fully qualified name of the code generator.
*
* @return The name of the code generator
* @return The the fully qualified name of the code generator
*/
String[] generator();

/**
* The source element MUST have the name of the source. The name is the fully qualified name of the annotated
* class.
* The fully qualified name of the annotated class.
*
* @return The name of the annotated class
* @return The fully qualified name of the annotated class
*/
String source();
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
*
* @return a mapping of specializations of parameter types for the refinement's constructor parameters
*/
Map[] parameterMapping() default {};
Mapping[] typeMapping() default {};

/**
* An array of additional interfaces the refinement should implement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
public @interface Generic {

/**
* A literal representation of a type parameter (e.g. defined in {@link GenerateRefinement#generics()}).
* A literal representation of a type parameter (e.g. defined in {@link GenerateRefinement#generics()}). A non-empty
* value has a higher precedence over any {@link #clazz()} parameter.
*
* @return a literal representation of a type parameter
*/
Expand All @@ -40,7 +41,7 @@
Class<?> clazz() default Void.class;

/**
* Potential nested type parameters of the referenced (cf. {@link #clazz()}) referential type parameter.
* Potential nested type parameters of the referenced {@link #clazz() referential} type parameter.
*
* @return potential nested type parameters of the referenced referential type parameter
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
*
* @return potential nested type parameters of the referenced interface
*/
String[] generics() default {};
Generic[] generics() default {};

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
@Retention(RetentionPolicy.SOURCE)
@Target({})
public @interface Map {
public @interface Mapping {

/**
* The type of input parameter that if matched (equality) should be replaced.
Expand All @@ -40,19 +40,10 @@
Class<?> to();

/**
* Potential nested type parameters of the replacement (cf. {@link #to()}) type. If the replacement type has inner
* type variables use {@link #withComplexGenerics()}.
* Potential nested type parameters of the {@link #to() replacement} type.
*
* @return potential nested type parameters of the replacement type
*/
String[] withGenerics() default {};

/**
* Potential nested type parameters of the replacement (cf. {@link #to()}) type that may contain inner type
* variables themselves.
*
* @return potential nested type parameters of the replacement type
*/
Generic[] withComplexGenerics() default {};
Generic[] generics() default {};

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@
*/
package de.learnlib.tooling.processor;

import java.lang.annotation.Annotation;
import java.util.List;

import javax.annotation.processing.AbstractProcessor;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.tools.Diagnostic.Kind;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeElement;

import com.squareup.javapoet.AnnotationSpec;
import com.squareup.javapoet.ArrayTypeName;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterSpec;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeVariableName;
import de.learnlib.tooling.annotation.Generated;

public abstract class AbstractLearnLibProcessor extends AbstractProcessor {
Expand All @@ -29,15 +39,51 @@ public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}

public AnnotationSpec createAnnotation(Element annotatedClass) {
protected AnnotationSpec createAnnotation(Element annotatedClass) {
return AnnotationSpec.builder(Generated.class)
.addMember("generator", "$S", getClass().getCanonicalName())
.addMember("source", "$S", annotatedClass.toString())
.build();
}

public void error(String msg) {
super.processingEnv.getMessager().printMessage(Kind.ERROR, msg);
protected TypeElement validateClassKind(Element element, Class<? extends Annotation> annotation) {
if (element.getKind() != ElementKind.CLASS) {
throw new IllegalArgumentException("Annotation " + annotation + " is only supported on classes");
}

return (TypeElement) element;
}

protected String getPackageName(Element element, String defaultValue) {
if (defaultValue != null && !defaultValue.isEmpty()) {
return defaultValue;
} else {
return super.processingEnv.getElementUtils().getPackageOf(element).getQualifiedName().toString();
}
}

protected boolean requiresSafeVarargs(MethodSpec.Builder mBuilder) {
final List<ParameterSpec> parameters = mBuilder.parameters;

if (parameters.isEmpty()) {
return false;
} else {
final ParameterSpec last = parameters.get(parameters.size() - 1);
final TypeName type = last.type;

return requiresSafeVarargs(type);
}
}

private boolean requiresSafeVarargs(TypeName type) {
if (type instanceof ParameterizedTypeName) {
return true;
} else if (type instanceof TypeVariableName) {
return true;
} else if (type instanceof ArrayTypeName) {
return requiresSafeVarargs(((ArrayTypeName) type).componentType);
} else {
return false;
}
}
}
Loading

0 comments on commit 2fbca95

Please sign in to comment.