|
16 | 16 | package com.googlecode.androidannotations; |
17 | 17 |
|
18 | 18 | import java.io.IOException; |
| 19 | +import java.io.PrintWriter; |
| 20 | +import java.io.StringWriter; |
19 | 21 | import java.util.Set; |
20 | 22 |
|
21 | 23 | import javax.annotation.processing.Messager; |
|
88 | 90 | import com.googlecode.androidannotations.processor.AnnotatedAbstractProcessor; |
89 | 91 | import com.googlecode.androidannotations.processor.SupportedAnnotationClasses; |
90 | 92 | import com.googlecode.androidannotations.rclass.AndroidRClassFinder; |
| 93 | +import com.googlecode.androidannotations.rclass.CompiledRClassFinder; |
91 | 94 | import com.googlecode.androidannotations.rclass.CoumpoundRClass; |
92 | 95 | import com.googlecode.androidannotations.rclass.IRClass; |
93 | | -import com.googlecode.androidannotations.rclass.CompiledRClassFinder; |
94 | 96 | import com.googlecode.androidannotations.rclass.RClassFinder; |
95 | 97 | import com.googlecode.androidannotations.validation.BeforeCreateValidator; |
96 | 98 | import com.googlecode.androidannotations.validation.ClickValidator; |
@@ -152,26 +154,28 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment |
152 | 154 | try { |
153 | 155 | processThrowing(annotations, roundEnv); |
154 | 156 | } catch (Exception e) { |
| 157 | + |
| 158 | + String errorMessage = "Unexpected error. Please report an issue on AndroidAnnotations, with the following content: " + stackTraceToString(e); |
| 159 | + messager.printMessage(Diagnostic.Kind.ERROR, errorMessage); |
155 | 160 |
|
156 | | - Throwable rootCause = e; |
157 | | - while (rootCause.getCause() != null) { |
158 | | - rootCause = rootCause.getCause(); |
159 | | - } |
160 | | - |
161 | | - StackTraceElement firstElement = e.getStackTrace()[0]; |
162 | | - StackTraceElement rootFirstElement = rootCause.getStackTrace()[0]; |
163 | | - String errorMessage = e.toString() + " " + firstElement.toString() + " root: " + rootCause.toString() + " " + rootFirstElement.toString(); |
164 | | - |
165 | | - messager.printMessage(Diagnostic.Kind.ERROR, "Unexpected annotation processing exception: " + errorMessage); |
166 | | - e.printStackTrace(); |
167 | | - |
| 161 | + /* |
| 162 | + * Printing exception as an error on a random element. The exception is not related to this element, but otherwise it wouldn't show up in eclipse. |
| 163 | + */ |
| 164 | + |
168 | 165 | Element element = roundEnv.getElementsAnnotatedWith(annotations.iterator().next()).iterator().next(); |
169 | | - messager.printMessage(Diagnostic.Kind.ERROR, "Unexpected annotation processing exception (not related to this element, but otherwise it wouldn't show up in eclipse) : " + errorMessage, element); |
| 166 | + messager.printMessage(Diagnostic.Kind.ERROR, errorMessage, element); |
170 | 167 | } |
171 | 168 |
|
172 | 169 | return false; |
173 | 170 | } |
174 | 171 |
|
| 172 | + private String stackTraceToString(Throwable e) { |
| 173 | + StringWriter writer = new StringWriter(); |
| 174 | + PrintWriter pw = new PrintWriter(writer); |
| 175 | + e.printStackTrace(pw); |
| 176 | + return writer.toString(); |
| 177 | + } |
| 178 | + |
175 | 179 | private void processThrowing(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws IOException { |
176 | 180 | AnnotationElementsHolder extractedModel = extractAnnotations(annotations, roundEnv); |
177 | 181 |
|
|
0 commit comments