diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lombok/eclipse/TransformEclipseAST.java | 36 | ||||
-rw-r--r-- | src/lombok/installer/EclipseLocation.java | 71 | ||||
-rw-r--r-- | src/lombok/installer/Installer.java | 4 |
3 files changed, 35 insertions, 76 deletions
diff --git a/src/lombok/eclipse/TransformEclipseAST.java b/src/lombok/eclipse/TransformEclipseAST.java index 691327b1..6eac4196 100644 --- a/src/lombok/eclipse/TransformEclipseAST.java +++ b/src/lombok/eclipse/TransformEclipseAST.java @@ -22,11 +22,9 @@ package lombok.eclipse; import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; import lombok.eclipse.EclipseAST.Node; +import lombok.patcher.Symbols; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.Annotation; @@ -77,24 +75,6 @@ public class TransformEclipseAST { handlers = l; } - private static final List<String> DONT_RUN_LIST = Collections.unmodifiableList(Arrays.asList( - "org.eclipse.jdt.internal.corext.util.CodeFormatterUtil." - )); - - - /** - * Returns 'true' if the stack trace indicates lombok definitely SHOULD run for this parse job, by checking the context, - * and returns 'false' if the stack trace indicates lombok should definitely NOT run. - * - * Returns null if it can't tell (you probably should default to running lombok if you don't know). - */ - private static Boolean analyzeStackTrace(StackTraceElement[] trace) { - for ( StackTraceElement e : trace ) - if ( e.toString().contains(DONT_RUN_LIST.get(0)) ) return false; - return null; - //potential speedup: if trace contains org.eclipse.swt.widgets. -> stop - nothing interesting ever follows that. I think. - } - public static void transform_swapped(CompilationUnitDeclaration ast, Parser parser) { transform(parser, ast); } @@ -111,29 +91,27 @@ public class TransformEclipseAST { * @param ast The AST node belonging to the compilation unit (java speak for a single source file). */ public static void transform(Parser parser, CompilationUnitDeclaration ast) { - if ( disableLombok ) return; + if (disableLombok) return; - Boolean parse = analyzeStackTrace(new Throwable().getStackTrace()); - - if ( parse != null && parse == false ) return; + if (Symbols.hasSymbol("lombok.disable")) return; try { EclipseAST existing = getCache(ast); - if ( existing == null ) { + if (existing == null) { existing = new EclipseAST(ast); setCache(ast, existing); } else existing.reparse(); new TransformEclipseAST(existing).go(); - } catch ( Throwable t ) { + } catch (Throwable t) { try { String message = "Lombok can't parse this source: " + t.toString(); EclipseAST.addProblemToCompilationResult(ast, false, message, 0, 0); t.printStackTrace(); - } catch ( Throwable t2 ) { + } catch (Throwable t2) { try { Eclipse.error(ast, "Can't create an error in the problems dialog while adding: " + t.toString(), t2); - } catch ( Throwable t3 ) { + } catch (Throwable t3) { //This seems risky to just silently turn off lombok, but if we get this far, something pretty //drastic went wrong. For example, the eclipse help system's JSP compiler will trigger a lombok call, //but due to class loader shenanigans we'll actually get here due to a cascade of diff --git a/src/lombok/installer/EclipseLocation.java b/src/lombok/installer/EclipseLocation.java index d6a2f4b7..2b7e021d 100644 --- a/src/lombok/installer/EclipseLocation.java +++ b/src/lombok/installer/EclipseLocation.java @@ -31,10 +31,8 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.jar.JarFile; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.zip.ZipEntry; import javax.swing.JFrame; import javax.swing.JOptionPane; @@ -205,12 +203,15 @@ final class EclipseLocation { null); } - File agentJar = new File(dir, "lombok.eclipse.agent.jar"); - if ( agentJar.exists() ) { - if ( !agentJar.delete() ) throw new UninstallException( - "Can't delete " + agentJar.getAbsolutePath() + - " - perhaps the installer does not have the access rights to do so.", - null); + /* legacy code - lombok at one point used to have a separate jar for the eclipse agent. + * Leave this code in to delete it for those upgrading from an old version. */ { + File agentJar = new File(dir, "lombok.eclipse.agent.jar"); + if ( agentJar.exists() ) { + if ( !agentJar.delete() ) throw new UninstallException( + "Can't delete " + agentJar.getAbsolutePath() + + " - perhaps the installer does not have the access rights to do so.", + null); + } } File iniFile = new File(dir, "eclipse.ini"); @@ -230,7 +231,9 @@ final class EclipseLocation { boolean first = true; for ( String elem : m.group(1).split(Pattern.quote(File.pathSeparator)) ) { if ( elem.toLowerCase().endsWith("lombok.jar") ) continue; - if ( elem.toLowerCase().endsWith("lombok.eclipse.agent.jar") ) continue; + /* legacy code -see previous comment that starts with 'legacy' */ { + if ( elem.toLowerCase().endsWith("lombok.eclipse.agent.jar") ) continue; + } if ( first ) first = false; else elemBuilder.append(File.pathSeparator); elemBuilder.append(elem); @@ -295,33 +298,11 @@ final class EclipseLocation { //is no less bad than aborting, and this situation should be rare to the point of non-existence. File lombokJar = new File(iniFile.getParentFile(), "lombok.jar"); - File agentJar = new File(iniFile.getParentFile(), "lombok.eclipse.agent.jar"); File ourJar = EclipseFinder.findOurJar(); byte[] b = new byte[524288]; boolean readSucceeded = false; try { - JarFile jar = new JarFile(ourJar); - - try { - ZipEntry entry = jar.getEntry("lombok.eclipse.agent.jar"); - InputStream in = jar.getInputStream(entry); - FileOutputStream out = new FileOutputStream(agentJar); - try { - while ( true ) { - int r = in.read(b); - if ( r == -1 ) break; - readSucceeded = true; - out.write(b, 0, r); - } - } finally { - out.close(); - } - } finally { - jar.close(); - - } - FileOutputStream out = new FileOutputStream(lombokJar); InputStream in = new FileInputStream(ourJar); try { @@ -336,13 +317,16 @@ final class EclipseLocation { } catch ( IOException e ) { try { lombokJar.delete(); - agentJar.delete(); } catch ( Throwable ignore ) {} if ( !readSucceeded ) throw new InstallException("I can't read my own jar file. I think you've found a bug in this installer! I suggest you restart it " + "and use the 'what do I do' link, to manually install lombok. And tell us about this. Thanks!", e); throw new InstallException("I can't write to your Eclipse directory, probably because this installer does not have the access rights.", e); } + /* legacy - delete lombok.eclipse.agent.jar if its there, which lombok no longer uses. */ { + new File(lombokJar.getParentFile(), "lombok.eclipse.agent.jar").delete(); + } + try { FileInputStream fis = new FileInputStream(iniFile); try { @@ -357,7 +341,9 @@ final class EclipseLocation { boolean first = true; for ( String elem : m.group(1).split(Pattern.quote(File.pathSeparator)) ) { if ( elem.toLowerCase().endsWith("lombok.jar") ) continue; - if ( elem.toLowerCase().endsWith("lombok.eclipse.agent.jar") ) continue; + /* legacy code -see previous comment that starts with 'legacy' */ { + if ( elem.toLowerCase().endsWith("lombok.eclipse.agent.jar") ) continue; + } if ( first ) first = false; else elemBuilder.append(File.pathSeparator); elemBuilder.append(elem); @@ -374,13 +360,11 @@ final class EclipseLocation { } String fullPathToLombok = fullPathRequired ? (lombokJar.getParentFile().getCanonicalPath() + File.separator) : ""; - String fullPathToAgent = fullPathRequired ? (agentJar.getParentFile().getCanonicalPath() + File.separator) : ""; newContents.append(String.format( - "-javaagent:%slombok.eclipse.agent.jar", fullPathToLombok)).append(OS_NEWLINE); + "-javaagent:%slombok.jar", fullPathToLombok)).append(OS_NEWLINE); newContents.append(String.format( - "-Xbootclasspath/a:%slombok.jar" + File.pathSeparator + "%slombok.eclipse.agent.jar", - fullPathToLombok, fullPathToAgent)).append(OS_NEWLINE); + "-Xbootclasspath/a:%slombok.jar", fullPathToLombok)).append(OS_NEWLINE); FileOutputStream fos = new FileOutputStream(iniFile); try { @@ -395,7 +379,6 @@ final class EclipseLocation { } finally { if ( !installSucceeded ) try { lombokJar.delete(); - agentJar.delete(); } catch ( Throwable ignore ) {} } } @@ -406,12 +389,12 @@ final class EclipseLocation { } for ( File dir : failedDirs ) { - //If we're updating the old installation might have worked by putting the lombok jars in a different place. - //We'll delete these old files. - try { - new File(dir, "lombok.jar").delete(); - new File(dir, "lombok.eclipse.agent.jar").delete(); - } catch ( Throwable ignore ) {} + /* Legacy code - lombok's installer used to install in other places. To keep the user's eclipse dir clean, we'll delete these. */ { + try { + new File(dir, "lombok.jar").delete(); + new File(dir, "lombok.eclipse.agent.jar").delete(); + } catch ( Throwable ignore ) {} + } } } } diff --git a/src/lombok/installer/Installer.java b/src/lombok/installer/Installer.java index 89ebfc37..695de4b7 100644 --- a/src/lombok/installer/Installer.java +++ b/src/lombok/installer/Installer.java @@ -810,10 +810,8 @@ public class Installer { private static final String HOW_I_WORK_EXPLANATION = "<html><ol>" + "<li>First, I copy myself (lombok.jar) to your Eclipse install directory.</li>" + - "<li>Then, I unpack lombok.eclipse.agent.jar like so:<br>" + - "<pre>jar xvf lombok.jar lombok.eclipse.agent.jar</pre></li>" + "<li>Then, I edit the eclipse.ini file to add the following two entries:<br>" + - "<pre>-Xbootclasspath/a:lombok.jar%1$slombok.eclipse.agent.jar<br>" + + "<pre>-Xbootclasspath/a:lombok.jar<br>" + "-javaagent:lombok.jar</pre></li></ol>" + "<br>" + "That's all there is to it. Note that on Mac OS X, eclipse.ini is hidden in<br>" + |