Author: dazarov
Date: 2009-10-01 08:33:57 -0400 (Thu, 01 Oct 2009)
New Revision: 17834
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreMessages.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/messages.properties
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRefactorSearcher.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameMethodParticipant.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/ELSearchQuery.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamELReferencesQueryParticipant.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4771
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreMessages.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreMessages.java 2009-10-01
12:33:10 UTC (rev 17833)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreMessages.java 2009-10-01
12:33:57 UTC (rev 17834)
@@ -50,4 +50,6 @@
public static String SEAM_RENAME_PROCESSOR_ERROR_READ_ONLY_FILE;
public static String SEAM_RENAME_PROCESSOR_LOCATION_NOT_FOUND;
public static String SEAM_RENAME_PROCESSOR_DECLARATION_NOT_FOUND;
+ public static String SEAM_RENAME_METHOD_PARTICIPANT_SETTER_WARNING;
+ public static String SEAM_RENAME_METHOD_PARTICIPANT_GETTER_WARNING;
}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/messages.properties
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/messages.properties 2009-10-01
12:33:10 UTC (rev 17833)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/messages.properties 2009-10-01
12:33:57 UTC (rev 17834)
@@ -38,4 +38,6 @@
SEAM_RENAME_PROCESSOR_LOCATION_NOT_FOUND=Location for declaration or annotation not found
in file: ''{0}''
SEAM_RENAME_PROCESSOR_DECLARATION_NOT_FOUND=Component: ''{0}'' does not
have any declarations
SEAM_RENAME_PROCESSOR_ERROR_PHANTOM_FILE=Cannot change phantom file:
''{0}''.
-SEAM_RENAME_PROCESSOR_ERROR_READ_ONLY_FILE=Cannot change read-only file:
''{0}''.
\ No newline at end of file
+SEAM_RENAME_PROCESSOR_ERROR_READ_ONLY_FILE=Cannot change read-only file:
''{0}''.
+SEAM_RENAME_METHOD_PARTICIPANT_SETTER_WARNING=Be sure, may be you also should rename
getter method to avoid compilation problems.
+SEAM_RENAME_METHOD_PARTICIPANT_GETTER_WARNING=Be sure, may be you also should rename
setter method to avoid compilation problems.
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRefactorSearcher.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRefactorSearcher.java 2009-10-01
12:33:10 UTC (rev 17833)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRefactorSearcher.java 2009-10-01
12:33:57 UTC (rev 17834)
@@ -23,6 +23,7 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.internal.ui.text.FastJavaPartitionScanner;
@@ -345,7 +346,7 @@
key = false;
if(key && token.startsWith(propertyName)){
- match(file, offset, token.length());
+ match(file, offset, token.length(), true);
}
}
@@ -373,13 +374,13 @@
protected abstract boolean isFileCorrect(IFile file);
- protected abstract void match(IFile file, int offset, int length);
+ protected abstract void match(IFile file, int offset, int length, boolean resolved);
private void checkMatch(IFile file, ELExpression operand, int leftOffset, int offset,
int length){
if(javaElement != null && operand != null)
resolve(file, operand, leftOffset, offset, length);
else
- match(file, offset, length);
+ match(file, offset, length, true);
}
public static String getPropertyName(String methodName){
@@ -396,9 +397,21 @@
return methodName;
}
- public static boolean isSetter(String methodName){
- return methodName.startsWith(SET);
+ // TODO: move to util class
+ public boolean isGetter(IMethod method) {
+ String name = method.getElementName();
+ int numberOfParameters = method.getNumberOfParameters();
+
+ return (((name.startsWith(GET) && !name.equals(GET)) || name.startsWith(IS))
&& numberOfParameters == 0);
}
+
+ // TODO: move to util class
+ public boolean isSetter(IMethod method) {
+ String name = method.getElementName();
+ int numberOfParameters = method.getNumberOfParameters();
+
+ return ((name.startsWith(SET) && !name.equals(SET)) &&
numberOfParameters == 1);
+ }
private boolean containsInSearchScope(IProject project){
if(searchScope == null)
@@ -447,8 +460,9 @@
.getProject()))
;
} else if (javaElement.equals(segmentJavaElement))
- match(file, offset, length);
+ match(file, offset, length, true);
}
}
+ match(file, offset, length, false);
}
}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameMethodParticipant.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameMethodParticipant.java 2009-10-01
12:33:10 UTC (rev 17833)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameMethodParticipant.java 2009-10-01
12:33:57 UTC (rev 17834)
@@ -43,13 +43,25 @@
private TextFileChange lastChange;
private ArrayList<String> keys = new ArrayList<String>();
+ private static boolean added = false;
+
@Override
public RefactoringStatus checkConditions(IProgressMonitor pm,
CheckConditionsContext context) throws OperationCanceledException {
- if(searcher != null)
- searcher.findELReferences();
+ if(searcher == null)
+ return status;
+ if(method != null && !added){
+ if(searcher.isGetter(method))
+ status.addWarning(SeamCoreMessages.SEAM_RENAME_METHOD_PARTICIPANT_GETTER_WARNING);
+ else if(searcher.isSetter(method))
+ status.addWarning(SeamCoreMessages.SEAM_RENAME_METHOD_PARTICIPANT_SETTER_WARNING);
+ added = true;
+ }
+
+ searcher.findELReferences();
+
return status;
}
@@ -72,13 +84,11 @@
rootChange = new CompositeChange("");
method = (IMethod)element;
- if(!SeamRenameMethodSearcher.isSetter(method.getElementName()))
- return false;
-
oldName = SeamRenameMethodSearcher.getPropertyName(method.getElementName());
newName = SeamRenameMethodSearcher.getPropertyName(getArguments().getNewName());
searcher = new SeamRenameMethodSearcher((IFile)method.getResource(), oldName);
+ added = false;
return true;
}
return false;
@@ -116,7 +126,7 @@
class SeamRenameMethodSearcher extends SeamRefactorSearcher{
public SeamRenameMethodSearcher(IFile file, String name){
- super(file, name);
+ super(file, name, method);
}
@Override
@@ -150,7 +160,7 @@
}
@Override
- protected void match(IFile file, int offset, int length) {
+ protected void match(IFile file, int offset, int length, boolean resolved) {
change(file, offset, length, newName);
}
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java 2009-10-01
12:33:10 UTC (rev 17833)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java 2009-10-01
12:33:57 UTC (rev 17834)
@@ -448,7 +448,7 @@
}
@Override
- protected void match(IFile file, int offset, int length) {
+ protected void match(IFile file, int offset, int length, boolean resolved) {
change(file, offset, length, newName);
}
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/ELSearchQuery.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/ELSearchQuery.java 2009-10-01
12:33:10 UTC (rev 17833)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/ELSearchQuery.java 2009-10-01
12:33:57 UTC (rev 17834)
@@ -83,7 +83,7 @@
}
@Override
- protected void match(IFile file, int offset, int length) {
+ protected void match(IFile file, int offset, int length, boolean resolved) {
Match match = new Match(file, offset, length);
result.addMatch(match);
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamELReferencesQueryParticipant.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamELReferencesQueryParticipant.java 2009-10-01
12:33:10 UTC (rev 17833)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamELReferencesQueryParticipant.java 2009-10-01
12:33:57 UTC (rev 17834)
@@ -86,7 +86,7 @@
}
@Override
- protected void match(IFile file, int offset, int length) {
+ protected void match(IFile file, int offset, int length, boolean resolved) {
Match match = new Match(file, offset, length);
requestor.reportMatch(match);
}