Author: dazarov
Date: 2010-04-02 12:06:43 -0400 (Fri, 02 Apr 2010)
New Revision: 21243
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/CDIRenameProcessor.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/RenameNamedBeanProcessor.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/CDIRefactorContributionFactory.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/RenameNamedBeanWizard.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java
Removed:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RefactorSearcher.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/META-INF/MANIFEST.MF
trunk/cdi/plugins/org.jboss.tools.cdi.ui/plugin.xml
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties
trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/ELReferencesQueryParticipant.java
trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/RenameMethodParticipant.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/ELRenameProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRefactorSearcher.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5927
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF 2010-04-02 15:19:07
UTC (rev 21242)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF 2010-04-02 16:06:43
UTC (rev 21243)
@@ -18,7 +18,8 @@
org.jboss.tools.jst.web.kb,
org.jboss.tools.common.el.core,
org.eclipse.jface.text,
- org.eclipse.equinox.preferences
+ org.eclipse.equinox.preferences,
+ org.eclipse.ltk.core.refactoring;bundle-version="3.5.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: JBoss by Red Hat
@@ -28,6 +29,7 @@
org.jboss.tools.cdi.internal.core.impl,
org.jboss.tools.cdi.internal.core.impl.definition,
org.jboss.tools.cdi.internal.core.project.facet,
+ org.jboss.tools.cdi.internal.core.refactoring,
org.jboss.tools.cdi.internal.core.scanner,
org.jboss.tools.cdi.internal.core.scanner.lib,
org.jboss.tools.cdi.internal.core.validation
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreMessages.java 2010-04-02
15:19:07 UTC (rev 21242)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreMessages.java 2010-04-02
16:06:43 UTC (rev 21243)
@@ -25,4 +25,8 @@
public static String CDI_FACET_INSTALL_ABSTRACT_DELEGATE_ERRORS_OCCURED;
public static String CDI_FACET_INSTALL_ABSTRACT_DELEGATE_CHECK_ERROR_LOG_VIEW;
public static String CDI_FACET_INSTALL_ABSTRACT_DELEGATE_ERROR;
+
+ public static String CDI_RENAME_PROCESSOR_OUT_OF_SYNC_FILE;
+ public static String CDI_RENAME_PROCESSOR_ERROR_PHANTOM_FILE;
+ public static String CDI_RENAME_PROCESSOR_ERROR_READ_ONLY_FILE;
}
\ No newline at end of file
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/CDIRenameProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/CDIRenameProcessor.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/CDIRenameProcessor.java 2010-04-02
16:06:43 UTC (rev 21243)
@@ -0,0 +1,296 @@
+/*******************************************************************************
+ * 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.cdi.internal.core.refactoring;
+
+import java.util.ArrayList;
+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;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+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.RefactoringParticipant;
+import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
+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.cdi.core.CDICoreMessages;
+import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.common.el.core.model.ELInvocationExpression;
+import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
+import org.jboss.tools.common.text.ITextSourceReference;
+import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.jst.web.kb.refactoring.RefactorSearcher;
+
+/**
+ * @author Daniel Azarov
+ */
+public abstract class CDIRenameProcessor extends RenameProcessor {
+ 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$
+
+ protected static final RefactoringParticipant[] EMPTY_REF_PARTICIPANT = new
RefactoringParticipant[0];
+
+ protected RefactoringStatus status;
+
+ protected CompositeChange rootChange;
+ protected TextFileChange lastChange;
+ protected IFile declarationFile=null;
+
+ private String newName;
+ private String oldName;
+
+ private CDISearcher searcher = null;
+ protected IBean bean;
+
+ protected CDISearcher getSearcher(){
+ if(searcher == null){
+ searcher = new CDISearcher(declarationFile, getOldName());
+ }
+ return searcher;
+ }
+
+ public void setNewName(String newName){
+ this.newName = newName;
+ }
+
+ protected String getNewName(){
+ return newName;
+ }
+
+ protected void setOldName(String oldName){
+ this.oldName = oldName;
+ }
+
+ public String getOldName(){
+ return oldName;
+ }
+
+ // lets collect all changes for the same files in one MultiTextEdit
+ 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;
+ }
+
+ protected void findDeclarations(IBean bean) throws CoreException{
+ changeDeclarations(bean);
+ }
+
+
+ private boolean isBadLocation(ITextSourceReference location, IFile file){
+ boolean flag=false;
+ return flag;
+ }
+
+ private void changeXMLNode(ITextSourceReference location, IFile file){
+ if(isBadLocation(location, file))
+ return;
+
+ if(!isFileCorrect(file))
+ return;
+
+ String content = null;
+ try {
+ content = FileUtil.readStream(file);
+ } catch (CoreException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+
+ String text = content.substring(location.getStartPosition(),
location.getStartPosition()+location.getLength());
+ if(text.startsWith("<")){ //$NON-NLS-1$
+ int position = text.lastIndexOf("/>"); //$NON-NLS-1$
+ if(position < 0){
+ position = text.lastIndexOf(">"); //$NON-NLS-1$
+ }
+ change(file, location.getStartPosition()+position, 0, "
name=\""+getNewName()+"\""); //$NON-NLS-1$ //$NON-NLS-2$
+ }else{
+ change(file, location.getStartPosition(), location.getLength(), getNewName());
+ }
+ }
+
+ private void changeAnnotation(ITextSourceReference location, IFile file){
+ if(isBadLocation(location, file))
+ return;
+
+ if(!isFileCorrect(file))
+ return;
+
+ String content = null;
+ try {
+ content = FileUtil.readStream(file);
+ } catch (CoreException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+
+ String text = content.substring(location.getStartPosition(),
location.getStartPosition()+location.getLength());
+ int openBracket = text.indexOf("("); //$NON-NLS-1$
+ int openQuote = text.indexOf("\""); //$NON-NLS-1$
+ if(openBracket >= 0){
+ int closeBracket = text.indexOf(")", openBracket); //$NON-NLS-1$
+
+ int equals = text.indexOf("=", openBracket); //$NON-NLS-1$
+ int value = text.indexOf("value", openBracket); //$NON-NLS-1$
+
+ if(closeBracket == openBracket+1){ // empty brackets
+ String newText = "\""+getNewName()+"\""; //$NON-NLS-1$
//$NON-NLS-2$
+ change(file, location.getStartPosition()+openBracket+1, 0, newText);
+ }else if(value > 0){ // construction value="name" found so change name
+ String newText = text.replace(getOldName(), getNewName());
+ change(file, location.getStartPosition(), location.getLength(), newText);
+ }else if(equals > 0){ // other parameters are found
+ String newText = "value=\""+getNewName()+"\",";
//$NON-NLS-1$ //$NON-NLS-2$
+ change(file, location.getStartPosition()+openBracket+1, 0, newText);
+ }else{ // other cases
+ String newText = text.replace(getOldName(), getNewName());
+ change(file, location.getStartPosition(), location.getLength(), newText);
+ }
+ }else if(openQuote >= 0){
+ int closeQuota = text.indexOf("\"", openQuote); //$NON-NLS-1$
+
+ if(closeQuota == openQuote+1){ // empty quotas
+ String newText = "\""+getNewName()+"\""; //$NON-NLS-1$
//$NON-NLS-2$
+ change(file, location.getStartPosition()+openQuote+1, 0, newText);
+ }else{ // the other cases
+ String newText = text.replace(getOldName(), getNewName());
+ change(file, location.getStartPosition(), location.getLength(), newText);
+ }
+ }else{
+ String newText = "(\""+getNewName()+"\")"; //$NON-NLS-1$
//$NON-NLS-2$
+ change(file, location.getStartPosition()+location.getLength(), 0, newText);
+ }
+ }
+
+
+ private void changeDeclarations(IBean bean) throws CoreException{
+ }
+
+ protected void checkDeclarations(IBean bean) throws CoreException{
+ }
+
+ protected boolean isFileCorrect(IFile file){
+ if(!file.isSynchronized(IResource.DEPTH_ZERO)){
+ status.addFatalError(Messages.format(CDICoreMessages.CDI_RENAME_PROCESSOR_OUT_OF_SYNC_FILE,
file.getFullPath().toString()));
+ return false;
+ }else if(file.isPhantom()){
+ status.addFatalError(Messages.format(CDICoreMessages.CDI_RENAME_PROCESSOR_ERROR_PHANTOM_FILE,
file.getFullPath().toString()));
+ return false;
+ }else if(file.isReadOnly()){
+ status.addFatalError(Messages.format(CDICoreMessages.CDI_RENAME_PROCESSOR_ERROR_READ_ONLY_FILE,
file.getFullPath().toString()));
+ return false;
+ }
+ return true;
+ }
+
+
+ protected void renameBean(IProgressMonitor pm, IBean bean)throws CoreException{
+ pm.beginTask("", 3);
+
+ clearChanges();
+
+ findDeclarations(bean);
+
+ if(status.hasFatalError())
+ return;
+
+ pm.worked(1);
+
+ getSearcher().findELReferences();
+
+ pm.done();
+ }
+
+ ArrayList<String> keys = new ArrayList<String>();
+
+ private void clearChanges(){
+ keys.clear();
+ }
+
+ 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 CDISearcher extends RefactorSearcher{
+ public CDISearcher(IFile declarationFile, String oldName){
+ super(declarationFile, oldName);
+ }
+
+ @Override
+ protected boolean isFileCorrect(IFile file) {
+ return CDIRenameProcessor.this.isFileCorrect(file);
+ }
+
+ @Override
+ protected void match(IFile file, int offset, int length) {
+ change(file, offset, length, newName);
+ }
+
+ protected ELInvocationExpression findComponentReference(ELInvocationExpression
invocationExpression){
+ if(bean != null)
+ return 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;
+ }
+
+ @Override
+ protected IProject[] getProjects() {
+ return null;
+ }
+
+ @Override
+ protected IContainer getViewFolder(IProject project) {
+ return null;
+ }
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/CDIRenameProcessor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/RenameNamedBeanProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/RenameNamedBeanProcessor.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/RenameNamedBeanProcessor.java 2010-04-02
16:06:43 UTC (rev 21243)
@@ -0,0 +1,142 @@
+ /*******************************************************************************
+ * Copyright (c) 2008 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.cdi.internal.core.refactoring;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+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.participants.CheckConditionsContext;
+import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
+import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
+import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
+import org.jboss.tools.cdi.core.IBean;
+
+/**
+ * @author Daniel Azarov
+ */
+public class RenameNamedBeanProcessor extends CDIRenameProcessor {
+ private IBean bean;
+ /**
+ * @param component Renamed component
+ */
+ public RenameNamedBeanProcessor(IBean bean) {
+ super();
+ setBean(bean);
+ }
+
+ public IBean getBean() {
+ return bean;
+ }
+
+ public void setBean(IBean bean) {
+ this.bean = bean;
+ setOldName(bean.getName());
+ }
+
+
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor,
org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
+ */
+ @Override
+ public RefactoringStatus checkFinalConditions(IProgressMonitor pm,
+ CheckConditionsContext context) throws CoreException,
+ OperationCanceledException {
+ status = new RefactoringStatus();
+ if(bean != null){
+ checkDeclarations(bean);
+
+ if(status.hasFatalError())
+ return status;
+
+ rootChange = new CompositeChange("Rename @Named Bean");
+
+ renameBean(pm, bean);
+ }
+ return status;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
+ throws CoreException, OperationCanceledException {
+ RefactoringStatus result = new RefactoringStatus();
+ if(bean==null) {
+ result.addFatalError("This is not a @Named Bean");
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#createChange(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public Change createChange(IProgressMonitor pm) throws CoreException,
+ OperationCanceledException {
+
+ return rootChange;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getElements()
+ */
+ @Override
+ public Object[] getElements() {
+ return new IBean[]{bean};
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getIdentifier()
+ */
+ @Override
+ public String getIdentifier() {
+ return getClass().getName();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getProcessorName()
+ */
+ @Override
+ public String getProcessorName() {
+ return "Rename @Named Bean";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#isApplicable()
+ */
+ @Override
+ public boolean isApplicable() throws CoreException {
+ return bean!=null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#loadParticipants(org.eclipse.ltk.core.refactoring.RefactoringStatus,
org.eclipse.ltk.core.refactoring.participants.SharableParticipants)
+ */
+ @Override
+ public RefactoringParticipant[] loadParticipants(RefactoringStatus status,
+ SharableParticipants sharedParticipants) throws CoreException {
+ return EMPTY_REF_PARTICIPANT;
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/RenameNamedBeanProcessor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/META-INF/MANIFEST.MF 2010-04-02 15:19:07 UTC
(rev 21242)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/META-INF/MANIFEST.MF 2010-04-02 16:06:43 UTC
(rev 21243)
@@ -19,7 +19,15 @@
org.eclipse.wst.sse.ui,
org.jboss.tools.jst.web.kb,
org.eclipse.jdt.core;bundle-version="3.5.0",
- org.eclipse.search;bundle-version="3.5.0"
+ org.eclipse.search;bundle-version="3.5.0",
+ org.eclipse.wst.sse.core;bundle-version="1.1.400",
+ org.eclipse.ltk.ui.refactoring;bundle-version="3.4.100",
+ org.eclipse.ui.ide;bundle-version="3.5.0",
+ org.jboss.tools.common.model;bundle-version="2.0.0",
+ org.jboss.tools.common.model.ui;bundle-version="2.0.0",
+ org.jboss.tools.jst.web.ui;bundle-version="2.0.0",
+ org.eclipse.core.expressions;bundle-version="3.4.100",
+ org.eclipse.ltk.core.refactoring;bundle-version="3.5.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: %Bundle-Vendor.0
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.ui/plugin.xml
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/plugin.xml 2010-04-02 15:19:07 UTC (rev
21242)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/plugin.xml 2010-04-02 16:06:43 UTC (rev
21243)
@@ -106,4 +106,13 @@
nature="org.jboss.tools.cdi.core.cdinature">
</queryParticipant>
</extension>
+ <!-- Refactorng -->
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+
class="org.jboss.tools.cdi.ui.refactoring.CDIRefactorContributionFactory"
+ locationURI="popup:org.eclipse.ui.popup.any?after=save">
+ </menuContribution>
+ </extension>
+
</plugin>
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2010-04-02
15:19:07 UTC (rev 21242)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2010-04-02
16:06:43 UTC (rev 21243)
@@ -22,4 +22,9 @@
public static String INJECTION_POINT_LABEL_PROVIDER;
public static String CDI_UI_IMAGESBASE_URL_FOR_IMAGE_REGISTRY_CANNOT_BE_NULL;
public static String CDI_UI_IMAGESIMAGE_NAME_CANNOT_BE_NULL;
+
+ public static String CDI_REFACTOR_CONTRIBUTOR_MENU_NAME;
+ public static String CDI_REFACTOR_CONTRIBUTOR_ERROR;
+ public static String CDI_REFACTOR_CONTRIBUTOR_RENAME_NAMED_BEAN_ACTION_NAME;
+ public static String RENAME_NAMED_BEAN_WIZARD_FIELD_NAME;
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2010-04-02
15:19:07 UTC (rev 21242)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2010-04-02
16:06:43 UTC (rev 21243)
@@ -11,4 +11,8 @@
INJECTION_POINT_LABEL_PROVIDER=Injected class
CDI_UI_IMAGESBASE_URL_FOR_IMAGE_REGISTRY_CANNOT_BE_NULL=Base url for image registry
cannot be null.
-CDI_UI_IMAGESIMAGE_NAME_CANNOT_BE_NULL=Image name cannot be null.
\ No newline at end of file
+CDI_UI_IMAGESIMAGE_NAME_CANNOT_BE_NULL=Image name cannot be null.
+CDI_REFACTOR_CONTRIBUTOR_MENU_NAME=CDI Refactor
+CDI_REFACTOR_CONTRIBUTOR_ERROR=Error
+CDI_REFACTOR_CONTRIBUTOR_RENAME_NAMED_BEAN_ACTION_NAME=Rename Named Bean
+RENAME_NAMED_BEAN_WIZARD_FIELD_NAME=@Named Bean Name
\ No newline at end of file
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/CDIRefactorContributionFactory.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/CDIRefactorContributionFactory.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/CDIRefactorContributionFactory.java 2010-04-02
16:06:43 UTC (rev 21243)
@@ -0,0 +1,200 @@
+/*******************************************************************************
+ * 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.cdi.ui.refactoring;
+
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring;
+import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.internal.services.IWorkbenchLocationService;
+import org.eclipse.ui.menus.AbstractContributionFactory;
+import org.eclipse.ui.menus.IContributionRoot;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.services.IServiceLocator;
+import org.jboss.tools.cdi.core.CDICoreNature;
+import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.ICDIProject;
+import org.jboss.tools.cdi.internal.core.refactoring.RenameNamedBeanProcessor;
+import org.jboss.tools.cdi.ui.CDIUIMessages;
+import org.jboss.tools.cdi.ui.CDIUIPlugin;
+import org.jboss.tools.common.model.util.EclipseJavaUtil;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+
+/**
+ * @author Daniel Azarov
+ */
+public class CDIRefactorContributionFactory extends AbstractContributionFactory {
+ private static final String ANNOTATION_NAMED = "javax.inject.Named";
//$NON-NLS-1$
+ private static final String JAVA_EXT = "java"; //$NON-NLS-1$
+
+ static private IFile editorFile;
+ private IEditorPart editor;
+ private Shell shell;
+
+ public CDIRefactorContributionFactory(){
+ super("","");
+ }
+
+ public CDIRefactorContributionFactory(String location, String namespace){
+ super(location, namespace);
+ }
+
+ @Override
+ public void createContributionItems(IServiceLocator serviceLocator,
+ IContributionRoot additions) {
+
+ if(serviceLocator.hasService(IWorkbenchLocationService.class)){
+ IWorkbenchLocationService service =
(IWorkbenchLocationService)serviceLocator.getService(IWorkbenchLocationService.class);
+ editor = service.getWorkbenchWindow().getActivePage().getActiveEditor();
+ shell = service.getWorkbench().getActiveWorkbenchWindow().getShell();
+
+ if(!(editor.getEditorInput() instanceof FileEditorInput))
+ return;
+
+ FileEditorInput input = (FileEditorInput)editor.getEditorInput();
+
+ editorFile = input.getFile();
+ String ext = editorFile.getFileExtension();
+
+ if (!JAVA_EXT.equalsIgnoreCase(ext) )
+ return;
+
+ if(CDICorePlugin.getCDI(editorFile.getProject(), true) == null)
+ return;
+
+ MenuManager mm = new MenuManager(CDIUIMessages.CDI_REFACTOR_CONTRIBUTOR_MENU_NAME);
+ mm.setVisible(true);
+
+ boolean separatorIsAdded = false;
+
+ if(JAVA_EXT.equalsIgnoreCase(ext)){
+ IBean bean = getBean(editorFile);
+ if(bean != null){
+ mm.add(new RenameNamedBeanAction());
+
+ additions.addContributionItem(new Separator(), null);
+ additions.addContributionItem(mm, null);
+ separatorIsAdded = true;
+ }
+ }
+
+ }
+ }
+
+ private IBean getBean(IFile file){
+ IProject project = file.getProject();
+ CDICoreNature cdiNature = CDICorePlugin.getCDI(file.getProject(), true);
+ if(cdiNature == null)
+ return null;
+
+ ICDIProject cdiProject = cdiNature.getDelegate();
+
+ if(cdiProject == null)
+ return null;
+
+ Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
+
+ for(IBean bean : beans){
+ if(bean.getName() != null)
+ return bean;
+ }
+
+ return null;
+ }
+
+ private IAnnotation getNamedAnnotation(IFile file){
+ try{
+ ICompilationUnit unit = getCompilationUnit(file);
+ for(IType type : unit.getAllTypes()){
+ for(IAnnotation annotation : type.getAnnotations()){
+ if(EclipseJavaUtil.resolveType(type,
annotation.getElementName()).equals(ANNOTATION_NAMED))
+ return annotation;
+ }
+ }
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ return null;
+ }
+
+ private ICompilationUnit getCompilationUnit(IFile file) throws CoreException {
+ IProject project = file.getProject();
+ IJavaProject javaProject = (IJavaProject)project.getNature(JavaCore.NATURE_ID);
+ for (IResource resource : EclipseResourceUtil.getJavaSourceRoots(project)) {
+ if(resource.getFullPath().isPrefixOf(file.getFullPath())) {
+ IPath path =
file.getFullPath().removeFirstSegments(resource.getFullPath().segmentCount());
+ IJavaElement element = javaProject.findElement(path);
+ if(element instanceof ICompilationUnit) {
+ return (ICompilationUnit)element;
+ }
+ }
+ }
+ return null;
+ }
+
+ private static void saveAndBuild(){
+ if(!CDIUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().saveAllEditors(true))
+ return;
+
+ try {
+ Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
+ } catch (InterruptedException e) {
+ // do nothing
+ }
+ }
+
+ public static void invokeRenameNamedBeanWizard(IBean bean, Shell activeShell) {
+ saveAndBuild();
+
+ RenameNamedBeanProcessor processor = new RenameNamedBeanProcessor(bean);
+ RenameRefactoring refactoring = new RenameRefactoring(processor);
+ RenameNamedBeanWizard wizard = new RenameNamedBeanWizard(refactoring, bean);
+ RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
+ try {
+ String titleForFailedChecks = CDIUIMessages.CDI_REFACTOR_CONTRIBUTOR_ERROR;
+ op.run(activeShell, titleForFailedChecks);
+ } catch (final InterruptedException irex) {
+ // operation was canceled
+ }
+ }
+
+ class RenameNamedBeanAction extends Action{
+ public RenameNamedBeanAction(){
+ super(CDIUIMessages.CDI_REFACTOR_CONTRIBUTOR_RENAME_NAMED_BEAN_ACTION_NAME);
+ }
+
+ public void run(){
+ saveAndBuild();
+
+ IBean bean = getBean(editorFile);
+ invokeRenameNamedBeanWizard(bean, shell);
+ }
+ }
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/CDIRefactorContributionFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/RenameNamedBeanWizard.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/RenameNamedBeanWizard.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/RenameNamedBeanWizard.java 2010-04-02
16:06:43 UTC (rev 21243)
@@ -0,0 +1,119 @@
+ /*******************************************************************************
+ * Copyright (c) 2008 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.cdi.ui.refactoring;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.ltk.core.refactoring.Refactoring;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
+import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.internal.core.refactoring.RenameNamedBeanProcessor;
+import org.jboss.tools.cdi.ui.CDIUIMessages;
+import org.jboss.tools.common.ui.IValidator;
+import org.jboss.tools.common.ui.widget.editor.CompositeEditor;
+import org.jboss.tools.common.ui.widget.editor.IFieldEditor;
+import org.jboss.tools.common.ui.widget.editor.IFieldEditorFactory;
+
+/**
+ * @author Daniel Azarov
+ */
+public class RenameNamedBeanWizard extends RefactoringWizard {
+
+ private IBean bean;
+ private String componentName;
+ private IFieldEditor editor;
+
+ public RenameNamedBeanWizard(Refactoring refactoring, IBean bean) {
+ super(refactoring, WIZARD_BASED_USER_INTERFACE);
+ this.bean = bean;
+ if(bean != null){
+
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.ui.refactoring.RefactoringWizard#addUserInputPages()
+ */
+ @Override
+ protected void addUserInputPages() {
+ setDefaultPageTitle(getRefactoring().getName());
+ RenameNamedBeanProcessor processor= (RenameNamedBeanProcessor)
getRefactoring().getAdapter(RenameNamedBeanProcessor.class);
+ addPage(new RenameNamedBeanWizardPage(processor));
+ }
+
+ class RenameNamedBeanWizardPage extends UserInputWizardPage{
+ private RenameNamedBeanProcessor processor;
+
+ public RenameNamedBeanWizardPage(RenameNamedBeanProcessor processor){
+ super("");
+ this.processor = processor;
+ }
+
+ public void createControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NULL);
+ container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 2;
+
+ String defaultName = bean.getName();
+ editor = IFieldEditorFactory.INSTANCE.createTextEditor(componentName,
CDIUIMessages.RENAME_NAMED_BEAN_WIZARD_FIELD_NAME, defaultName);
+ editor.doFillIntoGrid(container);
+
+ ((CompositeEditor)editor).addPropertyChangeListener(new
PropertyChangeListener(){
+ public void propertyChange(PropertyChangeEvent evt){
+ validatePage();
+ }
+ });
+ setControl(container);
+ setPageComplete(false);
+ }
+
+ protected final void validatePage() {
+ RefactoringStatus status= new RefactoringStatus();
+ setPageComplete(status);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.ui.refactoring.UserInputWizardPage#performFinish()
+ */
+ protected boolean performFinish() {
+
+ initializeRefactoring();
+ return super.performFinish();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.ui.refactoring.UserInputWizardPage#getNextPage()
+ */
+ public IWizardPage getNextPage() {
+ initializeRefactoring();
+ return super.getNextPage();
+ }
+
+ private void initializeRefactoring() {
+ processor.setNewName(editor.getValueAsString());
+ }
+
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/RenameNamedBeanWizard.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/ELRenameProcessor.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/ELRenameProcessor.java 2010-04-02
15:19:07 UTC (rev 21242)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/ELRenameProcessor.java 2010-04-02
16:06:43 UTC (rev 21243)
@@ -31,6 +31,7 @@
import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
import org.jboss.tools.common.model.project.ProjectHome;
import org.jboss.tools.common.text.ITextSourceReference;
+import org.jboss.tools.jst.web.kb.refactoring.RefactorSearcher;
/**
* @author Daniel Azarov
Deleted:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RefactorSearcher.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RefactorSearcher.java 2010-04-02
15:19:07 UTC (rev 21242)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RefactorSearcher.java 2010-04-02
16:06:43 UTC (rev 21243)
@@ -1,493 +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.jsf.el.refactoring;
-
-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.jboss.tools.common.el.core.ELCorePlugin;
-import org.jboss.tools.common.el.core.ELReference;
-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.ELContext;
-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.SimpleELContext;
-import org.jboss.tools.common.el.core.resolver.Var;
-import org.jboss.tools.common.model.util.EclipseResourceUtil;
-import org.jboss.tools.common.util.FileUtil;
-import org.jboss.tools.jst.web.kb.PageContextFactory;
-
-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;
-
- //startStatistics();
-
- IProject[] projects = getProjects();
- for (IProject project : projects) {
- if(project == null) continue;
-
- if(!containsInSearchScope(project))
- continue;
-
- updateEnvironment(project);
-
- 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);
- }
- //stopStatistic();
- }
-
- protected void updateEnvironment(IProject 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){
- ELCorePlugin.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){
- ELCorePlugin.getDefault().logError(ex);
- }
- }
-
- private String getFileContent(IFile file){
- try {
- return FileUtil.readStream(file);
- //collectStatistic(content.length());
- } catch (CoreException e) {
- ELCorePlugin.getDefault().logError(e);
- }
- return null;
- }
-
- private void scanForJava(IFile file){
- if(isFileCorrect(file)) {
- if(PROPERTIES_EXT.equalsIgnoreCase(file.getFileExtension())){
- if(file.getName().equals(SEAM_PROPERTIES_FILE)){
- String content = getFileContent(file);
- scanProperties(file, content);
- }else
- searchInCach(file);
- } else if (JAVA_EXT.equalsIgnoreCase(file.getFileExtension())
- || JSP_EXT.equalsIgnoreCase(file.getFileExtension())
- || XHTML_EXT.equalsIgnoreCase(file.getFileExtension())
- || XML_EXT.equalsIgnoreCase(file.getFileExtension())) {
- searchInCach(file);
- }
- }
- }
-
- private void scan(IFile file){
- if(isFileCorrect(file)) {
- String ext = file.getFileExtension();
- if(XML_EXT.equalsIgnoreCase(ext)
- || XHTML_EXT.equalsIgnoreCase(ext)
- || JSP_EXT.equalsIgnoreCase(ext)) {
- searchInCach(file);
- }
- }
- }
-
- private void searchInCach(IFile file){
- ELContext context = PageContextFactory.createPageContext(file);
-
- if(context == null)
- return;
-
- ELReference[] references = context.getELReferences();
- ELResolver[] resolvers = context.getElResolvers();
-
- if(javaElement != null){
- for(ELReference reference : references){
- int offset = reference.getStartPosition();
- for(ELExpression operand : reference.getEl()){
- for (ELResolver resolver : resolvers) {
- if (!(resolver instanceof ELCompletionEngine))
- continue;
-
- ELResolution resolution = resolver.resolve(context, operand, offset);
-
- if(resolution == null)
- continue;
-
- List<ELSegment> segments =
resolution.findSegmentsByJavaElement(javaElement);
-
- for(ELSegment segment : segments){
- match(file, offset+segment.getSourceReference().getStartPosition(),
segment.getSourceReference().getLength());
- }
- }
- }
- }
- }else{
- for(ELReference reference : references){
- int offset = reference.getStartPosition();
- ELExpression[] expressions = reference.getEl();
- for(ELExpression operand : expressions){
- if(operand instanceof ELInvocationExpression){
- ELInvocationExpression expression =
findComponentReference((ELInvocationExpression)operand);
- if(expression != null){
- checkMatch(file, expression, offset+getOffset(expression),
getLength(expression));
- }
- }
- }
- }
- }
-
- }
-
-
- // looking for component references in EL
- private void scanString(IFile file, String string, int offset) {
- int startEl = string.indexOf("#{"); //$NON-NLS-1$
- if(startEl<0)
- 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){
- checkMatch(file, expression, offset+getOffset(expression), getLength(expression));
- }
- }
- }
- }
- }
-
- protected int getOffset(ELInvocationExpression expression){
- if(expression instanceof ELPropertyInvocation){
- ELPropertyInvocation pi = (ELPropertyInvocation)expression;
-
- if(pi.getName() != null)
- return pi.getName().getStart();
- }else if(expression instanceof ELMethodInvocation){
- ELMethodInvocation mi = (ELMethodInvocation)expression;
-
- if(mi.getName() != null)
- return mi.getName().getStart();
- }
- return 0;
- }
-
- private int getLength(ELInvocationExpression expression){
- if(expression instanceof ELPropertyInvocation){
- ELPropertyInvocation pi = (ELPropertyInvocation)expression;
-
- if(pi.getName() != null)
- return pi.getName().getLength();
- }else if(expression instanceof ELMethodInvocation){
- ELMethodInvocation mi = (ELMethodInvocation)expression;
-
- if(mi.getName() != null)
- 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());
- }
- }
-
- lastToken = token;
- offset += token.length();
- }
- }
-
- protected ELInvocationExpression findComponentReference(ELInvocationExpression
invocationExpression){
- return invocationExpression;
- }
-
- protected abstract boolean isFileCorrect(IFile file);
-
- protected abstract void match(IFile file, int offset, int length);
-
- protected void checkMatch(IFile file, ELExpression operand, int offset, int length){
- if(javaElement != null && operand != null)
- resolve(file, operand, offset-getOffset((ELInvocationExpression)operand));
- else
- match(file, offset, length);
- }
-
- // TODO: move to util class
- public static 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 static boolean isSetter(IMethod method) {
- String name = method.getElementName();
- int numberOfParameters = method.getNumberOfParameters();
-
- return ((name.startsWith(SET) && !name.equals(SET)) &&
numberOfParameters == 1);
- }
-
- // TODO: move to util class
- public static String getPropertyName(IMethod method, String methodName){
- if (isGetter(method) || isSetter(method)) {
- StringBuffer name = new StringBuffer(methodName);
- if(methodName.startsWith("i")) { //$NON-NLS-1$
- name.delete(0, 2);
- } else {
- name.delete(0, 3);
- }
- if(name.length()<2 || Character.isLowerCase(name.charAt(1))) {
- name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
- }
- String propertyName = name.toString();
- return propertyName;
- }
- return methodName;
- }
-
- public static String getPropertyName(IType method, String className){
- StringBuffer name = new StringBuffer(className);
- if(name.length()<2 || Character.isLowerCase(name.charAt(1))) {
- name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
- }
- String propertyName = name.toString();
- return propertyName;
- }
-
- 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;
- }
-
- protected void resolve(IFile file, ELExpression operand, int offset) {
- 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, offset,
- resolver);
-
- context.setVars(vars);
-
- ELResolution resolution = resolver.resolve(context, operand, offset);
- if(resolution!=null) {
- List<ELSegment> segments = resolution.findSegmentsByJavaElement(javaElement);
-
- for(ELSegment segment : segments){
- match(file, offset+segment.getSourceReference().getStartPosition(),
segment.getSourceReference().getLength());
- }
- }
- }
- }
- // performance measure
-// private int totalSize = 0;
-// private int filesNumber = 0;
-// private long startTime = 0;
-// private long stopTime = 0;
-// private long startMem = 0;
-// private long stopMem = 0;
-//
-// private boolean log = false;
-//
-// private void clearHistory(){
-// totalSize = 0;
-// filesNumber = 0;
-// startTime = 0;
-// stopTime = 0;
-// startMem = 0;
-// stopMem = 0;
-// }
-//
-// private void startStatistics(){
-// clearHistory();
-// startTime = System.currentTimeMillis();
-// startMem = Runtime.getRuntime().freeMemory();
-// }
-//
-// private void stopStatistic(){
-// stopTime = System.currentTimeMillis();
-// stopMem = Runtime.getRuntime().freeMemory();
-// printELSearchStatistics();
-// }
-//
-// private void collectStatistic(int fileSize){
-// filesNumber++;
-// totalSize += fileSize;
-// }
-//
-// private void printELSearchStatistics(){
-// if(log){
-// System.out.println("EL Search"); //$NON-NLS-1$
-// System.out.println("Total files number: "+getFilesNumber());
//$NON-NLS-1$
-// System.out.println("Total files size: "+getTotlalFilesSize()+"
Mb"); //$NON-NLS-1$ $NON-NLS-2$
-// System.out.println("Memory usage size: "+getTotlalMemorySize()+"
Mb"); //$NON-NLS-1$ $NON-NLS-2$
-// System.out.println("Free Memory size: "+getRestMemorySize()+"
Mb"); //$NON-NLS-1$ $NON-NLS-2$
-// System.out.println("Total time: "+getTotalTime()+" sec");
//$NON-NLS-1$ $NON-NLS-2$
-// }
-// }
-//
-// private double getTotlalFilesSize(){
-// return (double)totalSize/(1024*1025);
-// }
-//
-// private double getTotlalMemorySize(){
-// return (double)(startMem-stopMem)/(1024*1025);
-// }
-//
-// private double getRestMemorySize(){
-// return (double)stopMem/(1024*1025);
-// }
-//
-// private int getFilesNumber(){
-// return filesNumber;
-// }
-//
-// private double getTotalTime(){
-// return (double)(stopTime - startTime)/1000;
-// }
-
-}
\ No newline at end of file
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/ELReferencesQueryParticipant.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/ELReferencesQueryParticipant.java 2010-04-02
15:19:07 UTC (rev 21242)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/ELReferencesQueryParticipant.java 2010-04-02
16:06:43 UTC (rev 21243)
@@ -30,7 +30,7 @@
import org.jboss.tools.common.model.project.ProjectHome;
import org.jboss.tools.jsf.el.refactoring.ELProjectSetExtension;
import org.jboss.tools.jsf.el.refactoring.ProjectsSet;
-import org.jboss.tools.jsf.el.refactoring.RefactorSearcher;
+import org.jboss.tools.jst.web.kb.refactoring.RefactorSearcher;
public class ELReferencesQueryParticipant implements IQueryParticipant{
private ELSearcher searcher;
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/RenameMethodParticipant.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/RenameMethodParticipant.java 2010-04-02
15:19:07 UTC (rev 21242)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/RenameMethodParticipant.java 2010-04-02
16:06:43 UTC (rev 21243)
@@ -35,8 +35,8 @@
import org.jboss.tools.common.model.project.ProjectHome;
import org.jboss.tools.jsf.el.refactoring.ELProjectSetExtension;
import org.jboss.tools.jsf.el.refactoring.ProjectsSet;
-import org.jboss.tools.jsf.el.refactoring.RefactorSearcher;
import org.jboss.tools.jsf.ui.JsfUIMessages;
+import org.jboss.tools.jst.web.kb.refactoring.RefactorSearcher;
public class RenameMethodParticipant extends RenameParticipant{
private IJavaElement element;
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF 2010-04-02 15:19:07
UTC (rev 21242)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF 2010-04-02 16:06:43
UTC (rev 21243)
@@ -39,5 +39,6 @@
org.jboss.tools.jst.web.kb.internal.taglib,
org.jboss.tools.jst.web.kb.internal.taglib.composite,
org.jboss.tools.jst.web.kb.internal.validation,
+ org.jboss.tools.jst.web.kb.refactoring,
org.jboss.tools.jst.web.kb.taglib,
org.jboss.tools.jst.web.kb.validation
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java 2010-04-02
16:06:43 UTC (rev 21243)
@@ -0,0 +1,493 @@
+/*******************************************************************************
+ * 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.jst.web.kb.refactoring;
+
+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.jboss.tools.common.el.core.ELCorePlugin;
+import org.jboss.tools.common.el.core.ELReference;
+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.ELContext;
+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.SimpleELContext;
+import org.jboss.tools.common.el.core.resolver.Var;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.jst.web.kb.PageContextFactory;
+
+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;
+
+ //startStatistics();
+
+ IProject[] projects = getProjects();
+ for (IProject project : projects) {
+ if(project == null) continue;
+
+ if(!containsInSearchScope(project))
+ continue;
+
+ updateEnvironment(project);
+
+ 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);
+ }
+ //stopStatistic();
+ }
+
+ protected void updateEnvironment(IProject 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){
+ ELCorePlugin.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){
+ ELCorePlugin.getDefault().logError(ex);
+ }
+ }
+
+ private String getFileContent(IFile file){
+ try {
+ return FileUtil.readStream(file);
+ //collectStatistic(content.length());
+ } catch (CoreException e) {
+ ELCorePlugin.getDefault().logError(e);
+ }
+ return null;
+ }
+
+ private void scanForJava(IFile file){
+ if(isFileCorrect(file)) {
+ if(PROPERTIES_EXT.equalsIgnoreCase(file.getFileExtension())){
+ if(file.getName().equals(SEAM_PROPERTIES_FILE)){
+ String content = getFileContent(file);
+ scanProperties(file, content);
+ }else
+ searchInCach(file);
+ } else if (JAVA_EXT.equalsIgnoreCase(file.getFileExtension())
+ || JSP_EXT.equalsIgnoreCase(file.getFileExtension())
+ || XHTML_EXT.equalsIgnoreCase(file.getFileExtension())
+ || XML_EXT.equalsIgnoreCase(file.getFileExtension())) {
+ searchInCach(file);
+ }
+ }
+ }
+
+ private void scan(IFile file){
+ if(isFileCorrect(file)) {
+ String ext = file.getFileExtension();
+ if(XML_EXT.equalsIgnoreCase(ext)
+ || XHTML_EXT.equalsIgnoreCase(ext)
+ || JSP_EXT.equalsIgnoreCase(ext)) {
+ searchInCach(file);
+ }
+ }
+ }
+
+ private void searchInCach(IFile file){
+ ELContext context = PageContextFactory.createPageContext(file);
+
+ if(context == null)
+ return;
+
+ ELReference[] references = context.getELReferences();
+ ELResolver[] resolvers = context.getElResolvers();
+
+ if(javaElement != null){
+ for(ELReference reference : references){
+ int offset = reference.getStartPosition();
+ for(ELExpression operand : reference.getEl()){
+ for (ELResolver resolver : resolvers) {
+ if (!(resolver instanceof ELCompletionEngine))
+ continue;
+
+ ELResolution resolution = resolver.resolve(context, operand, offset);
+
+ if(resolution == null)
+ continue;
+
+ List<ELSegment> segments =
resolution.findSegmentsByJavaElement(javaElement);
+
+ for(ELSegment segment : segments){
+ match(file, offset+segment.getSourceReference().getStartPosition(),
segment.getSourceReference().getLength());
+ }
+ }
+ }
+ }
+ }else{
+ for(ELReference reference : references){
+ int offset = reference.getStartPosition();
+ ELExpression[] expressions = reference.getEl();
+ for(ELExpression operand : expressions){
+ if(operand instanceof ELInvocationExpression){
+ ELInvocationExpression expression =
findComponentReference((ELInvocationExpression)operand);
+ if(expression != null){
+ checkMatch(file, expression, offset+getOffset(expression),
getLength(expression));
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+
+ // looking for component references in EL
+ private void scanString(IFile file, String string, int offset) {
+ int startEl = string.indexOf("#{"); //$NON-NLS-1$
+ if(startEl<0)
+ 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){
+ checkMatch(file, expression, offset+getOffset(expression), getLength(expression));
+ }
+ }
+ }
+ }
+ }
+
+ protected int getOffset(ELInvocationExpression expression){
+ if(expression instanceof ELPropertyInvocation){
+ ELPropertyInvocation pi = (ELPropertyInvocation)expression;
+
+ if(pi.getName() != null)
+ return pi.getName().getStart();
+ }else if(expression instanceof ELMethodInvocation){
+ ELMethodInvocation mi = (ELMethodInvocation)expression;
+
+ if(mi.getName() != null)
+ return mi.getName().getStart();
+ }
+ return 0;
+ }
+
+ private int getLength(ELInvocationExpression expression){
+ if(expression instanceof ELPropertyInvocation){
+ ELPropertyInvocation pi = (ELPropertyInvocation)expression;
+
+ if(pi.getName() != null)
+ return pi.getName().getLength();
+ }else if(expression instanceof ELMethodInvocation){
+ ELMethodInvocation mi = (ELMethodInvocation)expression;
+
+ if(mi.getName() != null)
+ 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());
+ }
+ }
+
+ lastToken = token;
+ offset += token.length();
+ }
+ }
+
+ protected ELInvocationExpression findComponentReference(ELInvocationExpression
invocationExpression){
+ return invocationExpression;
+ }
+
+ protected abstract boolean isFileCorrect(IFile file);
+
+ protected abstract void match(IFile file, int offset, int length);
+
+ protected void checkMatch(IFile file, ELExpression operand, int offset, int length){
+ if(javaElement != null && operand != null)
+ resolve(file, operand, offset-getOffset((ELInvocationExpression)operand));
+ else
+ match(file, offset, length);
+ }
+
+ // TODO: move to util class
+ public static 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 static boolean isSetter(IMethod method) {
+ String name = method.getElementName();
+ int numberOfParameters = method.getNumberOfParameters();
+
+ return ((name.startsWith(SET) && !name.equals(SET)) &&
numberOfParameters == 1);
+ }
+
+ // TODO: move to util class
+ public static String getPropertyName(IMethod method, String methodName){
+ if (isGetter(method) || isSetter(method)) {
+ StringBuffer name = new StringBuffer(methodName);
+ if(methodName.startsWith("i")) { //$NON-NLS-1$
+ name.delete(0, 2);
+ } else {
+ name.delete(0, 3);
+ }
+ if(name.length()<2 || Character.isLowerCase(name.charAt(1))) {
+ name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
+ }
+ String propertyName = name.toString();
+ return propertyName;
+ }
+ return methodName;
+ }
+
+ public static String getPropertyName(IType method, String className){
+ StringBuffer name = new StringBuffer(className);
+ if(name.length()<2 || Character.isLowerCase(name.charAt(1))) {
+ name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
+ }
+ String propertyName = name.toString();
+ return propertyName;
+ }
+
+ 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;
+ }
+
+ protected void resolve(IFile file, ELExpression operand, int offset) {
+ 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, offset,
+ resolver);
+
+ context.setVars(vars);
+
+ ELResolution resolution = resolver.resolve(context, operand, offset);
+ if(resolution!=null) {
+ List<ELSegment> segments = resolution.findSegmentsByJavaElement(javaElement);
+
+ for(ELSegment segment : segments){
+ match(file, offset+segment.getSourceReference().getStartPosition(),
segment.getSourceReference().getLength());
+ }
+ }
+ }
+ }
+ // performance measure
+// private int totalSize = 0;
+// private int filesNumber = 0;
+// private long startTime = 0;
+// private long stopTime = 0;
+// private long startMem = 0;
+// private long stopMem = 0;
+//
+// private boolean log = false;
+//
+// private void clearHistory(){
+// totalSize = 0;
+// filesNumber = 0;
+// startTime = 0;
+// stopTime = 0;
+// startMem = 0;
+// stopMem = 0;
+// }
+//
+// private void startStatistics(){
+// clearHistory();
+// startTime = System.currentTimeMillis();
+// startMem = Runtime.getRuntime().freeMemory();
+// }
+//
+// private void stopStatistic(){
+// stopTime = System.currentTimeMillis();
+// stopMem = Runtime.getRuntime().freeMemory();
+// printELSearchStatistics();
+// }
+//
+// private void collectStatistic(int fileSize){
+// filesNumber++;
+// totalSize += fileSize;
+// }
+//
+// private void printELSearchStatistics(){
+// if(log){
+// System.out.println("EL Search"); //$NON-NLS-1$
+// System.out.println("Total files number: "+getFilesNumber());
//$NON-NLS-1$
+// System.out.println("Total files size: "+getTotlalFilesSize()+"
Mb"); //$NON-NLS-1$ $NON-NLS-2$
+// System.out.println("Memory usage size: "+getTotlalMemorySize()+"
Mb"); //$NON-NLS-1$ $NON-NLS-2$
+// System.out.println("Free Memory size: "+getRestMemorySize()+"
Mb"); //$NON-NLS-1$ $NON-NLS-2$
+// System.out.println("Total time: "+getTotalTime()+" sec");
//$NON-NLS-1$ $NON-NLS-2$
+// }
+// }
+//
+// private double getTotlalFilesSize(){
+// return (double)totalSize/(1024*1025);
+// }
+//
+// private double getTotlalMemorySize(){
+// return (double)(startMem-stopMem)/(1024*1025);
+// }
+//
+// private double getRestMemorySize(){
+// return (double)stopMem/(1024*1025);
+// }
+//
+// private int getFilesNumber(){
+// return filesNumber;
+// }
+//
+// private double getTotalTime(){
+// return (double)(stopTime - startTime)/1000;
+// }
+
+}
\ 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 2010-04-02
15:19:07 UTC (rev 21242)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRefactorSearcher.java 2010-04-02
16:06:43 UTC (rev 21243)
@@ -28,7 +28,7 @@
import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
import org.jboss.tools.common.el.core.resolver.SimpleELContext;
import org.jboss.tools.common.el.core.resolver.Var;
-import org.jboss.tools.jsf.el.refactoring.RefactorSearcher;
+import org.jboss.tools.jst.web.kb.refactoring.RefactorSearcher;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.ISeamXmlComponentDeclaration;