Author: dazarov
Date: 2009-10-07 11:56:31 -0400 (Wed, 07 Oct 2009)
New Revision: 17965
Added:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/refactoring/
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/refactoring/RefactorSearcher.java
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ElUiCoreMessages.java
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/refactoring/
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/refactoring/RenameMethodParticipant.java
Removed:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRefactorSearcher.java
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/META-INF/MANIFEST.MF
trunk/common/plugins/org.jboss.tools.common.el.ui/.classpath
trunk/common/plugins/org.jboss.tools.common.el.ui/META-INF/MANIFEST.MF
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/messages.properties
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-4989,
https://jira.jboss.org/jira/browse/JBIDE-4856
Modified: trunk/common/plugins/org.jboss.tools.common.el.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/META-INF/MANIFEST.MF 2009-10-07
15:19:20 UTC (rev 17964)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/META-INF/MANIFEST.MF 2009-10-07
15:56:31 UTC (rev 17965)
@@ -9,6 +9,7 @@
Export-Package: org.jboss.tools.common.el.core,
org.jboss.tools.common.el.core.model,
org.jboss.tools.common.el.core.parser,
+ org.jboss.tools.common.el.core.refactoring,
org.jboss.tools.common.el.core.resolver,
org.jboss.tools.common.el.internal.core.parser,
org.jboss.tools.common.el.internal.core.parser.token
@@ -19,5 +20,6 @@
org.jboss.tools.common,
org.jboss.tools.common.model,
org.jboss.tools.common.resref.core;visibility:=reexport,
- org.eclipse.ui
+ org.eclipse.ui,
+ org.eclipse.jdt.ui;bundle-version="3.5.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Added:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/refactoring/RefactorSearcher.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/refactoring/RefactorSearcher.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/refactoring/RefactorSearcher.java 2009-10-07
15:56:31 UTC (rev 17965)
@@ -0,0 +1,467 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.el.core.refactoring;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+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;
+import org.eclipse.jdt.ui.text.IJavaPartitions;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+import org.jboss.tools.common.el.core.Activator;
+import org.jboss.tools.common.el.core.model.ELExpression;
+import org.jboss.tools.common.el.core.model.ELInstance;
+import org.jboss.tools.common.el.core.model.ELInvocationExpression;
+import org.jboss.tools.common.el.core.model.ELMethodInvocation;
+import org.jboss.tools.common.el.core.model.ELModel;
+import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
+import org.jboss.tools.common.el.core.parser.ELParser;
+import org.jboss.tools.common.el.core.parser.ELParserUtil;
+import org.jboss.tools.common.el.core.resolver.ELCompletionEngine;
+import org.jboss.tools.common.el.core.resolver.ELResolution;
+import org.jboss.tools.common.el.core.resolver.ELResolver;
+import org.jboss.tools.common.el.core.resolver.ELResolverFactoryManager;
+import org.jboss.tools.common.el.core.resolver.ELSegment;
+import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
+import org.jboss.tools.common.el.core.resolver.JavaMemberELSegment;
+import org.jboss.tools.common.el.core.resolver.SimpleELContext;
+import org.jboss.tools.common.el.core.resolver.Var;
+import org.jboss.tools.common.model.util.EclipseJavaUtil;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.util.FileUtil;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public abstract class RefactorSearcher {
+ protected static final String JAVA_EXT = "java"; //$NON-NLS-1$
+ protected static final String XML_EXT = "xml"; //$NON-NLS-1$
+ protected static final String XHTML_EXT = "xhtml"; //$NON-NLS-1$
+ protected static final String JSP_EXT = "jsp"; //$NON-NLS-1$
+ protected static final String PROPERTIES_EXT = "properties"; //$NON-NLS-1$
+
+ private static final String GET = "get"; //$NON-NLS-1$
+ private static final String SET = "set"; //$NON-NLS-1$
+ private static final String IS = "is"; //$NON-NLS-1$
+
+
+ protected static final String SEAM_PROPERTIES_FILE = "seam.properties";
//$NON-NLS-1$
+
+ protected IFile baseFile;
+ protected String propertyName;
+ protected IJavaElement javaElement;
+ protected IJavaSearchScope searchScope;
+
+ public RefactorSearcher(IFile baseFile, String propertyName){
+ this.baseFile = baseFile;
+ this.propertyName = propertyName;
+ }
+
+ public RefactorSearcher(IFile baseFile, String propertyName, IJavaElement javaElement){
+ this(baseFile, propertyName);
+ this.javaElement = javaElement;
+ }
+
+ public void setSearchScope(IJavaSearchScope searchScope){
+ this.searchScope = searchScope;
+ }
+
+ public void findELReferences(){
+ if(baseFile == null)
+ return;
+
+ IProject[] projects = getProjects();
+ for (IProject project : projects) {
+ if(project == null) continue;
+
+ if(!containsInSearchScope(project))
+ continue;
+
+ IJavaProject javaProject = EclipseResourceUtil.getJavaProject(project);
+
+ // searching java, xml and property files in source folders
+ if(javaProject != null){
+ for(IResource resource : EclipseResourceUtil.getJavaSourceRoots(project)){
+ if(resource instanceof IFolder)
+ scanForJava((IFolder) resource);
+ else if(resource instanceof IFile)
+ scanForJava((IFile) resource);
+ }
+ }
+
+ // searching jsp, xhtml and xml files in WebContent folders
+
+ if(getViewFolder(project) != null)
+ scan(getViewFolder(project));
+ else
+ scan(project);
+ }
+ }
+
+ protected abstract IProject[] getProjects();
+
+ protected abstract IContainer getViewFolder(IProject project);
+
+ private void scanForJava(IContainer container){
+ try{
+ for(IResource resource : container.members()){
+ if(resource instanceof IFolder)
+ scanForJava((IFolder) resource);
+ else if(resource instanceof IFile)
+ scanForJava((IFile) resource);
+ }
+ }catch(CoreException ex){
+ Activator.getDefault().logError(ex);
+ }
+ }
+
+ private void scan(IContainer container){
+ try{
+ for(IResource resource : container.members()){
+ if(resource instanceof IFolder)
+ scan((IFolder) resource);
+ else if(resource instanceof IFile)
+ scan((IFile) resource);
+ }
+ }catch(CoreException ex){
+ Activator.getDefault().logError(ex);
+ }
+ }
+
+ private void scanForJava(IFile file){
+ String ext = file.getFileExtension();
+
+ if(!isFileCorrect(file))
+ return;
+
+ String content = null;
+ try {
+ content = FileUtil.readStream(file.getContents());
+ } catch (CoreException e) {
+ Activator.getDefault().logError(e);
+ return;
+ }
+ if(JAVA_EXT.equalsIgnoreCase(ext)){
+ scanJava(file, content);
+ }else if(XML_EXT.equalsIgnoreCase(ext))
+ scanDOM(file, content);
+ else if(PROPERTIES_EXT.equalsIgnoreCase(ext))
+ scanProperties(file, content);
+ }
+
+ private void scan(IFile file){
+ String ext = file.getFileExtension();
+
+ if(!isFileCorrect(file))
+ return;
+
+ String content = null;
+ try {
+ content = FileUtil.readStream(file.getContents());
+ } catch (CoreException e) {
+ Activator.getDefault().logError(e);
+ return;
+ }
+ if(XML_EXT.equalsIgnoreCase(ext) || XHTML_EXT.equalsIgnoreCase(ext) ||
JSP_EXT.equalsIgnoreCase(ext))
+ scanDOM(file, content);
+ }
+
+ private void scanJava(IFile file, String content){
+ try {
+ FastJavaPartitionScanner scaner = new FastJavaPartitionScanner();
+ Document document = new Document(content);
+ scaner.setRange(document, 0, document.getLength());
+ IToken token = scaner.nextToken();
+ while(token!=null && token!=Token.EOF) {
+ if(IJavaPartitions.JAVA_STRING.equals(token.getData())) {
+ int length = scaner.getTokenLength();
+ int offset = scaner.getTokenOffset();
+ String value = document.get(offset, length);
+ if(value.indexOf('{')>-1) {
+ scanString(file, value, offset);
+ }
+ }
+ token = scaner.nextToken();
+ }
+ } catch (BadLocationException e) {
+ Activator.getDefault().logError(e);
+ }
+ }
+
+ private void scanDOM(IFile file, String content){
+ IModelManager manager = StructuredModelManager.getModelManager();
+ if(manager == null) {
+ return;
+ }
+ IStructuredModel model = null;
+ try {
+ model = manager.getModelForRead(file);
+ if (model instanceof IDOMModel) {
+ IDOMModel domModel = (IDOMModel) model;
+ IDOMDocument document = domModel.getDocument();
+ scanChildNodes(file, document);
+ }
+ } catch (CoreException e) {
+ Activator.getDefault().logError(e);
+ } catch (IOException e) {
+ Activator.getDefault().logError(e);
+ } finally {
+ if (model != null) {
+ model.releaseFromRead();
+ }
+ }
+ }
+
+ private void scanChildNodes(IFile file, Node parent) {
+ NodeList children = parent.getChildNodes();
+ for(int i=0; i<children.getLength(); i++) {
+ Node curentValidatedNode = children.item(i);
+ if(Node.ELEMENT_NODE == curentValidatedNode.getNodeType()) {
+ scanNodeContent(file,
((IDOMNode)curentValidatedNode).getFirstStructuredDocumentRegion(),
DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE);
+ } else if(Node.TEXT_NODE == curentValidatedNode.getNodeType()) {
+ scanNodeContent(file,
((IDOMNode)curentValidatedNode).getFirstStructuredDocumentRegion(),
DOMRegionContext.XML_CONTENT);
+ }
+ scanChildNodes(file, curentValidatedNode);
+ }
+ }
+
+ private void scanNodeContent(IFile file, IStructuredDocumentRegion node, String
regionType) {
+ ITextRegionList regions = node.getRegions();
+ for(int i=0; i<regions.size(); i++) {
+ ITextRegion region = regions.get(i);
+ if(region.getType() == regionType) {
+ String text = node.getFullText(region);
+ if(text.indexOf("{")>-1) { //$NON-NLS-1$
+ int offset = node.getStartOffset() + region.getStart();
+ scanString(file, text, offset);
+ }
+ }
+ }
+ }
+
+ // looking for component references in EL
+ private void scanString(IFile file, String string, int offset) {
+ int startEl = string.indexOf("#{"); //$NON-NLS-1$
+ if(startEl>-1) {
+ ELParser parser = ELParserUtil.getJbossFactory().createParser();
+ ELModel model = parser.parse(string);
+ for (ELInstance instance : model.getInstances()) {
+ for(ELInvocationExpression ie : instance.getExpression().getInvocations()){
+ ELInvocationExpression expression = findComponentReference(ie);
+ if(expression != null){
+ ELInvocationExpression left = expression.getLeft();
+ checkMatch(file, left, offset+getOffset(left), offset+getOffset(expression),
getLength(expression));
+ }
+ }
+ }
+ }
+ }
+
+ private int getOffset(ELInvocationExpression expression){
+ if(expression instanceof ELPropertyInvocation){
+ ELPropertyInvocation pi = (ELPropertyInvocation)expression;
+
+ return pi.getName().getStart();
+ }else if(expression instanceof ELMethodInvocation){
+ ELMethodInvocation mi = (ELMethodInvocation)expression;
+
+ return mi.getName().getStart();
+ }
+ return 0;
+ }
+
+ private int getLength(ELInvocationExpression expression){
+ if(expression instanceof ELPropertyInvocation){
+ ELPropertyInvocation pi = (ELPropertyInvocation)expression;
+
+ return pi.getName().getLength();
+ }else if(expression instanceof ELMethodInvocation){
+ ELMethodInvocation mi = (ELMethodInvocation)expression;
+
+ return mi.getName().getLength();
+ }
+ return 0;
+ }
+
+ private void scanProperties(IFile file, String content){
+ scanString(file, content, 0);
+
+ if(!file.getName().equals(SEAM_PROPERTIES_FILE))
+ return;
+
+ StringTokenizer tokenizer = new StringTokenizer(content, "#= \t\r\n\f",
true); //$NON-NLS-1$
+
+ String lastToken = "\n"; //$NON-NLS-1$
+ int offset = 0;
+ boolean comment = false;
+ boolean key = true;
+
+ while(tokenizer.hasMoreTokens()){
+ String token = tokenizer.nextToken("#= \t\r\n\f"); //$NON-NLS-1$
+ if(token.equals("\r")) //$NON-NLS-1$
+ token = "\n"; //$NON-NLS-1$
+
+ if(token.equals("#") && lastToken.equals("\n"))
//$NON-NLS-1$ //$NON-NLS-2$
+ comment = true;
+ else if(token.equals("\n") && comment) //$NON-NLS-1$
+ comment = false;
+
+ if(!comment){
+ if(!token.equals("\n") && lastToken.equals("\n"))
//$NON-NLS-1$ //$NON-NLS-2$
+ key = true;
+ else if(key && (token.equals("=") || token.equals(" ")))
//$NON-NLS-1$ //$NON-NLS-2$
+ key = false;
+
+ if(key && token.startsWith(propertyName)){
+ match(file, offset, token.length(), true);
+ }
+ }
+
+ lastToken = token;
+ offset += token.length();
+ }
+ }
+
+
+ protected ELInvocationExpression findComponentReference(ELInvocationExpression
invocationExpression){
+ ELInvocationExpression invExp = invocationExpression;
+ while(invExp != null){
+ if(invExp instanceof ELPropertyInvocation){
+ if(((ELPropertyInvocation)invExp).getQualifiedName() != null &&
((ELPropertyInvocation)invExp).getQualifiedName().equals(propertyName))
+ return invExp;
+ else
+ invExp = invExp.getLeft();
+
+ }else{
+ invExp = invExp.getLeft();
+ }
+ }
+ return null;
+ }
+
+ protected abstract boolean isFileCorrect(IFile file);
+
+ 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, true);
+ }
+
+ public static String getPropertyName(String methodName){
+ if(methodName.startsWith(GET) || methodName.startsWith(SET)){
+ String name = methodName.substring(3);
+ return name.substring(0, 1).toLowerCase()+name.substring(1);
+ }
+
+ if(methodName.startsWith(IS)){
+ String name = methodName.substring(2);
+ return name.substring(0, 1).toLowerCase()+name.substring(1);
+ }
+
+ return methodName;
+ }
+
+ // 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)
+ return true;
+ IPath[] paths = searchScope.enclosingProjectsAndJars();
+ for(IPath path : paths){
+ if(path.equals(project.getFullPath()))
+ return true;
+ }
+ return false;
+ }
+
+ private void resolve(IFile file, ELExpression operand, int leftOffset,
+ int offset, int length) {
+ ELResolver[] resolvers = ELResolverFactoryManager.getInstance()
+ .getResolvers(file);
+
+ for (ELResolver resolver : resolvers) {
+ if (!(resolver instanceof ELCompletionEngine))
+ continue;
+
+ SimpleELContext context = new SimpleELContext();
+
+ context.setResource(file);
+ context.setElResolvers(resolvers);
+
+ List<Var> vars = ElVarSearcher.findAllVars(context, leftOffset,
+ resolver);
+
+ context.setVars(vars);
+
+ ELResolution resolution = resolver.resolve(context, operand);
+
+ ELSegment segment = resolution.findSegmentByOffset(leftOffset);
+
+ if (segment != null && segment instanceof JavaMemberELSegment
+ && segment.isResolved()) {
+ JavaMemberELSegment javaSegment = (JavaMemberELSegment) segment;
+ IJavaElement segmentJavaElement = javaSegment.getJavaElement();
+ if (javaElement instanceof IType
+ && segmentJavaElement instanceof IType) {
+ if (EclipseJavaUtil.isDerivedClass(
+ ((IType) javaElement).getFullyQualifiedName(),
+ ((IType) segmentJavaElement).getFullyQualifiedName(),
+ file.getProject()))
+ match(file, offset, length, true);
+ } else if (javaElement.equals(segmentJavaElement))
+ match(file, offset, length, true);
+ }
+ }
+ match(file, offset, length, false);
+ }
+}
\ No newline at end of file
Modified: trunk/common/plugins/org.jboss.tools.common.el.ui/.classpath
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.ui/.classpath 2009-10-07 15:19:20 UTC
(rev 17964)
+++ trunk/common/plugins/org.jboss.tools.common.el.ui/.classpath 2009-10-07 15:56:31 UTC
(rev 17965)
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Modified: trunk/common/plugins/org.jboss.tools.common.el.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.ui/META-INF/MANIFEST.MF 2009-10-07
15:19:20 UTC (rev 17964)
+++ trunk/common/plugins/org.jboss.tools.common.el.ui/META-INF/MANIFEST.MF 2009-10-07
15:56:31 UTC (rev 17965)
@@ -3,7 +3,7 @@
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Bundle-Name: %Bundle-Name.0
-Bundle-SymbolicName: org.jboss.tools.common.el.ui
+Bundle-SymbolicName: org.jboss.tools.common.el.ui;singleton:=true
Bundle-Version: 1.0.0
Export-Package: org.jboss.tools.common.el.ui
Bundle-Activator: org.jboss.tools.common.el.ui.Activator
@@ -12,7 +12,8 @@
org.jboss.tools.common.el.core;bundle-version="2.0.0",
org.jboss.tools.common.resref.ui;bundle-version="1.0.0",
org.eclipse.core.resources;bundle-version="3.4.0",
- org.jboss.tools.common.model.ui;bundle-version="2.0.0"
+ org.jboss.tools.common.model.ui;bundle-version="2.0.0",
+ org.eclipse.ltk.core.refactoring;bundle-version="3.5.0"
Bundle-Vendor: %Bundle-Vendor.0
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: org.jboss.tools.vpe.resref.core
Added:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ElUiCoreMessages.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ElUiCoreMessages.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ElUiCoreMessages.java 2009-10-07
15:56:31 UTC (rev 17965)
@@ -0,0 +1,18 @@
+package org.jboss.tools.common.el.ui;
+
+import org.eclipse.osgi.util.NLS;
+
+public class ElUiCoreMessages {
+ private static final String BUNDLE_NAME =
"org.jboss.tools.common.el.ui.messages"; //$NON-NLS-1$
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, ElUiCoreMessages.class);
+ }
+
+ public static String RENAME_METHOD_PARTICIPANT_GETTER_WARNING;
+ public static String RENAME_METHOD_PARTICIPANT_SETTER_WARNING;
+ public static String RENAME_METHOD_PARTICIPANT_OUT_OF_SYNC_FILE;
+ public static String RENAME_METHOD_PARTICIPANT_ERROR_PHANTOM_FILE;
+ public static String RENAME_METHOD_PARTICIPANT_ERROR_READ_ONLY_FILE;
+
+}
\ No newline at end of file
Property changes on:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ElUiCoreMessages.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/messages.properties
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/messages.properties 2009-10-07
15:19:20 UTC (rev 17964)
+++
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/messages.properties 2009-10-07
15:56:31 UTC (rev 17965)
@@ -1 +1,6 @@
-SUBSTITUTED_EL_EXPRESSIONS=Substituted El expressions
\ No newline at end of file
+SUBSTITUTED_EL_EXPRESSIONS=Substituted El expressions
+RENAME_METHOD_PARTICIPANT_GETTER_WARNING=Be sure, may be you also should rename setter
method to avoid compilation problems.
+RENAME_METHOD_PARTICIPANT_SETTER_WARNING=Be sure, may be you also should rename getter
method to avoid compilation problems.
+RENAME_METHOD_PARTICIPANT_OUT_OF_SYNC_FILE=Cannot change file. File
''{0}'' is not in sync.
+RENAME_METHOD_PARTICIPANT_ERROR_PHANTOM_FILE=Cannot change phantom file:
''{0}''.
+RENAME_METHOD_PARTICIPANT_ERROR_READ_ONLY_FILE=Cannot change read-only file:
''{0}''.
\ No newline at end of file
Added:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/refactoring/RenameMethodParticipant.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/refactoring/RenameMethodParticipant.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/refactoring/RenameMethodParticipant.java 2009-10-07
15:56:31 UTC (rev 17965)
@@ -0,0 +1,188 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.el.ui.refactoring;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
+import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
+import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
+import org.eclipse.ltk.internal.core.refactoring.Messages;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.eclipse.text.edits.ReplaceEdit;
+import org.eclipse.text.edits.TextEdit;
+import org.jboss.tools.common.el.core.model.ELInvocationExpression;
+import org.jboss.tools.common.el.core.model.ELMethodInvocation;
+import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
+import org.jboss.tools.common.el.core.refactoring.RefactorSearcher;
+import org.jboss.tools.common.el.ui.ElUiCoreMessages;
+
+public class RenameMethodParticipant extends RenameParticipant{
+ private IMethod method;
+ private String oldName;
+ private String newName;
+ private SeamRenameMethodSearcher searcher;
+ private RefactoringStatus status;
+ private CompositeChange rootChange;
+ private TextFileChange lastChange;
+ private ArrayList<String> keys = new ArrayList<String>();
+ private boolean resolved = true;
+
+ private static boolean added = false;
+
+
+ @Override
+ public RefactoringStatus checkConditions(IProgressMonitor pm,
+ CheckConditionsContext context) throws OperationCanceledException {
+ if(searcher == null)
+ return status;
+
+ if(method != null && !added){
+ if(searcher.isGetter(method))
+ status.addWarning(ElUiCoreMessages.RENAME_METHOD_PARTICIPANT_GETTER_WARNING);
+ else if(searcher.isSetter(method))
+ status.addWarning(ElUiCoreMessages.RENAME_METHOD_PARTICIPANT_SETTER_WARNING);
+ added = true;
+ }
+
+ searcher.findELReferences();
+
+ // TODO: find good phrase and externalize it
+ if(!resolved)
+ status.addWarning("Some changes were not resolved.");
+
+ return status;
+ }
+
+ @Override
+ public Change createChange(IProgressMonitor pm) throws CoreException,
+ OperationCanceledException {
+ return rootChange;
+ }
+
+ @Override
+ public String getName() {
+ return oldName;
+ }
+
+ @Override
+ protected boolean initialize(Object element) {
+ if(element instanceof IMethod){
+ status = new RefactoringStatus();
+
+ rootChange = new CompositeChange("");
+ method = (IMethod)element;
+
+ oldName = SeamRenameMethodSearcher.getPropertyName(method.getElementName());
+
+ newName = SeamRenameMethodSearcher.getPropertyName(getArguments().getNewName());
+ searcher = new SeamRenameMethodSearcher((IFile)method.getResource(), oldName);
+ added = false;
+ return true;
+ }
+ return false;
+ }
+
+ protected TextFileChange getChange(IFile file){
+ if(lastChange != null && lastChange.getFile().equals(file))
+ return lastChange;
+
+ for(int i=0; i < rootChange.getChildren().length; i++){
+ TextFileChange change = (TextFileChange)rootChange.getChildren()[i];
+ if(change.getFile().equals(file)){
+ lastChange = change;
+ return lastChange;
+ }
+ }
+ lastChange = new TextFileChange(file.getName(), file);
+ MultiTextEdit root = new MultiTextEdit();
+ lastChange.setEdit(root);
+ rootChange.add(lastChange);
+
+ return lastChange;
+ }
+
+ private void change(IFile file, int offset, int length, String text){
+ //System.out.println("change file - "+file.getFullPath()+" offset -
"+offset+" len - "+length+" text <"+text+">");
+ String key = file.getFullPath().toString()+" "+offset;
+ if(!keys.contains(key)){
+ TextFileChange change = getChange(file);
+ TextEdit edit = new ReplaceEdit(offset, length, text);
+ change.addEdit(edit);
+ keys.add(key);
+ }
+ }
+
+ class SeamRenameMethodSearcher extends RefactorSearcher{
+ public SeamRenameMethodSearcher(IFile file, String name){
+ super(file, name, method);
+ }
+
+ @Override
+ protected boolean isFileCorrect(IFile file) {
+ if(!file.isSynchronized(IResource.DEPTH_ZERO)){
+ status.addFatalError(Messages.format(ElUiCoreMessages.RENAME_METHOD_PARTICIPANT_OUT_OF_SYNC_FILE,
file.getFullPath().toString()));
+ return false;
+ }else if(file.isPhantom()){
+ status.addFatalError(Messages.format(ElUiCoreMessages.RENAME_METHOD_PARTICIPANT_ERROR_PHANTOM_FILE,
file.getFullPath().toString()));
+ return false;
+ }else if(file.isReadOnly()){
+ status.addFatalError(Messages.format(ElUiCoreMessages.RENAME_METHOD_PARTICIPANT_ERROR_READ_ONLY_FILE,
file.getFullPath().toString()));
+ return false;
+ }
+ return true;
+ }
+
+ protected IProject[] getProjects(){
+ IProject[] projects = new IProject[1];
+ projects[0] = baseFile.getProject();
+ return projects;
+ }
+
+ protected IContainer getViewFolder(IProject project){
+ return null;
+ }
+
+ protected ELInvocationExpression findComponentReference(ELInvocationExpression
invocationExpression){
+ ELInvocationExpression invExp = invocationExpression;
+ while(invExp != null){
+ if(invExp instanceof ELMethodInvocation || invExp instanceof ELPropertyInvocation){
+ if(invExp.getMemberName() != null &&
invExp.getMemberName().equals(propertyName))
+ return invExp;
+ else
+ invExp = invExp.getLeft();
+ }else{
+ invExp = invExp.getLeft();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ protected void match(IFile file, int offset, int length, boolean resolved) {
+ change(file, offset, length, newName);
+ if(!resolved)
+ RenameMethodParticipant.this.resolved = false;
+ }
+ }
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/refactoring/RenameMethodParticipant.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
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-07
15:19:20 UTC (rev 17964)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRefactorSearcher.java 2009-10-07
15:56:31 UTC (rev 17965)
@@ -1,467 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.internal.core.refactoring;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.StringTokenizer;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-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;
-import org.eclipse.jdt.ui.text.IJavaPartitions;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.Token;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.jboss.tools.common.el.core.model.ELExpression;
-import org.jboss.tools.common.el.core.model.ELInstance;
-import org.jboss.tools.common.el.core.model.ELInvocationExpression;
-import org.jboss.tools.common.el.core.model.ELMethodInvocation;
-import org.jboss.tools.common.el.core.model.ELModel;
-import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
-import org.jboss.tools.common.el.core.parser.ELParser;
-import org.jboss.tools.common.el.core.parser.ELParserUtil;
-import org.jboss.tools.common.el.core.resolver.ELCompletionEngine;
-import org.jboss.tools.common.el.core.resolver.ELResolution;
-import org.jboss.tools.common.el.core.resolver.ELResolver;
-import org.jboss.tools.common.el.core.resolver.ELResolverFactoryManager;
-import org.jboss.tools.common.el.core.resolver.ELSegment;
-import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
-import org.jboss.tools.common.el.core.resolver.JavaMemberELSegment;
-import org.jboss.tools.common.el.core.resolver.SimpleELContext;
-import org.jboss.tools.common.el.core.resolver.Var;
-import org.jboss.tools.common.model.util.EclipseJavaUtil;
-import org.jboss.tools.common.model.util.EclipseResourceUtil;
-import org.jboss.tools.common.util.FileUtil;
-import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.jboss.tools.seam.core.SeamProjectsSet;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-public abstract class SeamRefactorSearcher {
- protected static final String JAVA_EXT = "java"; //$NON-NLS-1$
- protected static final String XML_EXT = "xml"; //$NON-NLS-1$
- protected static final String XHTML_EXT = "xhtml"; //$NON-NLS-1$
- protected static final String JSP_EXT = "jsp"; //$NON-NLS-1$
- protected static final String PROPERTIES_EXT = "properties"; //$NON-NLS-1$
-
- private static final String GET = "get"; //$NON-NLS-1$
- private static final String SET = "set"; //$NON-NLS-1$
- private static final String IS = "is"; //$NON-NLS-1$
-
-
- protected static final String SEAM_PROPERTIES_FILE = "seam.properties";
//$NON-NLS-1$
-
- protected IFile baseFile;
- protected String propertyName;
- protected IJavaElement javaElement;
- protected IJavaSearchScope searchScope;
-
- public SeamRefactorSearcher(IFile baseFile, String propertyName){
- this.baseFile = baseFile;
- this.propertyName = propertyName;
- }
-
- public SeamRefactorSearcher(IFile baseFile, String propertyName, IJavaElement
javaElement){
- this(baseFile, propertyName);
- this.javaElement = javaElement;
- }
-
- public void setSearchScope(IJavaSearchScope searchScope){
- this.searchScope = searchScope;
- }
-
- public void findELReferences(){
- if(baseFile == null)
- return;
-
- SeamProjectsSet projectsSet = new SeamProjectsSet(baseFile.getProject());
-
- IProject[] projects = projectsSet.getAllProjects();
- for (IProject project : projects) {
- if(project == null) continue;
-
- if(!containsInSearchScope(project))
- continue;
-
- IJavaProject javaProject = EclipseResourceUtil.getJavaProject(project);
-
- // searching java, xml and property files in source folders
- if(javaProject != null){
- for(IResource resource : EclipseResourceUtil.getJavaSourceRoots(project)){
- if(resource instanceof IFolder)
- scanForJava((IFolder) resource);
- else if(resource instanceof IFile)
- scanForJava((IFile) resource);
- }
- }
-
- // searching jsp, xhtml and xml files in WebContent folders
- if(project.equals(projectsSet.getWarProject()))
- scan(projectsSet.getDefaultViewsFolder());
- else if(project.equals(projectsSet.getEarProject()))
- scan(projectsSet.getDefaultEarViewsFolder());
- else{
- scan(project);
- }
- }
- }
- private void scanForJava(IContainer container){
- try{
- for(IResource resource : container.members()){
- if(resource instanceof IFolder)
- scanForJava((IFolder) resource);
- else if(resource instanceof IFile)
- scanForJava((IFile) resource);
- }
- }catch(CoreException ex){
- SeamCorePlugin.getDefault().logError(ex);
- }
- }
-
- private void scan(IContainer container){
- try{
- for(IResource resource : container.members()){
- if(resource instanceof IFolder)
- scan((IFolder) resource);
- else if(resource instanceof IFile)
- scan((IFile) resource);
- }
- }catch(CoreException ex){
- SeamCorePlugin.getDefault().logError(ex);
- }
- }
-
- private void scanForJava(IFile file){
- String ext = file.getFileExtension();
-
- if(!isFileCorrect(file))
- return;
-
- String content = null;
- try {
- content = FileUtil.readStream(file.getContents());
- } catch (CoreException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- return;
- }
- if(JAVA_EXT.equalsIgnoreCase(ext)){
- scanJava(file, content);
- }else if(XML_EXT.equalsIgnoreCase(ext))
- scanDOM(file, content);
- else if(PROPERTIES_EXT.equalsIgnoreCase(ext))
- scanProperties(file, content);
- }
-
- private void scan(IFile file){
- String ext = file.getFileExtension();
-
- if(!isFileCorrect(file))
- return;
-
- String content = null;
- try {
- content = FileUtil.readStream(file.getContents());
- } catch (CoreException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- return;
- }
- if(XML_EXT.equalsIgnoreCase(ext) || XHTML_EXT.equalsIgnoreCase(ext) ||
JSP_EXT.equalsIgnoreCase(ext))
- scanDOM(file, content);
- }
-
- private void scanJava(IFile file, String content){
- try {
- FastJavaPartitionScanner scaner = new FastJavaPartitionScanner();
- Document document = new Document(content);
- scaner.setRange(document, 0, document.getLength());
- IToken token = scaner.nextToken();
- while(token!=null && token!=Token.EOF) {
- if(IJavaPartitions.JAVA_STRING.equals(token.getData())) {
- int length = scaner.getTokenLength();
- int offset = scaner.getTokenOffset();
- String value = document.get(offset, length);
- if(value.indexOf('{')>-1) {
- scanString(file, value, offset);
- }
- }
- token = scaner.nextToken();
- }
- } catch (BadLocationException e) {
- SeamCorePlugin.getDefault().logError(e);
- }
- }
-
- private void scanDOM(IFile file, String content){
- IModelManager manager = StructuredModelManager.getModelManager();
- if(manager == null) {
- return;
- }
- IStructuredModel model = null;
- try {
- model = manager.getModelForRead(file);
- if (model instanceof IDOMModel) {
- IDOMModel domModel = (IDOMModel) model;
- IDOMDocument document = domModel.getDocument();
- scanChildNodes(file, document);
- }
- } catch (CoreException e) {
- SeamCorePlugin.getDefault().logError(e);
- } catch (IOException e) {
- SeamCorePlugin.getDefault().logError(e);
- } finally {
- if (model != null) {
- model.releaseFromRead();
- }
- }
- }
-
- private void scanChildNodes(IFile file, Node parent) {
- NodeList children = parent.getChildNodes();
- for(int i=0; i<children.getLength(); i++) {
- Node curentValidatedNode = children.item(i);
- if(Node.ELEMENT_NODE == curentValidatedNode.getNodeType()) {
- scanNodeContent(file,
((IDOMNode)curentValidatedNode).getFirstStructuredDocumentRegion(),
DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE);
- } else if(Node.TEXT_NODE == curentValidatedNode.getNodeType()) {
- scanNodeContent(file,
((IDOMNode)curentValidatedNode).getFirstStructuredDocumentRegion(),
DOMRegionContext.XML_CONTENT);
- }
- scanChildNodes(file, curentValidatedNode);
- }
- }
-
- private void scanNodeContent(IFile file, IStructuredDocumentRegion node, String
regionType) {
- ITextRegionList regions = node.getRegions();
- for(int i=0; i<regions.size(); i++) {
- ITextRegion region = regions.get(i);
- if(region.getType() == regionType) {
- String text = node.getFullText(region);
- if(text.indexOf("{")>-1) { //$NON-NLS-1$
- int offset = node.getStartOffset() + region.getStart();
- scanString(file, text, offset);
- }
- }
- }
- }
-
- // looking for component references in EL
- private void scanString(IFile file, String string, int offset) {
- int startEl = string.indexOf("#{"); //$NON-NLS-1$
- if(startEl>-1) {
- ELParser parser = ELParserUtil.getJbossFactory().createParser();
- ELModel model = parser.parse(string);
- for (ELInstance instance : model.getInstances()) {
- for(ELInvocationExpression ie : instance.getExpression().getInvocations()){
- ELInvocationExpression expression = findComponentReference(ie);
- if(expression != null){
- ELInvocationExpression left = expression.getLeft();
- checkMatch(file, left, offset+getOffset(left), offset+getOffset(expression),
getLength(expression));
- }
- }
- }
- }
- }
-
- private int getOffset(ELInvocationExpression expression){
- if(expression instanceof ELPropertyInvocation){
- ELPropertyInvocation pi = (ELPropertyInvocation)expression;
-
- return pi.getName().getStart();
- }else if(expression instanceof ELMethodInvocation){
- ELMethodInvocation mi = (ELMethodInvocation)expression;
-
- return mi.getName().getStart();
- }
- return 0;
- }
-
- private int getLength(ELInvocationExpression expression){
- if(expression instanceof ELPropertyInvocation){
- ELPropertyInvocation pi = (ELPropertyInvocation)expression;
-
- return pi.getName().getLength();
- }else if(expression instanceof ELMethodInvocation){
- ELMethodInvocation mi = (ELMethodInvocation)expression;
-
- return mi.getName().getLength();
- }
- return 0;
- }
-
- private void scanProperties(IFile file, String content){
- scanString(file, content, 0);
-
- if(!file.getName().equals(SEAM_PROPERTIES_FILE))
- return;
-
- StringTokenizer tokenizer = new StringTokenizer(content, "#= \t\r\n\f",
true); //$NON-NLS-1$
-
- String lastToken = "\n"; //$NON-NLS-1$
- int offset = 0;
- boolean comment = false;
- boolean key = true;
-
- while(tokenizer.hasMoreTokens()){
- String token = tokenizer.nextToken("#= \t\r\n\f"); //$NON-NLS-1$
- if(token.equals("\r")) //$NON-NLS-1$
- token = "\n"; //$NON-NLS-1$
-
- if(token.equals("#") && lastToken.equals("\n"))
//$NON-NLS-1$ //$NON-NLS-2$
- comment = true;
- else if(token.equals("\n") && comment) //$NON-NLS-1$
- comment = false;
-
- if(!comment){
- if(!token.equals("\n") && lastToken.equals("\n"))
//$NON-NLS-1$ //$NON-NLS-2$
- key = true;
- else if(key && (token.equals("=") || token.equals(" ")))
//$NON-NLS-1$ //$NON-NLS-2$
- key = false;
-
- if(key && token.startsWith(propertyName)){
- match(file, offset, token.length(), true);
- }
- }
-
- lastToken = token;
- offset += token.length();
- }
- }
-
-
- protected ELInvocationExpression findComponentReference(ELInvocationExpression
invocationExpression){
- ELInvocationExpression invExp = invocationExpression;
- while(invExp != null){
- if(invExp instanceof ELPropertyInvocation){
- if(((ELPropertyInvocation)invExp).getQualifiedName() != null &&
((ELPropertyInvocation)invExp).getQualifiedName().equals(propertyName))
- return invExp;
- else
- invExp = invExp.getLeft();
-
- }else{
- invExp = invExp.getLeft();
- }
- }
- return null;
- }
-
- protected abstract boolean isFileCorrect(IFile file);
-
- 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, true);
- }
-
- public static String getPropertyName(String methodName){
- if(methodName.startsWith(GET) || methodName.startsWith(SET)){
- String name = methodName.substring(3);
- return name.substring(0, 1).toLowerCase()+name.substring(1);
- }
-
- if(methodName.startsWith(IS)){
- String name = methodName.substring(2);
- return name.substring(0, 1).toLowerCase()+name.substring(1);
- }
-
- return methodName;
- }
-
- // 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)
- return true;
- IPath[] paths = searchScope.enclosingProjectsAndJars();
- for(IPath path : paths){
- if(path.equals(project.getFullPath()))
- return true;
- }
- return false;
- }
-
- private void resolve(IFile file, ELExpression operand, int leftOffset,
- int offset, int length) {
- ELResolver[] resolvers = ELResolverFactoryManager.getInstance()
- .getResolvers(file);
-
- for (ELResolver resolver : resolvers) {
- if (!(resolver instanceof ELCompletionEngine))
- continue;
-
- SimpleELContext context = new SimpleELContext();
-
- context.setResource(file);
- context.setElResolvers(resolvers);
-
- List<Var> vars = ElVarSearcher.findAllVars(context, leftOffset,
- resolver);
-
- context.setVars(vars);
-
- ELResolution resolution = resolver.resolve(context, operand);
-
- ELSegment segment = resolution.findSegmentByOffset(leftOffset);
-
- if (segment != null && segment instanceof JavaMemberELSegment
- && segment.isResolved()) {
- JavaMemberELSegment javaSegment = (JavaMemberELSegment) segment;
- IJavaElement segmentJavaElement = javaSegment.getJavaElement();
- if (javaElement instanceof IType
- && segmentJavaElement instanceof IType) {
- if (EclipseJavaUtil.isDerivedClass(
- ((IType) javaElement).getFullyQualifiedName(),
- ((IType) segmentJavaElement).getFullyQualifiedName(),
- file.getProject()))
- match(file, offset, length, true);
- } else if (javaElement.equals(segmentJavaElement))
- 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-07
15:19:20 UTC (rev 17964)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameMethodParticipant.java 2009-10-07
15:56:31 UTC (rev 17965)
@@ -12,7 +12,9 @@
import java.util.ArrayList;
+import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -31,7 +33,9 @@
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.common.el.core.model.ELMethodInvocation;
import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
+import org.jboss.tools.common.el.core.refactoring.RefactorSearcher;
import org.jboss.tools.seam.core.SeamCoreMessages;
+import org.jboss.tools.seam.core.SeamProjectsSet;
public class SeamRenameMethodParticipant extends RenameParticipant{
private IMethod method;
@@ -129,9 +133,12 @@
}
}
- class SeamRenameMethodSearcher extends SeamRefactorSearcher{
+ class SeamRenameMethodSearcher extends RefactorSearcher{
+ SeamProjectsSet projectsSet;
+
public SeamRenameMethodSearcher(IFile file, String name){
super(file, name, method);
+ projectsSet = new SeamProjectsSet(file.getProject());
}
@Override
@@ -149,6 +156,19 @@
return true;
}
+ protected IProject[] getProjects(){
+ return projectsSet.getAllProjects();
+ }
+
+ protected IContainer getViewFolder(IProject project){
+ if(project.equals(projectsSet.getWarProject()))
+ return projectsSet.getDefaultViewsFolder();
+ else if(project.equals(projectsSet.getEarProject()))
+ return projectsSet.getDefaultEarViewsFolder();
+
+ return null;
+ }
+
protected ELInvocationExpression findComponentReference(ELInvocationExpression
invocationExpression){
ELInvocationExpression invExp = invocationExpression;
while(invExp != null){
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-07
15:19:20 UTC (rev 17964)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java 2009-10-07
15:56:31 UTC (rev 17965)
@@ -11,8 +11,10 @@
package org.jboss.tools.seam.internal.core.refactoring;
import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
+import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -28,6 +30,7 @@
import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.text.edits.TextEdit;
+import org.jboss.tools.common.el.core.refactoring.RefactorSearcher;
import org.jboss.tools.common.model.project.ext.ITextSourceReference;
import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.seam.core.BijectedAttributeType;
@@ -437,9 +440,11 @@
}
}
- class SeamSearcher extends SeamRefactorSearcher{
+ class SeamSearcher extends RefactorSearcher{
+ SeamProjectsSet projectsSet;
public SeamSearcher(IFile declarationFile, String oldName){
super(declarationFile, oldName);
+ projectsSet = new SeamProjectsSet(declarationFile.getProject());
}
@Override
@@ -451,5 +456,18 @@
protected void match(IFile file, int offset, int length, boolean resolved) {
change(file, offset, length, newName);
}
+
+ protected IProject[] getProjects(){
+ return projectsSet.getAllProjects();
+ }
+
+ protected IContainer getViewFolder(IProject project){
+ if(project.equals(projectsSet.getWarProject()))
+ return projectsSet.getDefaultViewsFolder();
+ else if(project.equals(projectsSet.getEarProject()))
+ return projectsSet.getDefaultEarViewsFolder();
+
+ return null;
+ }
}
}
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-07
15:19:20 UTC (rev 17964)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/ELSearchQuery.java 2009-10-07
15:56:31 UTC (rev 17965)
@@ -10,7 +10,9 @@
******************************************************************************/
package org.jboss.tools.seam.ui.search;
+import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -23,7 +25,8 @@
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.common.el.core.model.ELMethodInvocation;
import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
-import org.jboss.tools.seam.internal.core.refactoring.SeamRefactorSearcher;
+import org.jboss.tools.common.el.core.refactoring.RefactorSearcher;
+import org.jboss.tools.seam.core.SeamProjectsSet;
public class ELSearchQuery implements ISearchQuery {
private String propertyName;
@@ -65,9 +68,11 @@
return Status.OK_STATUS;
}
- class ELSearcher extends SeamRefactorSearcher{
+ class ELSearcher extends RefactorSearcher{
+ SeamProjectsSet projectsSet;
public ELSearcher(IFile file, String name){
super(file, name);
+ projectsSet = new SeamProjectsSet(file.getProject());
}
@Override
@@ -80,7 +85,20 @@
return false;
}
return true;
- }
+ }
+
+ protected IProject[] getProjects(){
+ return projectsSet.getAllProjects();
+ }
+
+ protected IContainer getViewFolder(IProject project){
+ if(project.equals(projectsSet.getWarProject()))
+ return projectsSet.getDefaultViewsFolder();
+ else if(project.equals(projectsSet.getEarProject()))
+ return projectsSet.getDefaultEarViewsFolder();
+
+ return null;
+ }
@Override
protected void match(IFile file, int offset, int length, boolean resolved) {
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-07
15:19:20 UTC (rev 17964)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamELReferencesQueryParticipant.java 2009-10-07
15:56:31 UTC (rev 17965)
@@ -10,7 +10,9 @@
******************************************************************************/
package org.jboss.tools.seam.ui.search;
+import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -35,7 +37,8 @@
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.common.el.core.model.ELMethodInvocation;
import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
-import org.jboss.tools.seam.internal.core.refactoring.SeamRefactorSearcher;
+import org.jboss.tools.common.el.core.refactoring.RefactorSearcher;
+import org.jboss.tools.seam.core.SeamProjectsSet;
public class SeamELReferencesQueryParticipant implements IQueryParticipant,
IMatchPresentation{
private ELSearcher searcher;
@@ -147,11 +150,14 @@
}
}
- class ELSearcher extends SeamRefactorSearcher{
+ class ELSearcher extends RefactorSearcher{
ISearchRequestor requestor;
+ SeamProjectsSet projectsSet;
+
public ELSearcher(ISearchRequestor requestor, IJavaElement element, IFile file, String
name){
super(file, name, element);
this.requestor = requestor;
+ projectsSet = new SeamProjectsSet(file.getProject());
}
@Override
@@ -164,7 +170,20 @@
return false;
}
return true;
- }
+ }
+
+ protected IProject[] getProjects(){
+ return projectsSet.getAllProjects();
+ }
+
+ protected IContainer getViewFolder(IProject project){
+ if(project.equals(projectsSet.getWarProject()))
+ return projectsSet.getDefaultViewsFolder();
+ else if(project.equals(projectsSet.getEarProject()))
+ return projectsSet.getDefaultEarViewsFolder();
+
+ return null;
+ }
@Override
protected void match(IFile file, int offset, int length, boolean resolved) {