aboutsummaryrefslogtreecommitdiff
path: root/test/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/src')
-rw-r--r--test/core/src/lombok/AbstractRunTests.java7
-rw-r--r--test/core/src/lombok/DirectoryRunner.java13
-rw-r--r--test/core/src/lombok/LombokTestSource.java28
-rw-r--r--test/core/src/lombok/RunTestsViaDelombok.java157
-rw-r--r--test/core/src/lombok/RunTestsViaEcj.java191
5 files changed, 329 insertions, 67 deletions
diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java
index 448f77ab..51ec41c5 100644
--- a/test/core/src/lombok/AbstractRunTests.java
+++ b/test/core/src/lombok/AbstractRunTests.java
@@ -48,6 +48,7 @@ import lombok.core.configuration.ConfigurationResolver;
import lombok.core.configuration.ConfigurationResolverFactory;
import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
import lombok.transform.TestLombokFilesIdempotent;
+import lombok.transform.TestSourceFiles;
public abstract class AbstractRunTests {
private final File dumpActualFilesHere;
@@ -91,7 +92,9 @@ public abstract class AbstractRunTests {
}
});
- boolean changed = transformCode(messages, writer, file, sourceDirectives_.getSpecifiedEncoding(), sourceDirectives_.getFormatPreferences(), sourceDirectives_.minVersion());
+ boolean checkPositions = !(params instanceof TestLombokFilesIdempotent || params instanceof TestSourceFiles) && !sourceDirectives_.isSkipCompareContent();
+
+ boolean changed = transformCode(messages, writer, file, sourceDirectives_.getSpecifiedEncoding(), sourceDirectives_.getFormatPreferences(), sourceDirectives_.minVersion(), checkPositions);
boolean forceUnchanged = sourceDirectives_.forceUnchanged() || sourceDirectives_.isSkipCompareContent();
if (params.expectChanges() && !forceUnchanged && !changed) messages.add(new CompilerMessage(-1, -1, true, "not flagged modified"));
if (!params.expectChanges() && changed) messages.add(new CompilerMessage(-1, -1, true, "unexpected modification"));
@@ -101,7 +104,7 @@ public abstract class AbstractRunTests {
};
}
- protected abstract boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences, int minVersion) throws Throwable;
+ protected abstract boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences, int minVersion, boolean checkPositions) throws Throwable;
protected String readFile(File file) throws IOException {
BufferedReader reader;
diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java
index a174355d..b041c42e 100644
--- a/test/core/src/lombok/DirectoryRunner.java
+++ b/test/core/src/lombok/DirectoryRunner.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2020 The Project Lombok Authors.
+ * Copyright (C) 2009-2021 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -78,6 +78,9 @@ public class DirectoryRunner extends Runner {
}
public abstract boolean expectChanges();
+ public String testNamePrefix() {
+ return "";
+ }
}
private static final FileFilter JAVA_FILE_FILTER = new FileFilter() {
@@ -114,8 +117,7 @@ public class DirectoryRunner extends Runner {
Throwable error = null;
try {
addTests(testClass);
- }
- catch (Throwable t) {
+ } catch (Throwable t) {
error = t;
}
this.failure = error;
@@ -124,7 +126,7 @@ public class DirectoryRunner extends Runner {
private void addTests(Class<?> testClass) throws Exception {
for (File file : params.getBeforeDirectory().listFiles(JAVA_FILE_FILTER)) {
if (!params.accept(file)) continue;
- Description testDescription = Description.createTestDescription(testClass, file.getName());
+ Description testDescription = Description.createTestDescription(testClass, this.params.testNamePrefix() + file.getName());
description.addChild(testDescription);
tests.put(file.getName(), testDescription);
}
@@ -180,7 +182,8 @@ public class DirectoryRunner extends Runner {
case DELOMBOK:
return new RunTestsViaDelombok().createTester(params, file, "javac", params.getVersion());
case ECJ:
- return new RunTestsViaEcj().createTester(params, file, "ecj", params.getVersion());
+ String platform = RunTestsViaEcj.eclipseAvailable() ? "eclipse" : "ecj";
+ return new RunTestsViaEcj().createTester(params, file, platform, params.getVersion());
default:
case JAVAC:
throw new UnsupportedOperationException();
diff --git a/test/core/src/lombok/LombokTestSource.java b/test/core/src/lombok/LombokTestSource.java
index 57a32333..0326dee9 100644
--- a/test/core/src/lombok/LombokTestSource.java
+++ b/test/core/src/lombok/LombokTestSource.java
@@ -65,8 +65,20 @@ public class LombokTestSource {
public boolean runOnPlatform(String platform) {
if (platforms == null || platforms.isEmpty()) return true;
- for (String pl : platforms) if (pl.equalsIgnoreCase(platform)) return true;
- return false;
+ int inclusiveCount = 0;
+ for (String pl : platforms) {
+ if (pl.startsWith("!")) continue;
+ inclusiveCount++;
+ if (pl.equalsIgnoreCase(platform)) return true;
+ }
+ if (inclusiveCount == platforms.size()) {
+ return false;
+ }
+ for (String pl : platforms) {
+ if (!pl.startsWith("!")) continue;
+ if (pl.regionMatches(true, 1, platform, 0, platform.length())) return false;
+ }
+ return true;
}
public boolean versionWithinLimit(int version) {
@@ -113,10 +125,10 @@ public class LombokTestSource {
return formatPreferences;
}
- private static final Pattern VERSION_STYLE_1 = Pattern.compile("^(\\d+)$");
- private static final Pattern VERSION_STYLE_2 = Pattern.compile("^\\:(\\d+)$");
- private static final Pattern VERSION_STYLE_3 = Pattern.compile("^(\\d+):$");
- private static final Pattern VERSION_STYLE_4 = Pattern.compile("^(\\d+):(\\d+)$");
+ private static final Pattern VERSION_STYLE_1 = Pattern.compile("^(\\d+)(?:\\s+.*)?$");
+ private static final Pattern VERSION_STYLE_2 = Pattern.compile("^\\:(\\d+)(?:\\s+.*)?$");
+ private static final Pattern VERSION_STYLE_3 = Pattern.compile("^(\\d+):(?:\\s+.*)?$");
+ private static final Pattern VERSION_STYLE_4 = Pattern.compile("^(\\d+):(\\d+)(?:\\s+.*)?$");
private int[] parseVersionLimit(String spec) {
/* Single version: '5' */ {
@@ -362,4 +374,8 @@ public class LombokTestSource {
public int minVersion() {
return Math.max(6, versionLowerLimit);
}
+
+ public int maxVersion() {
+ return versionUpperLimit;
+ }
}
diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java
index ffac8372..13acdf55 100644
--- a/test/core/src/lombok/RunTestsViaDelombok.java
+++ b/test/core/src/lombok/RunTestsViaDelombok.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2014 The Project Lombok Authors.
+ * Copyright (C) 2009-2021 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -21,24 +21,53 @@
*/
package lombok;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
+import java.util.ArrayDeque;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Deque;
import java.util.Locale;
import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.RoundEnvironment;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.TypeElement;
+
+import com.sun.source.util.TreePath;
+import com.sun.source.util.Trees;
+import com.sun.tools.javac.code.Flags;
+import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.TreeScanner;
+import com.sun.tools.javac.tree.JCTree.JCAnnotation;
+import com.sun.tools.javac.tree.JCTree.JCAssign;
+import com.sun.tools.javac.tree.JCTree.JCClassDecl;
+import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
+import com.sun.tools.javac.tree.JCTree.JCIdent;
+import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
+import com.sun.tools.javac.tree.JCTree.JCModifiers;
+import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
+import com.sun.tools.javac.tree.JCTree.TypeBoundKind;
import lombok.delombok.Delombok;
import lombok.javac.CapturingDiagnosticListener;
+import lombok.javac.Javac;
import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
public class RunTestsViaDelombok extends AbstractRunTests {
private Delombok delombok = new Delombok();
@Override
- public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file, String encoding, Map<String, String> formatPreferences, int version) throws Throwable {
+ public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file, String encoding, Map<String, String> formatPreferences, int version, boolean checkPositions) throws Throwable {
delombok.setVerbose(true);
ChangedChecker cc = new ChangedChecker();
delombok.setFeedback(cc.feedback);
@@ -48,6 +77,8 @@ public class RunTestsViaDelombok extends AbstractRunTests {
delombok.setDiagnosticsListener(new CapturingDiagnosticListener(file, messages));
+ if (checkPositions) delombok.addAdditionalAnnotationProcessor(new ValidatePositionProcessor(version));
+
delombok.addFile(file.getAbsoluteFile().getParentFile(), file.getName());
delombok.setSourcepath(file.getAbsoluteFile().getParent());
String bcp = System.getProperty("delombok.bootclasspath");
@@ -63,6 +94,128 @@ public class RunTestsViaDelombok extends AbstractRunTests {
}
}
+ public static class ValidatePositionProcessor extends TreeProcessor {
+ private final int version;
+
+ public ValidatePositionProcessor(int version) {
+ this.version = version;
+ }
+
+ private String craftFailMsg(String problematicNode, Deque<JCTree> astContext) {
+ StringBuilder msg = new StringBuilder(problematicNode).append(" position of node not set: ");
+ for (JCTree t : astContext) {
+ msg.append("\n ").append(t.getClass().getSimpleName());
+ String asStr = t.toString();
+ if (asStr.length() < 80) msg.append(": ").append(asStr);
+ else if (t instanceof JCClassDecl) msg.append(": ").append(((JCClassDecl) t).name);
+ else if (t instanceof JCMethodDecl) msg.append(": ").append(((JCMethodDecl) t).name);
+ else if (t instanceof JCVariableDecl) msg.append(": ").append(((JCVariableDecl) t).name);
+ }
+ return msg.append("\n-------").toString();
+ }
+
+ @Override void processCompilationUnit(final JCCompilationUnit unit) {
+ final Deque<JCTree> astContext = new ArrayDeque<JCTree>();
+ unit.accept(new TreeScanner() {
+ @Override public void scan(JCTree tree) {
+ if (tree == null) return;
+ if (tree instanceof JCMethodDecl && (((JCMethodDecl) tree).mods.flags & Flags.GENERATEDCONSTR) != 0) return;
+ try {
+ if (tree instanceof JCModifiers) return;
+
+ if (!Javac.validateDocComment(unit, tree)) {
+ fail("Start position of doc comment (" + Javac.getDocComment(unit, tree) + ") of " + tree + " not set");
+ }
+
+ boolean check = true;
+ if (version < 8 && tree instanceof TypeBoundKind) {
+ // TypeBoundKind works differently in java6, and as a consequence,
+ // the position is not set properly.
+ // Given status of j6/j7, not worth properly testing.
+ check = false;
+ }
+ if (version < 8 && tree instanceof JCIdent) {
+ // explicit `super()` invocations do not appear to have end pos in j6/7.
+ if ("super".equals("" + ((JCIdent) tree).name)) check = false;
+ }
+
+ if (check && tree.pos == -1) fail(craftFailMsg("Start", astContext));
+ if (check && Javac.getEndPosition(tree, unit) == -1) {
+ fail(craftFailMsg("End", astContext));
+ }
+ } finally {
+ astContext.push(tree);
+ super.scan(tree);
+ astContext.pop();
+ }
+ }
+
+ @Override public void visitMethodDef(JCMethodDecl tree) {
+ super.visitMethodDef(tree);
+ }
+
+ @Override public void visitVarDef(JCVariableDecl tree) {
+ if ((tree.mods.flags & Flags.ENUM) != 0) return;
+ super.visitVarDef(tree);
+ }
+
+ @Override public void visitAnnotation(JCAnnotation tree) {
+ scan(tree.annotationType);
+ // Javac parser maps @Annotation("val") to @Annotation(value = "val") but does not add an end position for the new JCIdent...
+ if (tree.args.length() == 1 && tree.args.head instanceof JCAssign && ((JCIdent)((JCAssign) tree.args.head).lhs).name.toString().equals("value")) {
+ scan(((JCAssign) tree.args.head).rhs);
+ } else {
+ scan(tree.args);
+ }
+ }
+ });
+ }
+ }
+
+ public static abstract class TreeProcessor extends AbstractProcessor {
+ private Trees trees;
+ @Override public synchronized void init(ProcessingEnvironment processingEnv) {
+ super.init(processingEnv);
+ trees = Trees.instance(processingEnv);
+ }
+
+ @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ for (Element element : roundEnv.getRootElements()) {
+ JCCompilationUnit unit = toUnit(element);
+ if (unit != null) {
+ processCompilationUnit(unit);
+ }
+ }
+ return false;
+ }
+
+ abstract void processCompilationUnit(JCCompilationUnit unit);
+
+ @Override public Set<String> getSupportedAnnotationTypes() {
+ return Collections.singleton("*");
+ }
+
+ @Override public SourceVersion getSupportedSourceVersion() {
+ return SourceVersion.latest();
+ }
+
+ private JCCompilationUnit toUnit(Element element) {
+ TreePath path = null;
+ if (trees != null) {
+ try {
+ path = trees.getPath(element);
+ } catch (NullPointerException ignore) {
+ // Happens if a package-info.java dowsn't conatin a package declaration.
+ // https://github.com/rzwitserloot/lombok/issues/2184
+ // We can safely ignore those, since they do not need any processing
+ }
+ }
+ if (path == null) return null;
+
+ return (JCCompilationUnit) path.getCompilationUnit();
+ }
+ }
+
static class ChangedChecker {
private final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
private final PrintStream feedback;
diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java
index 7f4c2a0f..1c2be160 100644
--- a/test/core/src/lombok/RunTestsViaEcj.java
+++ b/test/core/src/lombok/RunTestsViaEcj.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010-2020 The Project Lombok Authors.
+ * Copyright (C) 2010-2021 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,26 +23,29 @@ package lombok;
import java.io.File;
import java.io.StringWriter;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
import lombok.eclipse.Eclipse;
import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
+import org.eclipse.core.internal.registry.ExtensionRegistry;
+import org.eclipse.core.internal.runtime.Activator;
+import org.eclipse.core.internal.runtime.PlatformActivator;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.RegistryFactory;
+import org.eclipse.core.runtime.adaptor.EclipseStarter;
+import org.eclipse.core.runtime.spi.IRegistryProvider;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
+import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.internal.compiler.CompilationResult;
@@ -54,6 +57,9 @@ import org.eclipse.jdt.internal.compiler.batch.FileSystem;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
+import org.eclipse.jdt.internal.core.JavaModelManager;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
public class RunTestsViaEcj extends AbstractRunTests {
protected CompilerOptions ecjCompilerOptions() {
@@ -77,6 +83,8 @@ public class RunTestsViaEcj extends AbstractRunTests {
warnings.put(CompilerOptions.OPTION_ReportUnusedLabel, "ignore");
warnings.put(CompilerOptions.OPTION_ReportUnusedImport, "ignore");
warnings.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, "ignore");
+ warnings.put(CompilerOptions.OPTION_ReportIndirectStaticAccess, "warning");
+ warnings.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, "warning");
warnings.put("org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures", "enabled");
warnings.put("org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures", "ignore");
int ecjVersion = Eclipse.getEcjCompilerVersion();
@@ -103,7 +111,7 @@ public class RunTestsViaEcj extends AbstractRunTests {
}
@Override
- public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences, int minVersion) throws Throwable {
+ public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences, int minVersion, boolean checkPositions) throws Throwable {
final AtomicReference<CompilationResult> compilationResult_ = new AtomicReference<CompilationResult>();
final AtomicReference<CompilationUnitDeclaration> compilationUnit_ = new AtomicReference<CompilationUnitDeclaration>();
ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() {
@@ -114,7 +122,17 @@ public class RunTestsViaEcj extends AbstractRunTests {
String source = readFile(file);
char[] sourceArray = source.toCharArray();
- final org.eclipse.jdt.internal.compiler.batch.CompilationUnit sourceUnit = new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(sourceArray, file.getName(), encoding == null ? "UTF-8" : encoding);
+ final ICompilationUnit sourceUnit;
+ try {
+ if (eclipseAvailable()) {
+ sourceUnit = new TestCompilationUnitEclipse(file.getName(), source);
+ } else {
+ sourceUnit = new TestCompilationUnitEcj(file.getName(), source);
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ return false;
+ }
Compiler ecjCompiler = new Compiler(createFileSystem(file, minVersion), ecjErrorHandlingPolicy(), ecjCompilerOptions(), bitbucketRequestor, new DefaultProblemFactory(Locale.ENGLISH)) {
@Override protected synchronized void addCompilationUnit(ICompilationUnit inUnit, CompilationUnitDeclaration parsedUnit) {
@@ -123,6 +141,8 @@ public class RunTestsViaEcj extends AbstractRunTests {
}
};
+ // initializeEclipseBundles();
+
ecjCompiler.compile(new ICompilationUnit[] {sourceUnit});
CompilationResult compilationResult = compilationResult_.get();
@@ -144,7 +164,37 @@ public class RunTestsViaEcj extends AbstractRunTests {
return true;
}
- private boolean eclipseAvailable() {
+ @SuppressWarnings("unused")
+ private static class EclipseInitializer {
+ static void initializeEclipseBundles() throws Exception {
+ // This code does not work yet, it's research-in-progress.
+ // The problem is that parts of the eclipse handler (in `PatchValEclipse` and friends) do not work unless
+ // an actual eclipse exists; PatchVal causes code to run that will end up running `ResourcesPlugin.getWorkspace()`, which
+ // goes down a rabbit hole of pinging off of various static fields (or `getX()` calls which return static fields), all
+ // of which are `null` until the plugin they belong to is properly initialized.
+ // This code is work in progress to 'hack' the initialization of each plugin one-by-one, but I doubt this is the right
+ // way to do it, as I bet it's fragile (will break when eclipse updates rather easily), and who knows how many fields
+ // and things need to be initialized.
+ // A better plan would be to start an actual, real eclipse, by telling `EclipseStarter.startup` to launch some sort of
+ // application (or at least a bunch of bundles/products/apps, including the JDT). This will then take long enough that
+ // it'll need to be cached and re-used for each test or the Eclipse test run would take far too long.
+
+ BundleContext context = EclipseStarter.startup(new String[0], null);
+ RegistryFactory.setDefaultRegistryProvider(new IRegistryProvider() {
+ private final ExtensionRegistry REG = new ExtensionRegistry(null, null, null);
+ @Override public IExtensionRegistry getRegistry() {
+ return REG;
+ }
+ });
+ new Activator().start(context);
+ new PlatformActivator().start(context);
+ for (Bundle b : context.getBundles()) System.out.println("BUNDLE: " + b.getSymbolicName());
+ new ResourcesPlugin().start(context);
+ JavaModelManager.getJavaModelManager().startup();
+ }
+ }
+
+ static boolean eclipseAvailable() {
try {
Class.forName("org.eclipse.jdt.core.dom.CompilationUnit");
} catch (Throwable t) {
@@ -161,48 +211,13 @@ public class RunTestsViaEcj extends AbstractRunTests {
Map<String, String> options = new HashMap<String, String>();
options.put(JavaCore.COMPILER_SOURCE, "11");
options.put("org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures", "enabled");
- try {
- org.eclipse.jdt.internal.core.CompilationUnit ccu = new org.eclipse.jdt.internal.core.CompilationUnit(null, null, null) {
- @Override public char[] getContents() {
- return source;
- }
- };
- return AST.convertCompilationUnit(4, cud, options, false, ccu, 0, null);
- } catch (SecurityException e) {
- try {
- debugClasspathConflicts("org/eclipse/jdt/internal/compiler");
- } catch (Exception e2) {
- throw Lombok.sneakyThrow(e2);
- }
- throw e;
- }
- }
- }
-
- @SuppressWarnings({"all"})
- private static void debugClasspathConflicts(String prefixToLookFor) throws Exception {
- String[] paths = System.getProperty("java.class.path").split(":");
- for (String p : paths) {
- Path cp = Paths.get(p);
- if (Files.isDirectory(cp)) {
- if (Files.isDirectory(cp.resolve(prefixToLookFor))) System.out.println("** DIR-BASED: " + cp);
- } else if (Files.isRegularFile(cp)) {
- JarFile jf = new JarFile(cp.toFile());
- try {
- Enumeration<JarEntry> jes = jf.entries();
- while (jes.hasMoreElements()) {
- JarEntry je = jes.nextElement();
- if (je.getName().startsWith(prefixToLookFor)) {
- System.out.println("** JAR-BASED: " + cp);
- break;
- }
- }
- } finally {
- jf.close();
+
+ org.eclipse.jdt.internal.core.CompilationUnit ccu = new org.eclipse.jdt.internal.core.CompilationUnit(null, null, null) {
+ @Override public char[] getContents() {
+ return source;
}
- } else {
- System.out.println("** MISSING: " + cp);
- }
+ };
+ return AST.convertCompilationUnit(4, cud, options, false, ccu, 0, null);
}
}
@@ -213,8 +228,9 @@ public class RunTestsViaEcj extends AbstractRunTests {
i.remove();
}
}
- if (new File("bin").exists()) classpath.add("bin");
+ if (new File("bin/main").exists()) classpath.add("bin/main");
classpath.add("dist/lombok.jar");
+ classpath.add("build/teststubs");
if (bootRuntimePath == null || bootRuntimePath.isEmpty()) throw new IllegalStateException("System property delombok.bootclasspath is not set; set it to the rt of java6 or java8");
classpath.add(bootRuntimePath);
for (File f : new File("lib/test").listFiles()) {
@@ -225,4 +241,75 @@ public class RunTestsViaEcj extends AbstractRunTests {
}
return new FileSystem(classpath.toArray(new String[0]), new String[] {file.getAbsolutePath()}, "UTF-8");
}
+
+ private static final class TestCompilationUnitEcj implements ICompilationUnit {
+ private final char[] name, source, mainTypeName;
+
+ TestCompilationUnitEcj(String name, String source) {
+ this.source = source.toCharArray();
+ this.name = name.toCharArray();
+
+ char[] fileNameCharArray = getFileName();
+ int start = CharOperation.lastIndexOf(File.separatorChar, fileNameCharArray) + 1;
+ int end = CharOperation.lastIndexOf('.', fileNameCharArray);
+ if (end == -1) {
+ end = fileNameCharArray.length;
+ }
+ mainTypeName = CharOperation.subarray(fileNameCharArray, start, end);
+ }
+
+ @Override public char[] getFileName() {
+ return name;
+ }
+
+ @Override public char[] getContents() {
+ return source;
+ }
+
+ @Override public char[] getMainTypeName() {
+ return mainTypeName;
+ }
+
+ @Override public char[][] getPackageName() {
+ return null;
+ }
+ }
+
+ private static final class TestCompilationUnitEclipse extends org.eclipse.jdt.internal.core.CompilationUnit {
+ private final char[] source;
+ private final char[] mainTypeName;
+
+ private TestCompilationUnitEclipse(String name, String source) {
+ super(null, name, null);
+ this.source = source.toCharArray();
+
+ char[] fileNameCharArray = getFileName();
+ int start = CharOperation.lastIndexOf(File.separatorChar, fileNameCharArray) + 1;
+ int end = CharOperation.lastIndexOf('.', fileNameCharArray);
+ if (end == -1) {
+ end = fileNameCharArray.length;
+ }
+ mainTypeName = CharOperation.subarray(fileNameCharArray, start, end);
+ }
+
+ @Override public char[] getContents() {
+ return source;
+ }
+
+ @Override public char[] getMainTypeName() {
+ return mainTypeName;
+ }
+
+ @Override public boolean ignoreOptionalProblems() {
+ return false;
+ }
+
+ @Override public char[][] getPackageName() {
+ return null;
+ }
+
+ @Override public char[] getModuleName() {
+ return null;
+ }
+ }
}