[jbosstools-commits] JBoss Tools SVN: r23416 - in trunk: jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Jul 15 10:08:29 EDT 2010


Author: dazarov
Date: 2010-07-15 10:08:27 -0400 (Thu, 15 Jul 2010)
New Revision: 23416

Added:
   trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/MessagePropertyELSegment.java
   trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/MessagePropertyELSegmentImpl.java
Modified:
   trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolution.java
   trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java
   trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/MessagesFileRenameParticipant.java
   trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java
Log:
https://jira.jboss.org/browse/JBIDE-4858

Modified: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolution.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolution.java	2010-07-15 11:12:29 UTC (rev 23415)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolution.java	2010-07-15 14:08:27 UTC (rev 23416)
@@ -51,6 +51,14 @@
 	List<ELSegment> findSegmentsByJavaElement(IJavaElement element);
 
 	/**
+	 * Finds the segments which are resolved to given baseName and propertyName.
+	 * @param baseName
+	 * @param propertyName
+	 * @return
+	 */
+	List<ELSegment> findSegmentsByMessageProperty(String baseName, String propertyName);
+
+	/**
 	 * Finds the segment which is located at given offset.
 	 * @param offcet relative source EL operand.
 	 * @return

Modified: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java	2010-07-15 11:12:29 UTC (rev 23415)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java	2010-07-15 14:08:27 UTC (rev 23416)
@@ -70,6 +70,20 @@
 		}
 		return list;
 	}
+	
+	/* (non-Javadoc)
+	 * @see org.jboss.tools.common.el.core.resolver.ELResolution#findSegmentsByMessageProperty(String, String)
+	 */
+	public List<ELSegment> findSegmentsByMessageProperty(String baseName, String propertyName) {
+		ArrayList<ELSegment> list = new ArrayList<ELSegment>();
+		for(ELSegment segment : segments){
+			if(segment instanceof MessagePropertyELSegment){
+				if(((MessagePropertyELSegment)segment).getBaseName().equals(baseName) && segment.getToken().getText().equals(propertyName))
+					 list.add(segment);
+			}
+		}
+		return list;
+	}
 
 	/* (non-Javadoc)
 	 * @see org.jboss.tools.common.el.core.resolver.ELResolution#findSegmentByOffset(int)

Added: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/MessagePropertyELSegment.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/MessagePropertyELSegment.java	                        (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/MessagePropertyELSegment.java	2010-07-15 14:08:27 UTC (rev 23416)
@@ -0,0 +1,40 @@
+/******************************************************************************* 
+ * Copyright (c) 2010 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
+package org.jboss.tools.common.el.core.resolver;
+
+import org.eclipse.core.resources.IResource;
+import org.jboss.tools.common.text.ITextSourceReference;
+
+/**
+ * Describes a segment of EL operand which is a Message Bundle Property. 
+ * @author Daniel Azarov
+ */
+public interface MessagePropertyELSegment extends ELSegment {
+	/**
+	 * @return qualified name of property file.
+	 */
+	String getBaseName();
+
+	/**
+	 * @return resource of Message Bundle.
+	 */
+	IResource getMessageBundleResource();
+	
+	/**
+	 * @return true if the segment presents message property.
+	 */
+	boolean isProperty();
+	
+	/**
+	 * @return source reference of message property.
+	 */
+	ITextSourceReference getMessagePropertySourceReference();
+}


Property changes on: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/MessagePropertyELSegment.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/MessagePropertyELSegmentImpl.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/MessagePropertyELSegmentImpl.java	                        (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/MessagePropertyELSegmentImpl.java	2010-07-15 14:08:27 UTC (rev 23416)
@@ -0,0 +1,68 @@
+/******************************************************************************* 
+ * Copyright (c) 2010 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
+package org.jboss.tools.common.el.core.resolver;
+
+import org.eclipse.core.resources.IResource;
+import org.jboss.tools.common.text.ITextSourceReference;
+
+/**
+ * @author Daniel Azarov
+ */
+public class MessagePropertyELSegmentImpl extends ELSegmentImpl implements
+		MessagePropertyELSegment {
+	
+	private IResource messageBundleResource = null;
+	private ITextSourceReference messagePropertySourceReference = null;
+	private int propertyStart=0, propertyLength=0;
+	private String baseName=null;
+
+	@Override
+	public IResource getMessageBundleResource() {
+		return messageBundleResource;
+	}
+	
+	public void setMessageBundleResource(IResource resource){
+		messageBundleResource = resource;
+	}
+
+	@Override
+	public boolean isProperty() {
+		return messagePropertySourceReference != null;
+	}
+
+	@Override
+	public ITextSourceReference getMessagePropertySourceReference() {
+		if(messagePropertySourceReference==null) {
+			messagePropertySourceReference = new ITextSourceReference() {
+				public int getStartPosition() {
+					return propertyStart;
+				}
+				public int getLength() {
+					return propertyLength;
+				}
+			};
+		}
+		return messagePropertySourceReference;
+	}
+	
+	public void setMessagePropertySourceReference(int start, int lenght) {
+		propertyStart = start;
+		propertyLength = lenght;
+	}
+	
+	public String getBaseName(){
+		return baseName;
+	}
+	
+	public void setBaseName(String name){
+		baseName = name;
+	}
+}


Property changes on: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/MessagePropertyELSegmentImpl.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java	2010-07-15 11:12:29 UTC (rev 23415)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java	2010-07-15 14:08:27 UTC (rev 23416)
@@ -19,9 +19,12 @@
 import java.util.TreeSet;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.swt.graphics.Image;
+import org.jboss.tools.common.el.core.ELCorePlugin;
 import org.jboss.tools.common.el.core.ca.AbstractELCompletionEngine;
 import org.jboss.tools.common.el.core.model.ELExpression;
 import org.jboss.tools.common.el.core.model.ELInstance;
@@ -37,11 +40,15 @@
 import org.jboss.tools.common.el.core.resolver.ELResolutionImpl;
 import org.jboss.tools.common.el.core.resolver.ELSegmentImpl;
 import org.jboss.tools.common.el.core.resolver.IVariable;
+import org.jboss.tools.common.el.core.resolver.MessagePropertyELSegmentImpl;
 import org.jboss.tools.common.el.core.resolver.TypeInfoCollector.MemberInfo;
 import org.jboss.tools.common.model.XModel;
+import org.jboss.tools.common.model.XModelObject;
 import org.jboss.tools.common.model.project.IModelNature;
 import org.jboss.tools.common.model.util.EclipseResourceUtil;
 import org.jboss.tools.common.text.TextProposal;
+import org.jboss.tools.common.text.ext.util.Utils;
+import org.jboss.tools.common.util.FileUtil;
 import org.jboss.tools.jsf.JSFModelPlugin;
 import org.jboss.tools.jst.web.kb.IPageContext;
 import org.jboss.tools.jst.web.kb.IResourceBundle;
@@ -334,7 +341,9 @@
 		ELSegmentImpl segment = new ELSegmentImpl();
 		resolution.setProposals(kbProposals);
 		if(expr instanceof ELPropertyInvocation) {
-			segment.setToken(((ELPropertyInvocation)expr).getName());			
+			segment = new MessagePropertyELSegmentImpl();
+			segment.setToken(((ELPropertyInvocation)expr).getName());
+			processMessagePropertySegment(expr, (MessagePropertyELSegmentImpl)segment, members);
 		} else {
 			segment.setToken(expr.getFirstToken());			
 		}
@@ -444,7 +453,50 @@
 			resolution.setLastResolvedToken(expr);
 		}
 	}
-
+	
+	private void processMessagePropertySegment(ELInvocationExpression expr, MessagePropertyELSegmentImpl segment, List<Variable> variables){
+		for(Variable variable : variables){
+			if(expr.getFirstToken().getText().equals(variable.name)){
+				
+				IModelNature n = EclipseResourceUtil.getModelNature(variable.f.getProject());
+				if(n == null)
+					return;
+				XModel model = n.getModel();
+				if(model == null)
+					return;
+				XModelObject properties = model.getByPath("/" + variable.basename.replace('.', '/') + ".properties");
+				if(properties == null)
+					return;
+				IFile propFile = (IFile)properties.getAdapter(IFile.class);
+				if(propFile == null)
+					return;
+				segment.setMessageBundleResource(propFile);
+				XModelObject property = properties.getChildByPath(expr.getText());
+				if(property != null){
+					try {
+						String content = FileUtil.readStream(propFile);
+						if(findPropertyLocation(property, content, segment)){
+							segment.setBaseName(variable.basename);
+						}
+					} catch (CoreException e) {
+						log(e);
+					}
+				}
+			}
+		}
+	}
+	
+	public boolean findPropertyLocation(XModelObject property, String content, MessagePropertyELSegmentImpl segment) {
+		String name = property.getAttributeValue("name"); //$NON-NLS-1$
+		String nvs = property.getAttributeValue("name-value-separator"); //$NON-NLS-1$
+		int i = content.indexOf(name + nvs);
+		if(i < 0) return false;
+		int j = content.indexOf('\n', i);
+		if(j < 0) j = content.length();
+		segment.setMessagePropertySourceReference(i, j - i);
+		return true;
+	}
+	
 	protected void processSingularMember(Variable mbr, Set<TextProposal> kbProposals) {
 		// Surround the "long" keys containing the dots with [' '] 
 		TreeSet<String> keys = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);

Modified: trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/MessagesFileRenameParticipant.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/MessagesFileRenameParticipant.java	2010-07-15 11:12:29 UTC (rev 23415)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/MessagesFileRenameParticipant.java	2010-07-15 14:08:27 UTC (rev 23416)
@@ -55,7 +55,11 @@
 				newName = "\""+oldName.replace(fileName,newName)+"\"";
 				
 				SearchUtil su = new SearchUtil(SearchUtil.XML_FILES, oldName);
+				
 				SearchResult result = su.searchInNodeAttribute(file.getProject(), ":loadBundle", "basename");
+				if(result.getEntries().size() == 0)
+					return false;
+				
 				for(FileResult fr : result.getEntries()){
 					TextFileChange fileChange = new TextFileChange(fr.getFile().getName(), fr.getFile());
 					MultiTextEdit root = new MultiTextEdit();



More information about the jbosstools-commits mailing list