lombok.val import now gets removed. Only adding lombok.val flags the compilation unit as changed.

This commit is contained in:
Roel Spilker committed 2010-11-29 22:43:44 +01:00
1 parent dd0fded2bf
commit b0072a17eb
13 files changed
+54 -44

No files matched your search

+4 -3
View File
@@ -1,5 +1,5 @@
/*
* Copyright © 2009-2010 Reinier Zwitserloot and Roel Spilker.
* Copyright © 2009-2010 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -39,6 +39,7 @@ import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Options;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
/**
@@ -197,8 +198,8 @@ public class JavacNode extends lombok.core.LombokNode<JavacAST, JavacNode, JCTre
}
public boolean shouldDeleteLombokAnnotations() {
DeleteLombokAnnotations dla = ast.getContext().get(DeleteLombokAnnotations.class);
return dla != null && dla.isDeleteLombokAnnotations();
Options options = ast.getContext().get(Options.optionsKey);
return options instanceof LombokOptions && ((LombokOptions)options).deleteLombokAnnotations;
}
/**
+6 -4
View File
@@ -1,5 +1,5 @@
/*
* Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
* Copyright © 2009-2010 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -25,6 +25,7 @@ import java.util.ArrayList;
import javax.annotation.processing.Messager;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
@@ -32,6 +33,7 @@ import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Options;
public class JavacTransformer {
private final HandlerLibrary handlers;
@@ -78,9 +80,9 @@ public class JavacTransformer {
}
}
TrackChangedAsts changes = context.get(TrackChangedAsts.class);
if (changes != null) for (JavacAST ast : asts) {
if (ast.isChanged()) changes.changed.add((JCCompilationUnit) ast.top().get());
Options options = context.get(Options.optionsKey);
if (options instanceof LombokOptions) for (JavacAST ast : asts) {
if (ast.isChanged()) ((LombokOptions)options).changed.add((JCCompilationUnit) ast.top().get());
}
}
@@ -1,5 +1,5 @@
/*
* Copyright © 2010 Reinier Zwitserloot and Roel Spilker.
* Copyright © 2010 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans.
*
* 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,15 +21,27 @@
*/
package lombok.javac;
/** Used as marker in javac's Context object when delombok is running to signal that all lombok annotations should be deleted as they are processed. */
public class DeleteLombokAnnotations {
private final boolean deleteLombokAnnotations;
import java.util.HashSet;
import java.util.Set;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Options;
public class LombokOptions extends Options {
public DeleteLombokAnnotations(boolean deleteLombokAnnotations) {
this.deleteLombokAnnotations = deleteLombokAnnotations;
public boolean deleteLombokAnnotations = true;
public final Set<JCCompilationUnit> changed = new HashSet<JCCompilationUnit>();
public static LombokOptions replaceWithDelombokOptions(Context context) {
Options options = Options.instance(context);
context.put(optionsKey, (Options)null);
LombokOptions result = new LombokOptions(context);
result.putAll(options);
return result;
}
public boolean isDeleteLombokAnnotations() {
return deleteLombokAnnotations;
private LombokOptions(Context context) {
super(context);
}
}
@@ -1,10 +0,0 @@
package lombok.javac;
import java.util.HashSet;
import java.util.Set;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
public class TrackChangedAsts {
public final Set<JCCompilationUnit> changed = new HashSet<JCCompilationUnit>();
}
+5 -11
View File
@@ -1,5 +1,5 @@
/*
* Copyright © 2009-2010 Reinier Zwitserloot and Roel Spilker.
* Copyright © 2009-2010 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -44,14 +44,12 @@ import java.util.Map;
import javax.tools.DiagnosticListener;
import javax.tools.JavaFileObject;
import lombok.javac.DeleteLombokAnnotations;
import lombok.javac.TrackChangedAsts;
import lombok.javac.LombokOptions;
import com.sun.tools.javac.main.JavaCompiler;
import com.sun.tools.javac.main.OptionName;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Options;
import com.zwitserloot.cmdreader.CmdReader;
import com.zwitserloot.cmdreader.Description;
import com.zwitserloot.cmdreader.Excludes;
@@ -70,7 +68,7 @@ public class Delombok {
}
public Delombok() {
context.put(DeleteLombokAnnotations.class, new DeleteLombokAnnotations(true));
// context.put(DeleteLombokAnnotations.class, new DeleteLombokAnnotations(true));
}
private PrintStream feedback = System.err;
@@ -349,7 +347,7 @@ public class Delombok {
}
public boolean delombok() throws IOException {
Options options = Options.instance(context);
LombokOptions options = LombokOptions.replaceWithDelombokOptions(context);
options.put(OptionName.ENCODING, charset.name());
if (classpath != null) options.put(OptionName.CLASSPATH, classpath);
if (sourcepath != null) options.put(OptionName.SOURCEPATH, sourcepath);
@@ -383,13 +381,9 @@ public class Delombok {
return false;
}
TrackChangedAsts tca = new TrackChangedAsts();
context.put(TrackChangedAsts.class, tca);
JavaCompiler delegate = compiler.processAnnotations(compiler.enterTrees(toJavacList(roots)));
for (JCCompilationUnit unit : roots) {
DelombokResult result = new DelombokResult(commentsMap.get(unit).comments.toList(), unit, force || tca.changed.contains(unit));
DelombokResult result = new DelombokResult(commentsMap.get(unit).comments.toList(), unit, force || options.changed.contains(unit));
if (verbose) feedback.printf("File: %s [%s]\n", unit.sourcefile.getName(), result.isChanged() ? "delomboked" : "unchanged");
Writer rawWriter;
if (presetWriter != null) rawWriter = presetWriter;
@@ -9,11 +9,11 @@ public class ValInFor {
final java.lang.String v = a;
}
}
/* public void enhancedFor() {
public void enhancedFor() {
java.util.List<String> list = java.util.Arrays.asList("Hello, World!");
for (val shouldBeString : list) {
for (final java.lang.String shouldBeString : list) {
System.out.println(shouldBeString.toLowerCase());
val shouldBeString2 = shouldBeString;
final java.lang.String shouldBeString2 = shouldBeString;
}
}*/
}
}
@@ -1,3 +1,5 @@
import lombok.val;
public class ValComplex {
private ValSimple field = new ValSimple();
private static final int CONSTANT = 20;
@@ -1,3 +1,5 @@
import lombok.val;
public class ValErrors {
public void unresolvableExpression() {
val c = d;
+4 -2
View File
@@ -1,3 +1,5 @@
import lombok.val;
public class ValInFor {
{
val x = 10;
@@ -10,11 +12,11 @@ public class ValInFor {
}
}
/* public void enhancedFor() {
public void enhancedFor() {
java.util.List<String> list = java.util.Arrays.asList("Hello, World!");
for (val shouldBeString : list) {
System.out.println(shouldBeString.toLowerCase());
val shouldBeString2 = shouldBeString;
}
}*/
}
}
@@ -1,3 +1,5 @@
import lombok.val;
public class ValLessSimple {
private short field2 = 5;
@@ -1,3 +1,5 @@
import lombok.val;
public class ValSimple {
private String field = "field";
private short field2 = 5;
@@ -1,4 +1,5 @@
import java.util.*;
import lombok.val;
public class ValWeirdTypes<Z> {
private final List<Z> fieldList;
@@ -1,2 +1,2 @@
3:21 ERROR Cannot use 'val' here because initializer expression does not have a representable type: Type cannot be resolved
7:21 ERROR 'val' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })
5:21 ERROR Cannot use 'val' here because initializer expression does not have a representable type: Type cannot be resolved
9:21 ERROR 'val' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })