Skip to content

Commit

Permalink
Merge branch 'lombok-support-module'
Browse files Browse the repository at this point in the history
  • Loading branch information
stoicflame committed Oct 6, 2016
2 parents 87cedd4 + 1f2a5e9 commit 43a3ca0
Show file tree
Hide file tree
Showing 73 changed files with 1,957 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*/
package com.webcohesion.enunciate;

import com.webcohesion.enunciate.javac.decorations.DecoratedProcessingEnvironment;
import com.webcohesion.enunciate.javac.decorations.DecoratedRoundEnvironment;
import com.webcohesion.enunciate.javac.decorations.ElementDecorator;
import com.webcohesion.enunciate.javac.decorations.*;
import com.webcohesion.enunciate.module.ContextModifyingModule;
import com.webcohesion.enunciate.module.EnunciateModule;
import org.jgrapht.DirectedGraph;
import org.jgrapht.graph.DefaultEdge;
Expand All @@ -28,10 +27,7 @@
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.*;

/**
* @author Ryan Heaton
Expand Down Expand Up @@ -59,12 +55,25 @@ public SourceVersion getSupportedSourceVersion() {
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);

//set up the processing environment.
ArrayList<ElementDecoration> elementDecorations = new ArrayList<ElementDecoration>();
ArrayList<TypeMirrorDecoration> typeMirrorDecorations = new ArrayList<TypeMirrorDecoration>();
ArrayList<AnnotationMirrorDecoration> annotationMirrorDecorations = new ArrayList<AnnotationMirrorDecoration>();
DecoratedProcessingEnvironment processingEnvironment = new DecoratedProcessingEnvironment(processingEnv, elementDecorations, typeMirrorDecorations, annotationMirrorDecorations);

//construct a context.
this.context = new EnunciateContext(new DecoratedProcessingEnvironment(processingEnv), this.enunciate.getLogger(), this.enunciate.getApiRegistry(), this.enunciate.getConfiguration(), this.enunciate.getIncludePatterns(), this.enunciate.getExcludePatterns());
this.context = new EnunciateContext(processingEnvironment, this.enunciate.getLogger(), this.enunciate.getApiRegistry(), this.enunciate.getConfiguration(), this.enunciate.getIncludePatterns(), this.enunciate.getExcludePatterns());

//initialize the modules.
for (EnunciateModule module : this.enunciate.getModules()) {
module.init(this.context);

if (module instanceof ContextModifyingModule) {
ContextModifyingModule contextModifier = (ContextModifyingModule) module;
elementDecorations.addAll(contextModifier.getElementDecorations());
typeMirrorDecorations.addAll(contextModifier.getTypeMirrorDecorations());
annotationMirrorDecorations.addAll(contextModifier.getAnnotationMirrorDecorations());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.webcohesion.enunciate.Enunciate;
import com.webcohesion.enunciate.EnunciateContext;
import com.webcohesion.enunciate.javac.decorations.element.ElementUtils;
import org.apache.commons.configuration.HierarchicalConfiguration;

import javax.lang.model.element.ElementKind;
Expand Down Expand Up @@ -94,11 +95,7 @@ protected String positionOf(javax.lang.model.element.Element element) {
}

//capitalize it.
return capitalize(position.toString());
}

protected String capitalize(String position) {
return Character.toUpperCase(position.charAt(0)) + position.substring(1);
return ElementUtils.capitalize(position.toString());
}

protected String descriptionOf(javax.lang.model.element.Element element) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package com.webcohesion.enunciate.module;

import com.webcohesion.enunciate.javac.decorations.AnnotationMirrorDecoration;
import com.webcohesion.enunciate.javac.decorations.ElementDecoration;
import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecoration;

import java.util.List;

/**
* Marker interface for designating a module as one that modifies the Enunciate context.
*
* @author Ryan Heaton
*/
public interface ContextModifyingModule extends EnunciateModule {

List<ElementDecoration> getElementDecorations();

List<TypeMirrorDecoration> getTypeMirrorDecorations();

List<AnnotationMirrorDecoration> getAnnotationMirrorDecorations();

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package com.webcohesion.enunciate.util;

import com.webcohesion.enunciate.javac.decorations.DecoratedProcessingEnvironment;
import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator;
import com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror;
import com.webcohesion.enunciate.metadata.rs.TypeHint;

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.MirroredTypeException;
Expand All @@ -34,7 +34,7 @@ public class TypeHintUtils {
private TypeHintUtils() {}


public static TypeMirror getTypeHint(TypeHint hintInfo, ProcessingEnvironment env, TypeMirror defaultValue) {
public static TypeMirror getTypeHint(TypeHint hintInfo, DecoratedProcessingEnvironment env, TypeMirror defaultValue) {
TypeMirror typeMirror;
try {
Class hint = hintInfo.value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ else if (webParam.getMode() != javax.jws.WebParam.Mode.IN) {
usesUnmappableElements = true;
}

if (capitalize(webMethod.getClientSimpleName()).equals(ei.getClientSimpleName())) {
if (ElementUtils.capitalize(webMethod.getClientSimpleName()).equals(ei.getClientSimpleName())) {
warn("%s: C# can't handle methods that are of the same name as their containing class. Either rename the method, or use the @org.codehaus.enunciate.ClientName annotation to rename the method (or type) on the client-side.", positionOf(webMethod));
usesUnmappableElements = true;
}
Expand All @@ -246,21 +246,21 @@ else if (webParam.getMode() != javax.jws.WebParam.Mode.IN) {
for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
for (TypeDefinition complexType : schemaInfo.getTypeDefinitions()) {
for (Attribute attribute : complexType.getAttributes()) {
if (capitalize(attribute.getClientSimpleName()).equals(complexType.getClientSimpleName())) {
if (ElementUtils.capitalize(attribute.getClientSimpleName()).equals(complexType.getClientSimpleName())) {
warn("%s: C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @com.webcohesion.enunciate.metadata.ClientName annotation to rename the property/field on the client-side.", positionOf(attribute));
usesUnmappableElements = true;
}
}

if (complexType.getValue() != null) {
if (capitalize(complexType.getValue().getClientSimpleName()).equals(complexType.getClientSimpleName())) {
if (ElementUtils.capitalize(complexType.getValue().getClientSimpleName()).equals(complexType.getClientSimpleName())) {
warn("%s: C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @com.webcohesion.enunciate.metadata.ClientName annotation to rename the property/field on the client-side.", positionOf(complexType.getValue()));
usesUnmappableElements = true;
}
}

for (Element element : complexType.getElements()) {
if (capitalize(element.getClientSimpleName()).equals(complexType.getClientSimpleName())) {
if (ElementUtils.capitalize(element.getClientSimpleName()).equals(complexType.getClientSimpleName())) {
warn("%s: C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @com.webcohesion.enunciate.metadata.ClientName annotation to rename the property/field on the client-side.", positionOf(element));
usesUnmappableElements = true;
}
Expand Down
40 changes: 40 additions & 0 deletions examples/jackson2-api-lombok/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>

<project name="example" basedir="." xmlns:mvn="urn:maven-artifact-ant">

<!--global references to other modules-->
<property name="lib.dir" value="${basedir}/../../lib"/>

<target name="clean">
<delete dir="target"/>
</target>

<target name="enunciate">
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant" loaderref="antlib.loader">
<classpath>
<fileset dir="${lib.dir}/build">
<include name="maven-ant-tasks-*.jar"/>
</fileset>
</classpath>
</typedef>

<mvn:pom id="current.pom" file="${basedir}/pom.xml"/>
<echo message="Current version is: ${current.pom.version}"/>

<mvn:dependencies pathId="enunciate.classpath">
<dependency groupId="com.webcohesion.enunciate" artifactId="enunciate-top" version="${current.pom.version}"/>
</mvn:dependencies>

<mvn:dependencies pathId="project.classpath" pomRefId="current.pom"/>

<taskdef name="enunciate" classname="com.webcohesion.enunciate.EnunciateTask">
<classpath refid="enunciate.classpath" />
</taskdef>

<enunciate basedir="${basedir}/src/main/java" configFile="${basedir}/enunciate.xml" buildDir="${basedir}/target/enunciate-via-ant">
<include name="**/*.java" />
<classpath refid="project.classpath" />
</enunciate>
</target>

</project>
96 changes: 96 additions & 0 deletions examples/jackson2-api-lombok/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-examples</artifactId>
<version>2.7.0-SNAPSHOT</version>
</parent>

<artifactId>enunciate-examples-jax-rs-jackson-lombok</artifactId>
<name>Enunciate - Jackson 2 API Lombok Example</name>
<description>Enunciate Example: Jackson 2 API Lombok</description>
<packaging>war</packaging>

<build>
<plugins>
<plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
<version>${enunciate.version}</version>
<executions>
<execution>
<id>assemble</id>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-lombok</artifactId>
<version>${enunciate.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<!--skip deploy (this is just a test module)-->
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

<reporting>
<plugins>
<plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
<version>${enunciate.version}</version>
</plugin>
</plugins>
</reporting>

<dependencies>
<dependency>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-core-annotations</artifactId>
<version>${enunciate.version}</version>
</dependency>

<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey1.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>${jackson2.version}</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>

<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright © 2006-2016 Web Cohesion ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.webcohesion.enunciate.examples.jaxrsjackson.genealogy.data;

/**
* An assertion of a piece of information, usually associated with a source.
*
* @author Ryan Heaton
*/
public abstract class Assertion {

private String id;
private String note;

/**
* The id of the assertion.
*
* @return The id of the assertion.
*/
public String getId() {
return id;
}

/**
* The id of the assertion.
*
* @param id The id of the assertion.
*/
public void setId(String id) {
this.id = id;
}

/**
* A note associated with this assertion.
*
* @return A note associated with this assertion.
*/
public String getNote() {
return note;
}

/**
* A note associated with this assertion.
*
* @param note A note associated with this assertion.
*/
public void setNote(String note) {
this.note = note;
}
}
Loading

0 comments on commit 43a3ca0

Please sign in to comment.