Author: dazarov
Date: 2009-11-16 02:09:51 -0500 (Mon, 16 Nov 2009)
New Revision: 18689
Added:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ElUIMessages.java
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ElUiPlugin.java
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/refactoring/ELRefactorContributionFactory.java
Removed:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/Activator.java
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ElUiCoreMessages.java
Modified:
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/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/refactoring/RenameMethodParticipant.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4990
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-11-14
14:59:31 UTC (rev 18688)
+++ trunk/common/plugins/org.jboss.tools.common.el.ui/META-INF/MANIFEST.MF 2009-11-16
07:09:51 UTC (rev 18689)
@@ -6,7 +6,7 @@
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
+Bundle-Activator: org.jboss.tools.common.el.ui.ElUiPlugin
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.jboss.tools.common.el.core;bundle-version="2.0.0",
@@ -15,7 +15,12 @@
org.jboss.tools.common.model.ui;bundle-version="2.0.0",
org.eclipse.ltk.core.refactoring;bundle-version="3.5.0",
org.eclipse.jdt.ui;bundle-version="3.5.0",
- org.eclipse.search;bundle-version="3.5.0"
+ org.eclipse.search;bundle-version="3.5.0",
+ org.eclipse.ui.ide;bundle-version="3.5.0",
+ org.jboss.tools.jst.web.ui;bundle-version="2.0.0",
+ org.eclipse.jface.text;bundle-version="3.5.0",
+ org.eclipse.core.expressions;bundle-version="3.4.100",
+ org.eclipse.ltk.ui.refactoring;bundle-version="3.4.100"
Bundle-Vendor: %Bundle-Vendor.0
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: org.jboss.tools.vpe.resref.core
Deleted:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/Activator.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/Activator.java 2009-11-14
14:59:31 UTC (rev 18688)
+++
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/Activator.java 2009-11-16
07:09:51 UTC (rev 18689)
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * 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.common.el.ui;
-
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class Activator extends AbstractUIPlugin {
-
- // The plug-in ID
- public static final String PLUGIN_ID = "org.jboss.tools.common.el.ui";
//$NON-NLS-1$
-
- // The shared instance
- private static Activator plugin;
-
- /**
- * The constructor
- */
- public Activator() {
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
- */
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
- }
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static Activator getDefault() {
- return plugin;
- }
-
-}
Copied:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ElUIMessages.java
(from rev 18131,
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/ElUIMessages.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ElUIMessages.java 2009-11-16
07:09:51 UTC (rev 18689)
@@ -0,0 +1,22 @@
+package org.jboss.tools.common.el.ui;
+
+import org.eclipse.osgi.util.NLS;
+
+public class ElUIMessages {
+ private static final String BUNDLE_NAME =
"org.jboss.tools.common.el.ui.messages"; //$NON-NLS-1$
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, ElUIMessages.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;
+ public static String RENAME_METHOD_PARTICIPANT_UPDATE_METHOD_REFERENCES;
+ public static String RESOURCE_BUNDLES_RENAME_PARTICIPANT_UPDATE_BUNDLE_REFERENCES;
+
+ public static String REFACTOR_CONTRIBUTOR_MAIN_MENU;
+ public static String REFACTOR_CONTRIBUTOR_RENAME_EL_VARIABLE;
+}
\ 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/ElUIMessages.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
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 2009-11-14
14:59:31 UTC (rev 18688)
+++
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ElUiCoreMessages.java 2009-11-16
07:09:51 UTC (rev 18689)
@@ -1,19 +0,0 @@
-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;
- public static String RENAME_METHOD_PARTICIPANT_UPDATE_METHOD_REFERENCES;
-
-}
\ No newline at end of file
Copied:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ElUiPlugin.java
(from rev 17542,
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/Activator.java)
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ElUiPlugin.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ElUiPlugin.java 2009-11-16
07:09:51 UTC (rev 18689)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * 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.common.el.ui;
+
+import org.jboss.tools.common.log.BaseUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class ElUiPlugin extends BaseUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.jboss.tools.common.el.ui";
//$NON-NLS-1$
+
+ // The shared instance
+ private static ElUiPlugin plugin;
+
+ /**
+ * The constructor
+ */
+ public ElUiPlugin() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static ElUiPlugin getDefault() {
+ return plugin;
+ }
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ElUiPlugin.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-11-14
14:59:31 UTC (rev 18688)
+++
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/messages.properties 2009-11-16
07:09:51 UTC (rev 18689)
@@ -4,4 +4,7 @@
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}''.
-RENAME_METHOD_PARTICIPANT_UPDATE_METHOD_REFERENCES=Update method references in EL
\ No newline at end of file
+RENAME_METHOD_PARTICIPANT_UPDATE_METHOD_REFERENCES=Update method references in EL
+RESOURCE_BUNDLES_RENAME_PARTICIPANT_UPDATE_BUNDLE_REFERENCES=Update bundle references in
EL
+REFACTOR_CONTRIBUTOR_MAIN_MENU=EL Refactor
+REFACTOR_CONTRIBUTOR_RENAME_EL_VARIABLE=Rename EL Variable
Added:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/refactoring/ELRefactorContributionFactory.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/refactoring/ELRefactorContributionFactory.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/refactoring/ELRefactorContributionFactory.java 2009-11-16
07:09:51 UTC (rev 18689)
@@ -0,0 +1,387 @@
+/*******************************************************************************
+ * 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.io.IOException;
+
+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.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.ui.text.FastJavaPartitionScanner;
+import org.eclipse.jdt.ui.text.IJavaPartitions;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+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.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.ELInstance;
+import org.jboss.tools.common.el.core.model.ELInvocationExpression;
+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.ui.ElUiPlugin;
+import org.jboss.tools.common.el.ui.ElUIMessages;
+import org.jboss.tools.common.model.ui.editor.EditorPartWrapper;
+import org.jboss.tools.common.model.util.EclipseJavaUtil;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.propertieseditor.PropertiesCompoundEditor;
+import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.jst.web.ui.editors.WebCompoundEditor;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author Daniel Azarov
+ */
+public class ELRefactorContributionFactory extends AbstractContributionFactory {
+ private static final String ANNOTATION_NAME =
"org.jboss.seam.annotations.Name"; //$NON-NLS-1$
+ private static final String JAVA_EXT = "java"; //$NON-NLS-1$
+ private static final String XML_EXT = "xml"; //$NON-NLS-1$
+ private static final String XHTML_EXT = "xhtml"; //$NON-NLS-1$
+ private static final String JSP_EXT = "jsp"; //$NON-NLS-1$
+ private 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$
+
+ static private String selectedText;
+ static private IFile editorFile;
+ private String fileContent;
+ private IEditorPart editor;
+ private Shell shell;
+
+ public ELRefactorContributionFactory(){
+ super("","");
+ }
+
+ public ELRefactorContributionFactory(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)
+ && !XML_EXT.equalsIgnoreCase(ext)
+ && !XHTML_EXT.equalsIgnoreCase(ext)
+ && !JSP_EXT.equalsIgnoreCase(ext)
+ && !PROPERTIES_EXT.equalsIgnoreCase(ext))
+ return;
+
+ MenuManager mm = new MenuManager(ElUIMessages.REFACTOR_CONTRIBUTOR_MAIN_MENU);
+ mm.setVisible(true);
+
+ boolean separatorIsAdded = false;
+
+ ISelection sel = editor.getEditorSite().getSelectionProvider().getSelection();
+
+ if(sel == null || sel.isEmpty())
+ return;
+
+ if(sel instanceof StructuredSelection){
+ if(editor instanceof PropertiesCompoundEditor){
+ sel =
((PropertiesCompoundEditor)editor).getActiveEditor().getSite().getSelectionProvider().getSelection();
+ }else if(editor instanceof EditorPartWrapper){
+ EditorPartWrapper wrapperEditor = (EditorPartWrapper)editor;
+ if(wrapperEditor.getEditor() instanceof WebCompoundEditor){
+ WebCompoundEditor xmlEditor = (WebCompoundEditor)wrapperEditor.getEditor();
+ sel = xmlEditor.getActiveEditor().getSite().getSelectionProvider().getSelection();
+ }
+ }else if(editor instanceof WebCompoundEditor)
+ sel =
((WebCompoundEditor)editor).getActiveEditor().getSite().getSelectionProvider().getSelection();
+ }
+
+ if(sel instanceof TextSelection){
+ TextSelection selection = (TextSelection)sel;
+
+ selectedText = selection.getText();
+
+ try {
+ fileContent = FileUtil.readStream(editorFile);
+ } catch (CoreException e) {
+ ElUiPlugin.getDefault().logError(e);
+ }
+
+ boolean status = false;
+
+ if(JAVA_EXT.equalsIgnoreCase(ext)){
+ status = checkContextVariableInJava(editorFile, fileContent, selection);
+ } else if(XML_EXT.equalsIgnoreCase(ext) || XHTML_EXT.equalsIgnoreCase(ext) ||
JSP_EXT.equalsIgnoreCase(ext))
+ status = checkContextVariableInDOM(editorFile, fileContent, selection);
+ else if(PROPERTIES_EXT.equalsIgnoreCase(ext))
+ status = checkContextVariableInProperties(editorFile, fileContent, selection);
+
+ if(status){
+ mm.add(new RenameSeamContextVariableAction());
+
+ if(!separatorIsAdded)
+ additions.addContributionItem(new Separator(), null);
+ additions.addContributionItem(mm, null);
+ }
+ }
+ }
+ }
+
+ private boolean checkContextVariableInJava(IFile file, String content, TextSelection
selection){
+ 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();
+ if(offset <= selection.getOffset() && (offset+length) >=
(selection.getOffset()+selection.getLength())){
+ String value = document.get(offset, length);
+ if(value.indexOf('{')>-1) {
+ return scanString(file, value, offset, selection);
+ }
+ }
+ }
+ token = scaner.nextToken();
+ }
+ } catch (BadLocationException e) {
+ ElUiPlugin.getDefault().logError(e);
+ }
+ return false;
+ }
+
+ private boolean scanString(IFile file, String string, int offset, TextSelection
selection) {
+ 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()){
+ ELPropertyInvocation pi = findSeamContextVariable(ie);
+ if(pi != null){
+ if(offset+pi.getStartPosition() == selection.getOffset() && pi.getLength()
== selection.getLength())
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ private ELPropertyInvocation findSeamContextVariable(ELInvocationExpression
invocationExpression){
+ ELInvocationExpression invExp = invocationExpression;
+ while(invExp != null){
+ if(invExp instanceof ELPropertyInvocation){
+ if(((ELPropertyInvocation)invExp).getQualifiedName() != null &&
((ELPropertyInvocation)invExp).getQualifiedName().equals(selectedText))
+ return (ELPropertyInvocation)invExp;
+ else
+ invExp = invExp.getLeft();
+
+ }else{
+ invExp = invExp.getLeft();
+ }
+ }
+ return null;
+ }
+
+ private boolean checkContextVariableInDOM(IFile file, String content, TextSelection
selection){
+ IModelManager manager = StructuredModelManager.getModelManager();
+ if(manager == null) {
+ return false;
+ }
+ IStructuredModel model = null;
+ try {
+ model = manager.getModelForRead(file);
+ if (model instanceof IDOMModel) {
+ IDOMModel domModel = (IDOMModel) model;
+ IDOMDocument document = domModel.getDocument();
+ return scanChildNodes(file, document, selection);
+ }
+ } catch (CoreException e) {
+ ElUiPlugin.getDefault().logError(e);
+ } catch (IOException e) {
+ ElUiPlugin.getDefault().logError(e);
+ } finally {
+ if (model != null) {
+ model.releaseFromRead();
+ }
+ }
+ return false;
+ }
+
+ private boolean scanChildNodes(IFile file, Node parent, TextSelection selection) {
+ boolean status = false;
+ NodeList children = parent.getChildNodes();
+ for(int i=0; i<children.getLength(); i++) {
+ Node curentValidatedNode = children.item(i);
+ if(Node.ELEMENT_NODE == curentValidatedNode.getNodeType()) {
+ status = scanNodeContent(file,
((IDOMNode)curentValidatedNode).getFirstStructuredDocumentRegion(),
DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE, selection);
+ if(status)
+ return status;
+ } else if(Node.TEXT_NODE == curentValidatedNode.getNodeType()) {
+ status = scanNodeContent(file,
((IDOMNode)curentValidatedNode).getFirstStructuredDocumentRegion(),
DOMRegionContext.XML_CONTENT, selection);
+ if(status)
+ return status;
+ }
+ status = scanChildNodes(file, curentValidatedNode, selection);
+ if(status)
+ return status;
+ }
+ return false;
+ }
+
+ private boolean scanNodeContent(IFile file, IStructuredDocumentRegion node, String
regionType, TextSelection selection) {
+ boolean status = false;
+ 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();
+ status = scanString(file, text, offset, selection);
+ if(status)
+ return status;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean checkContextVariableInProperties(IFile file, String content,
TextSelection selection){
+ return scanString(file, content, 0, selection);
+ }
+
+ private IAnnotation getNameAnnotation(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_NAME))
+ return annotation;
+ }
+ }
+ }catch(CoreException ex){
+ ElUiPlugin.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 String getPropertyName(IMethod method){
+ String name = method.getElementName();
+
+ if(name.startsWith(GET) || name.startsWith(SET))
+ return name.substring(3).toLowerCase();
+
+ if(name.startsWith(IS))
+ return name.substring(2).toLowerCase();
+
+ return name.toLowerCase();
+ }
+
+ private static void saveAndBuild(){
+ if(!ElUiPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().saveAllEditors(true))
+ return;
+
+ try {
+ Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
+ } catch (InterruptedException e) {
+ // do nothing
+ }
+ }
+
+ public static void invokeRenameSeamContextVariableWizard(String oldName, Shell
activeShell) {
+// saveAndBuild();
+//
+// RenameSeamContextVariableProcessor processor = new
RenameSeamContextVariableProcessor(editorFile, selectedText);
+// RenameComponentRefactoring refactoring = new RenameComponentRefactoring(processor);
+// RenameSeamContextVariableWizard wizard = new
RenameSeamContextVariableWizard(refactoring, editorFile);
+// RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
+// try {
+// String titleForFailedChecks = ElUIMessages.SEAM_COMPONENT_RENAME_HANDLER_ERROR;
+// op.run(activeShell, titleForFailedChecks);
+// } catch (final InterruptedException irex) {
+// // operation was canceled
+// }
+ }
+
+ class RenameSeamContextVariableAction extends Action{
+ public RenameSeamContextVariableAction(){
+ super(ElUIMessages.REFACTOR_CONTRIBUTOR_RENAME_EL_VARIABLE);
+ }
+ public void run(){
+ saveAndBuild();
+
+ invokeRenameSeamContextVariableWizard(selectedText, shell);
+ }
+ }
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/refactoring/ELRefactorContributionFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
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 2009-11-14
14:59:31 UTC (rev 18688)
+++
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/refactoring/RenameMethodParticipant.java 2009-11-16
07:09:51 UTC (rev 18689)
@@ -34,7 +34,7 @@
import org.jboss.tools.common.el.core.refactoring.ELProjectSetExtension;
import org.jboss.tools.common.el.core.refactoring.ProjectsSet;
import org.jboss.tools.common.el.core.refactoring.RefactorSearcher;
-import org.jboss.tools.common.el.ui.ElUiCoreMessages;
+import org.jboss.tools.common.el.ui.ElUIMessages;
import org.jboss.tools.common.model.project.ProjectHome;
public class RenameMethodParticipant extends RenameParticipant{
@@ -58,9 +58,9 @@
if(method != null && !added){
if(searcher.isGetter(method))
- status.addWarning(ElUiCoreMessages.RENAME_METHOD_PARTICIPANT_GETTER_WARNING);
+ status.addWarning(ElUIMessages.RENAME_METHOD_PARTICIPANT_GETTER_WARNING);
else if(searcher.isSetter(method))
- status.addWarning(ElUiCoreMessages.RENAME_METHOD_PARTICIPANT_SETTER_WARNING);
+ status.addWarning(ElUIMessages.RENAME_METHOD_PARTICIPANT_SETTER_WARNING);
added = true;
}
@@ -85,7 +85,7 @@
if(element instanceof IMethod){
status = new RefactoringStatus();
- rootChange = new
CompositeChange(ElUiCoreMessages.RENAME_METHOD_PARTICIPANT_UPDATE_METHOD_REFERENCES);
+ rootChange = new
CompositeChange(ElUIMessages.RENAME_METHOD_PARTICIPANT_UPDATE_METHOD_REFERENCES);
method = (IMethod)element;
oldName = method.getElementName();
@@ -142,13 +142,13 @@
@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()));
+ status.addFatalError(Messages.format(ElUIMessages.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()));
+ status.addFatalError(Messages.format(ElUIMessages.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()));
+ status.addFatalError(Messages.format(ElUIMessages.RENAME_METHOD_PARTICIPANT_ERROR_READ_ONLY_FILE,
file.getFullPath().toString()));
return false;
}
return true;