diff options
author | Roel Spilker <r.spilker@gmail.com> | 2017-01-19 21:53:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-19 21:53:17 +0100 |
commit | ac2bedb8f31c73a9b92793611c9199ba95f904af (patch) | |
tree | d6754f3fc0bae404bc0a3164a329315227a6e6a7 /src/eclipseAgent/lombok/launch/PatchFixesHider.java | |
parent | 20b5a1204a6763af32d332f53fc4445c8dc4a4f7 (diff) | |
parent | af3de95b277a5d106aa6a4d8feb03e48dc0af8d0 (diff) | |
download | lombok-ac2bedb8f31c73a9b92793611c9199ba95f904af.tar.gz lombok-ac2bedb8f31c73a9b92793611c9199ba95f904af.tar.bz2 lombok-ac2bedb8f31c73a9b92793611c9199ba95f904af.zip |
Merge pull request #1060 from rgra/Issue210
Patch for renaming fields with Getter/Setter/Data in eclipse #210
Diffstat (limited to 'src/eclipseAgent/lombok/launch/PatchFixesHider.java')
-rw-r--r-- | src/eclipseAgent/lombok/launch/PatchFixesHider.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/eclipseAgent/lombok/launch/PatchFixesHider.java b/src/eclipseAgent/lombok/launch/PatchFixesHider.java index fae06900..b1d73352 100644 --- a/src/eclipseAgent/lombok/launch/PatchFixesHider.java +++ b/src/eclipseAgent/lombok/launch/PatchFixesHider.java @@ -36,11 +36,13 @@ import lombok.eclipse.EclipseAugments; import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.IAnnotatable; import org.eclipse.jdt.core.IAnnotation; +import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.search.SearchMatch; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; @@ -55,9 +57,11 @@ import org.eclipse.jdt.internal.compiler.lookup.Scope; import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; import org.eclipse.jdt.internal.compiler.parser.Parser; import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; +import org.eclipse.jdt.internal.core.SourceField; import org.eclipse.jdt.internal.core.dom.rewrite.NodeRewriteEvent; import org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent; import org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner; +import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; /** These contain a mix of the following: @@ -565,6 +569,48 @@ final class PatchFixesHider { return result.size() == methods.length ? methods : result.toArray(new IMethod[result.size()]); } + public static SearchMatch[] removeGenerated(SearchMatch[] returnValue) { + List<SearchMatch> result = new ArrayList<SearchMatch>(); + for (int j = 0; j < returnValue.length; j++) { + SearchMatch searchResult = returnValue[j]; + if (searchResult.getElement() instanceof IField) { + IField field = (IField) searchResult.getElement(); + + // can not check for value=lombok because annotation is + // not fully resolved + IAnnotation annotation = field.getAnnotation("Generated"); + if (annotation != null) { + // Method generated at field location, skip + continue; + } + + } + result.add(searchResult); + } + return result.toArray(new SearchMatch[result.size()]); + } + + public static SearchResultGroup[] createFakeSearchResult(SearchResultGroup[] returnValue, + Object/* + * org.eclipse.jdt.internal.corext.refactoring.rename. + * RenameFieldProcessor + */ processor) throws Exception { + if (returnValue == null || returnValue.length == 0) { + // if no matches were found, check if Data annotation is present on the class + Field declaredField = processor.getClass().getDeclaredField("fField"); + if (declaredField != null) { + declaredField.setAccessible(true); + SourceField fField = (SourceField) declaredField.get(processor); + IAnnotation dataAnnotation = fField.getDeclaringType().getAnnotation("Data"); + if (dataAnnotation != null) { + // add fake item, to make refactoring checks pass + return new SearchResultGroup[] {new SearchResultGroup(null, new SearchMatch[1])}; + } + } + } + return returnValue; + } + public static SimpleName[] removeGeneratedSimpleNames(SimpleName[] in) throws Exception { Field f = SimpleName.class.getField("$isGenerated"); |