From 2b4b5c983540af4a4c08cfb7a3d4057df0b84c39 Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Wed, 29 Jul 2020 12:55:02 +0200 Subject: Support javadoc copying in eclipse --- test/core/src/lombok/RunTestsViaEcj.java | 43 ++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'test/core/src') diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index ab28cb0c..3a6e1702 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -36,16 +36,17 @@ import lombok.eclipse.Eclipse; import lombok.javac.CapturingDiagnosticListener.CompilerMessage; import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.CompilationResult; import org.eclipse.jdt.internal.compiler.Compiler; import org.eclipse.jdt.internal.compiler.ICompilerRequestor; import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; -import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; 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.CompilationUnit; public class RunTestsViaEcj extends AbstractRunTests { protected CompilerOptions ecjCompilerOptions() { @@ -103,7 +104,7 @@ public class RunTestsViaEcj extends AbstractRunTests { }; String source = readFile(file); - final CompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), file.getName(), encoding == null ? "UTF-8" : encoding); + final CompilationUnit sourceUnit = new TestCompilationUnit(file.getName(), source); Compiler ecjCompiler = new Compiler(createFileSystem(file, minVersion), ecjErrorHandlingPolicy(), ecjCompilerOptions(), bitbucketRequestor, new DefaultProblemFactory(Locale.ENGLISH)) { @Override protected synchronized void addCompilationUnit(ICompilationUnit inUnit, CompilationUnitDeclaration parsedUnit) { @@ -150,4 +151,42 @@ public class RunTestsViaEcj extends AbstractRunTests { } return new FileSystem(classpath.toArray(new String[0]), new String[] {file.getAbsolutePath()}, "UTF-8"); } + + private static final class TestCompilationUnit extends CompilationUnit { + private final char[] source; + private final char[] mainTypeName; + + private TestCompilationUnit(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; + } + } } -- cgit