forked from projectlombok/lombok
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fixes projectlombok#3529] Set real field initializer source
Eclipse copies the field initializer source code if it is a constant. For generated nodes we have to read it from the ast node and not from the source file.
- Loading branch information
Showing
7 changed files
with
193 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
test/eclipse/resource/noerrors/fieldNameConstantsInAnnotation/Annotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package pkg; | ||
|
||
public @interface Annotation { | ||
String value(); | ||
} |
8 changes: 8 additions & 0 deletions
8
test/eclipse/resource/noerrors/fieldNameConstantsInAnnotation/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package pkg; | ||
|
||
import lombok.experimental.FieldNameConstants; | ||
|
||
@FieldNameConstants | ||
public class Constants { | ||
String test; | ||
} |
5 changes: 5 additions & 0 deletions
5
test/eclipse/resource/noerrors/fieldNameConstantsInAnnotation/Usage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package pkg; | ||
|
||
@Annotation(Constants.Fields.test) | ||
public class Usage { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package lombok.eclipse.compile; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.jdt.core.ICompilationUnit; | ||
import org.eclipse.jdt.core.IProblemRequestor; | ||
import org.eclipse.jdt.core.WorkingCopyOwner; | ||
import org.eclipse.jdt.core.compiler.IProblem; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import lombok.eclipse.EclipseRunner; | ||
import lombok.eclipse.SetupSingleFileTest; | ||
|
||
@RunWith(EclipseRunner.class) | ||
public class NoErrorsTest { | ||
|
||
@Rule | ||
public SetupSingleFileTest setup = new SetupSingleFileTest(); | ||
|
||
@Test | ||
public void fieldNameConstantsInAnnotation() throws Exception { | ||
ICompilationUnit cu = setup.getPackageFragment().getCompilationUnit("Usage.java"); | ||
|
||
final List<IProblem> problems = new ArrayList<IProblem>(); | ||
final IProblemRequestor requestor = new IProblemRequestor() { | ||
@Override | ||
public void acceptProblem(IProblem problem) { | ||
problems.add(problem); | ||
} | ||
|
||
@Override | ||
public void beginReporting() { | ||
problems.clear(); | ||
} | ||
|
||
@Override | ||
public void endReporting() { | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return true; | ||
} | ||
}; | ||
|
||
WorkingCopyOwner workingCopyOwner = new WorkingCopyOwner() { | ||
@Override | ||
public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) { | ||
return requestor; | ||
} | ||
}; | ||
|
||
ICompilationUnit workingCopy = cu.getWorkingCopy(workingCopyOwner, null); | ||
try { | ||
workingCopy.reconcile(ICompilationUnit.NO_AST, true, true, workingCopy.getOwner(), null); | ||
} finally { | ||
workingCopy.discardWorkingCopy(); | ||
} | ||
|
||
System.out.println(problems); | ||
assertTrue(problems.isEmpty()); | ||
} | ||
} |