aboutsummaryrefslogtreecommitdiff
path: root/test/core/src/lombok/RunTestsViaEclipse.java
diff options
context:
space:
mode:
authorPhilipp Eichhorn <peichhor@web.de>2011-06-05 22:14:50 +0200
committerPhilipp Eichhorn <peichhor@web.de>2011-06-05 22:14:50 +0200
commit476b198f168223f1e30a5a4fa97e27cc2b9ea008 (patch)
treea15ae5731bd49a74e0a8283619438ca93da6b5db /test/core/src/lombok/RunTestsViaEclipse.java
parent964b82124dd92e91652925a450ab9208e41df601 (diff)
downloadlombok-476b198f168223f1e30a5a4fa97e27cc2b9ea008.tar.gz
lombok-476b198f168223f1e30a5a4fa97e27cc2b9ea008.tar.bz2
lombok-476b198f168223f1e30a5a4fa97e27cc2b9ea008.zip
Allow "before" to be used as a source-package for eclipse tests (see LoggerSlf4jWithPackage).
Diffstat (limited to 'test/core/src/lombok/RunTestsViaEclipse.java')
-rw-r--r--test/core/src/lombok/RunTestsViaEclipse.java40
1 files changed, 26 insertions, 14 deletions
diff --git a/test/core/src/lombok/RunTestsViaEclipse.java b/test/core/src/lombok/RunTestsViaEclipse.java
index 03f205ba..82df9c91 100644
--- a/test/core/src/lombok/RunTestsViaEclipse.java
+++ b/test/core/src/lombok/RunTestsViaEclipse.java
@@ -66,29 +66,37 @@ public class RunTestsViaEclipse extends AbstractRunTests {
}
@Override public void transformCode(final StringBuilder messages, StringWriter result, File file) throws Throwable {
- String source = readFile(file);
- CompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), file.getName(), "UTF-8");
- IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems();
- IProblemFactory problemFactory = new DefaultProblemFactory(Locale.ENGLISH);
- INameEnvironment nameEnvironment = new LombokTestNameEnvironment();
- ICompilerRequestor compilerRequestor = new LombokTestCompilerRequestor();
- CompilerOptions options = ecjCompilerOptions();
+ // setup parser and compiler
+ final IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems();
+ final IProblemFactory problemFactory = new DefaultProblemFactory(Locale.ENGLISH);
+ final INameEnvironment nameEnvironment = new LombokTestNameEnvironment();
+ final ICompilerRequestor compilerRequestor = new LombokTestCompilerRequestor();
+ final ISourceElementRequestor sourceElementRequestor = new LombokTestSourceElementRequestor();
+ final CompilerOptions options = ecjCompilerOptions();
+ final LombokTestCompiler jdtCompiler = new LombokTestCompiler(nameEnvironment, policy, options, compilerRequestor, problemFactory);
+ final SourceElementParser parser = new SourceElementParser(sourceElementRequestor, problemFactory, options, true, true);
+ // read the file
+ final String source = readFile(file);
+ final CompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), file.getName(), "UTF-8");
- ISourceElementRequestor sourceElementRequestor = new LombokTestSourceElementRequestor();
- SourceElementParser parser = new SourceElementParser(sourceElementRequestor, problemFactory, options, true, true);
- final CompilationUnitDeclaration cud = parser.parseCompilationUnit(sourceUnit, true, null);
- final LombokTestCompiler jdtCompiler = new LombokTestCompiler(nameEnvironment, policy, options, compilerRequestor, problemFactory);
+ // parse
+ final CompilationUnitDeclaration cud = parser.parseCompilationUnit(sourceUnit, true, null);
+ // build
jdtCompiler.lookupEnvironment.buildTypeBindings(cud, null);
jdtCompiler.lookupEnvironment.completeTypeBindings(cud, true);
+ // process
+ if (cud.scope != null) cud.scope.verifyMethods(jdtCompiler.lookupEnvironment.methodVerifier());
- CategorizedProblem[] problems = cud.compilationResult.getAllProblems();
+ // handle problems
+ final CategorizedProblem[] problems = cud.compilationResult.getAllProblems();
if (problems != null) for (CategorizedProblem p : problems) {
messages.append(String.format("%d %s %s\n", p.getSourceLineNumber(), p.isError() ? "error" : p.isWarning() ? "warning" : "unknown", p.getMessage()));
}
+ // set transformed code
result.append(cud.toString());
}
@@ -217,6 +225,10 @@ public class RunTestsViaEclipse extends AbstractRunTests {
private static class LombokTestNameEnvironment implements INameEnvironment {
Map<String, Boolean> packagesCache = new HashMap<String, Boolean>();
+ public LombokTestNameEnvironment() {
+ packagesCache.put("before", true);
+ }
+
public NameEnvironmentAnswer findType(final char[][] compoundTypeName) {
final StringBuffer result = new StringBuffer();
for (int i = 0; i < compoundTypeName.length; i++) {
@@ -289,8 +301,8 @@ public class RunTestsViaEclipse extends AbstractRunTests {
if (packagesCache.containsKey(name)) {
return packagesCache.get(name).booleanValue();
}
- byte[] bytes = getClassDefinition(name);
- if (bytes != null) {
+
+ if (name.startsWith("before") || (getClassDefinition(name) != null)) {
packagesCache.put(name, false);
return false;
}