Skip to content

Commit

Permalink
Fix #95 - Compilation error in Eclipse: Unexpected type
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarneim committed Dec 8, 2014
1 parent 0374cb4 commit 155834d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ apply plugin: 'com.github.kt3k.coveralls'

group = 'net.karneim'
archivesBaseName = "pojobuilder"
version = '3.4.0-SNAPSHOT'
version = '3.3.2'
sourceCompatibility = 1.6

repositories.mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeKind;
import javax.tools.Diagnostic;
Expand Down Expand Up @@ -64,13 +65,11 @@ public SourceVersion getSupportedSourceVersion() {
}

private void initHelpers(ProcessingEnvironment env) {
this.javaModelAnalyzerUtil =
new JavaModelAnalyzerUtil(env.getElementUtils(), env.getTypeUtils());
this.javaModelAnalyzer =
new JavaModelAnalyzer(env.getElementUtils(), env.getTypeUtils(), javaModelAnalyzerUtil);
this.javaModelAnalyzerUtil = new JavaModelAnalyzerUtil(env.getElementUtils(), env.getTypeUtils());
this.javaModelAnalyzer = new JavaModelAnalyzer(env.getElementUtils(), env.getTypeUtils(), javaModelAnalyzerUtil);
this.inputFactory =
new InputFactory(env.getTypeUtils(), new DirectivesFactory(env.getElementUtils(),
env.getTypeUtils(), javaModelAnalyzerUtil));
new InputFactory(env.getTypeUtils(), new DirectivesFactory(env.getElementUtils(), env.getTypeUtils(),
javaModelAnalyzerUtil));
this.annotationHierarchyUtil = new AnnotationHierarchyUtil(env.getTypeUtils());
}

Expand Down Expand Up @@ -142,14 +141,13 @@ private void resetFailedElements() {
}

private void addElementsThatFailedInLastRound(List<Element> elementsToProcess) {
elementsToProcess.addAll(javaModelAnalyzerUtil.findAnnotatedElements(
getTypeElements(failedTypeNames), GeneratePojoBuilder.class));
elementsToProcess.addAll(javaModelAnalyzerUtil.findAnnotatedElements(getTypeElements(failedTypeNames),
GeneratePojoBuilder.class));
}

private void addFailedElement(Element elem, Exception ex) {
failedElementsMap.put(elem, ex);
failedTypeNames.add(javaModelAnalyzerUtil.getCompilationUnit(elem).getQualifiedName()
.toString());
failedTypeNames.add(javaModelAnalyzerUtil.getCompilationUnit(elem).getQualifiedName().toString());
}

private void showErrorsForFailedElements() {
Expand All @@ -158,13 +156,22 @@ private void showErrorsForFailedElements() {
}
}

private List<Element> getAnnotatedElements(RoundEnvironment aRoundEnv,
Set<TypeElement> triggeringAnnotations) {
private List<Element> getAnnotatedElements(RoundEnvironment aRoundEnv, Set<TypeElement> triggeringAnnotations) {
List<Element> elementsToProcess = new ArrayList<Element>();
for (TypeElement annoTypeEl : triggeringAnnotations) {
elementsToProcess.addAll(aRoundEnv.getElementsAnnotatedWith(annoTypeEl));
}
return elementsToProcess;
return removeAnnotationElements(elementsToProcess);
}

private List<Element> removeAnnotationElements(List<Element> elements) {
List<Element> result = new ArrayList<Element>();
for (Element el : elements) {
if (el.getKind() != ElementKind.ANNOTATION_TYPE) {
result.add(el);
}
}
return result;
}

private TypeElement getTypeElement(Class<?> cls) {
Expand All @@ -187,8 +194,7 @@ private void generateSources(Output output) throws IOException {
if (!hasAlreadyBeenCreated(getTypeName(output.getBuilderModel()))) {
generateBuilderImpl(output);
}
if (output.getManualBuilderModel() != null
&& !hasAlreadyBeenCreated(getTypeName(output.getManualBuilderModel()))
if (output.getManualBuilderModel() != null && !hasAlreadyBeenCreated(getTypeName(output.getManualBuilderModel()))
&& !typeExists(getTypeName(output.getManualBuilderModel()))) {
generateManualBuilder(output);
}
Expand All @@ -202,8 +208,7 @@ private void generateBuilderImpl(Output output) throws IOException {
BuilderM builderModel = output.getBuilderModel();
String qualifiedName = getTypeName(builderModel);
JavaFileObject jobj =
processingEnv.getFiler().createSourceFile(qualifiedName,
asArray(output.getInput().getOrginatingElements()));
processingEnv.getFiler().createSourceFile(qualifiedName, asArray(output.getInput().getOrginatingElements()));
Writer writer = jobj.openWriter();
JavaWriter javaWriter = new JavaWriter(writer);
BuilderSourceGenerator generator = new BuilderSourceGenerator(javaWriter);
Expand All @@ -229,8 +234,7 @@ private void generateManualBuilder(Output output) throws IOException {
ManualBuilderM manualBuilderModel = output.getManualBuilderModel();
String qualifiedName = getTypeName(manualBuilderModel);
JavaFileObject jobj =
processingEnv.getFiler().createSourceFile(qualifiedName,
asArray(output.getInput().getOrginatingElements()));
processingEnv.getFiler().createSourceFile(qualifiedName, asArray(output.getInput().getOrginatingElements()));
Writer writer = jobj.openWriter();
JavaWriter javaWriter = new JavaWriter(writer);
ManualBuilderSourceGenerator generator = new ManualBuilderSourceGenerator(javaWriter);
Expand Down Expand Up @@ -263,8 +267,7 @@ private void error(Exception ex, Element processedElement) {
error(invElemEx.getMessage(), elem);
} else {
String message =
String.format("PojoBuilder caught unexpected exception on element %s!%s",
processedElement, toString(ex));
String.format("PojoBuilder caught unexpected exception on element %s!%s", processedElement, toString(ex));
error(message, processedElement);
}
}
Expand Down

0 comments on commit 155834d

Please sign in to comment.