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

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Tue Oct 11 14:30:48 EDT 2011


Author: vrubezhny
Date: 2011-10-11 14:30:47 -0400 (Tue, 11 Oct 2011)
New Revision: 35552

Modified:
   trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/src/org/jboss/tools/cdi/seam/core/international/el/CDIInternationalMessagesELResolver.java
   trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java
   trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/hover/ELTooltipTest.java
   trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.java
   trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.properties
   trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java
   trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/el/MessagePropertyELSegmentImpl.java
Log:
JBIDE-9731 Tooltip for EL referenced to message bundles

EL Tooltips were added for Resource Bundles/Properties. JUnit test for EL Tooltips is updated

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/src/org/jboss/tools/cdi/seam/core/international/el/CDIInternationalMessagesELResolver.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/src/org/jboss/tools/cdi/seam/core/international/el/CDIInternationalMessagesELResolver.java	2011-10-11 18:19:55 UTC (rev 35551)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/src/org/jboss/tools/cdi/seam/core/international/el/CDIInternationalMessagesELResolver.java	2011-10-11 18:30:47 UTC (rev 35552)
@@ -56,7 +56,6 @@
 import org.jboss.tools.common.model.XModelObject;
 import org.jboss.tools.common.model.util.PositionHolder;
 import org.jboss.tools.common.text.TextProposal;
-import org.jboss.tools.jst.web.kb.IPageContext;
 import org.jboss.tools.jst.web.kb.IResourceBundle;
 import org.jboss.tools.jst.web.kb.el.MessagePropertyELSegmentImpl;
 import org.jboss.tools.jst.web.kb.internal.ResourceBundle;
@@ -250,16 +249,16 @@
 						segment.getVariables().add(variable);						
 					}
 					resolution.addSegment(segment);
-					if(left.getLastToken() != left.getFirstToken()) {
-						LexicalToken combined = left.getFirstToken().getNextToken().getCombinedToken(left.getLastToken());
-						segment = new MessagePropertyELSegmentImpl(combined);
-						processMessageBundleSegment(expr, (MessagePropertyELSegmentImpl)segment, resolvedVariables);
-						segment.setResolved(true);
-						for (Variable variable : resolvedVars) {
-							segment.getVariables().add(variable);						
-						}
-						resolution.addSegment(segment);
-					}
+//					if(left.getLastToken() != left.getFirstToken()) {
+//						LexicalToken combined = left.getFirstToken().getNextToken().getCombinedToken(left.getLastToken());
+//						segment = new MessagePropertyELSegmentImpl(combined);
+//						processMessageBundleSegment(expr, (MessagePropertyELSegmentImpl)segment, resolvedVariables);
+//						segment.setResolved(true);
+//						for (Variable variable : resolvedVars) {
+//							segment.getVariables().add(variable);						
+//						}
+//						resolution.addSegment(segment);
+//					}
 
 					break;
 				}
@@ -303,9 +302,6 @@
 		if (resolution.getLastResolvedToken() == operand) {
 			// First segment is the last one
 			Set<TextProposal> proposals = new TreeSet<TextProposal>(TextProposal.KB_PROPOSAL_ORDER);
-			ELSegmentImpl segment = new ELSegmentImpl(operand.getFirstToken());
-			segment.setResolved(true);
-			resolution.addSegment(segment);
 
 			for (Variable var : resolvedVariables) {
 				String varName = var.getName();
@@ -322,7 +318,7 @@
 					setImage(proposal);
 					proposals.add(proposal);
 				}
-				segment.getVariables().add(var);
+				resolution.getLastSegment().getVariables().add(var);
 			}
 			resolution.setLastResolvedToken(expr);
 			resolution.setProposals(proposals);

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	2011-10-11 18:19:55 UTC (rev 35551)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java	2011-10-11 18:30:47 UTC (rev 35552)
@@ -274,9 +274,6 @@
 		if (resolution.getLastResolvedToken() == operand) {
 			// First segment is the last one
 			Set<TextProposal> proposals = new TreeSet<TextProposal>(TextProposal.KB_PROPOSAL_ORDER);
-			ELSegmentImpl segment = new ELSegmentImpl(operand.getFirstToken());
-			segment.setResolved(true);
-			resolution.addSegment(segment);
 
 			for (Variable var : resolvedVariables) {
 				String varName = var.getName();
@@ -293,7 +290,7 @@
 					setImage(proposal);
 					proposals.add(proposal);
 				}
-				segment.getVariables().add(var);
+				resolution.getLastSegment().getVariables().add(var);
 			}
 			resolution.setLastResolvedToken(expr);
 			resolution.setProposals(proposals);

Modified: trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/hover/ELTooltipTest.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/hover/ELTooltipTest.java	2011-10-11 18:19:55 UTC (rev 35551)
+++ trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/hover/ELTooltipTest.java	2011-10-11 18:30:47 UTC (rev 35552)
@@ -25,7 +25,7 @@
 import org.jboss.tools.test.util.ProjectImportTestSetup;
 
 /**
- * The JUnit test cases for JBIDE-9448 issue 
+ * The JUnit test cases for JBIDE-9448, JBIDE-9731 issues 
  * 
  * @author Victor Rubezhny
  */
@@ -33,8 +33,14 @@
 	private static final String PROJECT_NAME = "JSF2KickStartWithoutLibs";
 	private static final String PAGE_NAME = "WebContent/pages/inputname.xhtml";
 
-	private static final String EL_PREFIX[] = {"value=\"#{user", "value=\"#{user.name", "action=\"#{user.sayHello"};
-	private static final String EL_VALUE[] = {"user", "name", "sayHello"};
+	private static final String EL_PREFIX[] = {
+				"value=\"#{user", 
+				"value=\"#{user.name", 
+				"action=\"#{user.sayHello",
+				"label=\"${msgs",
+				"label=\"${msgs.prompt"
+			};
+	private static final String EL_VALUE[] = {"user", "name", "sayHello", "msgs", "prompt"};
 	private static final String EL_TOOLTIP_TEXT[] = {
 		"<html><body text=\"#000000\" bgcolor=\"#ffffe1\"><h5><img style='position: relative; width: 16px; height: 16px; top: 2px; left: 2px; ' src='file:/home/jeremy/projects/junit-workspace/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png'>\n" + 
 				"<span style='word-wrap:break-word;margin-left: 2px; margin-top: 2px; '>demo.User</span></span></h5><p>Created by JBoss Tools</body></html>",
@@ -42,7 +48,10 @@
 				"<span style='word-wrap:break-word;margin-left: 2px; margin-top: 2px; '>void demo.<a class='header' href='eclipse-javadoc:%E2%98%82=JSF2KickStartWithoutLibs/JavaSource%3Cdemo%7BUser.java%E2%98%83User'>User</a>.setName(<a class='header' href='eclipse-javadoc:%E2%98%82=JSF2KickStartWithoutLibs/JavaSource%3Cdemo%7BUser.java%E2%98%83User~setName~QString;%E2%98%82String'>String</a> name)</span></span></h5><br/><h5><img style='position: relative; width: 16px; height: 16px; top: 2px; left: 2px; ' src='file:/home/jeremy/projects/junit-workspace/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/1.png'>\n" +
 				"<span style='word-wrap:break-word;margin-left: 2px; margin-top: 2px; '><a class='header' href='eclipse-javadoc:%E2%98%82=JSF2KickStartWithoutLibs/JavaSource%3Cdemo%7BUser.java%E2%98%83User~getName%E2%98%82String'>String</a> demo.<a class='header' href='eclipse-javadoc:%E2%98%82=JSF2KickStartWithoutLibs/JavaSource%3Cdemo%7BUser.java%E2%98%83User'>User</a>.getName()</span></span></h5></body></html>",
 		"<html><body text=\"#000000\" bgcolor=\"#ffffe1\"><h5><img style='position: relative; width: 16px; height: 16px; top: 2px; left: 2px; ' src='file:/home/jeremy/projects/junit-workspace/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/1.png'>\n" +
-				"<span style='word-wrap:break-word;margin-left: 2px; margin-top: 2px; '><a class='header' href='eclipse-javadoc:%E2%98%82=JSF2KickStartWithoutLibs/JavaSource%3Cdemo%7BUser.java%E2%98%83User~sayHello%E2%98%82String'>String</a> demo.<a class='header' href='eclipse-javadoc:%E2%98%82=JSF2KickStartWithoutLibs/JavaSource%3Cdemo%7BUser.java%E2%98%83User'>User</a>.sayHello()</span></span></h5></body></html>"
+				"<span style='word-wrap:break-word;margin-left: 2px; margin-top: 2px; '><a class='header' href='eclipse-javadoc:%E2%98%82=JSF2KickStartWithoutLibs/JavaSource%3Cdemo%7BUser.java%E2%98%83User~sayHello%E2%98%82String'>String</a> demo.<a class='header' href='eclipse-javadoc:%E2%98%82=JSF2KickStartWithoutLibs/JavaSource%3Cdemo%7BUser.java%E2%98%83User'>User</a>.sayHello()</span></span></h5></body></html>",
+		"Base Name: resources<br><br>Resource Bundle: /JSF2KickStartWithoutLibs/JavaSource/resources.properties<br>",
+		"Property: prompt<br>Base Name: resources<br><br>Resource Bundle: /JSF2KickStartWithoutLibs/JavaSource/resources.properties<br>Value: Your Name:<br><br>"
+				
 	};
 	
 	public void setUp() throws Exception {

Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.java	2011-10-11 18:19:55 UTC (rev 35551)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.java	2011-10-11 18:30:47 UTC (rev 35552)
@@ -25,7 +25,15 @@
 	public static String ELInfoHover_noAttachedJavaSource; 	//
 	public static String ELInfoHover_noInformation;			//
 	public static String ELInfoHover_error_gettingJavadoc; 	//	
-	
+	public static String ELInfoHover_baseName; 
+	public static String ELInfoHover_propertyName;
+	public static String ELInfoHover_resourceBundle; 
+	public static String ELInfoHover_resourceBundlePropertyValue;
+	public static String ELInfoHover_resourceBundlePropertyValueNotDefined; 
+	public static String ELInfoHover_resourceBundleNotDefined;
+	public static String ELInfoHover_newLine;
+	public static String ELInfoHover_treeDots;
+		
 	static {
 		NLS.initializeMessages(BUNDLE_NAME, ELInfoHoverMessages.class);
 	}

Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.properties
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.properties	2011-10-11 18:19:55 UTC (rev 35551)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.properties	2011-10-11 18:30:47 UTC (rev 35552)
@@ -3,3 +3,11 @@
 ELInfoHover_noAttachedJavadoc= <em>Note: This element has no attached Javadoc and the Javadoc could not be found in the attached source.</em>
 ELInfoHover_noInformation= <em>Note: The Javadoc for this element could neither be found in the attached source nor the attached Javadoc.</em>
 ELInfoHover_error_gettingJavadoc= <em>Note: An exception occurred while getting the Javadoc. See log for details.</em>
+ELInfoHover_baseName=Base Name: {0}<br>
+ELInfoHover_propertyName=Property: {0}<br>
+ELInfoHover_resourceBundle=Resource Bundle: {0}<br>
+ELInfoHover_resourceBundlePropertyValue=Value: {0}{1}<br>
+ELInfoHover_resourceBundlePropertyValueNotDefined=[Value not defined]
+ELInfoHover_resourceBundleNotDefined=[Resource Bundle not defined]
+ELInfoHover_newLine=<br>
+ELInfoHover_treeDots=...

Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java	2011-10-11 18:19:55 UTC (rev 35551)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java	2011-10-11 18:30:47 UTC (rev 35552)
@@ -13,11 +13,14 @@
 import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
+import java.text.MessageFormat;
 import java.util.List;
 import java.util.Map;
 
 import org.eclipse.core.filebuffers.FileBuffers;
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.jdt.core.IJavaElement;
@@ -53,6 +56,9 @@
 import org.jboss.tools.common.el.core.resolver.ELResolver;
 import org.jboss.tools.common.el.core.resolver.ELSegment;
 import org.jboss.tools.common.el.core.resolver.JavaMemberELSegmentImpl;
+import org.jboss.tools.common.el.core.resolver.MessagePropertyELSegment;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.filesystems.impl.JarSystemImpl;
 import org.jboss.tools.common.text.TextProposal;
 import org.jboss.tools.jst.jsp.contentassist.Utils;
 import org.jboss.tools.jst.jsp.contentassist.computers.AbstractXmlCompletionProposalComputer.TextRegion;
@@ -61,6 +67,7 @@
 import org.jboss.tools.jst.web.kb.KbQuery.Type;
 import org.jboss.tools.jst.web.kb.PageContextFactory;
 import org.jboss.tools.jst.web.kb.PageProcessor;
+import org.jboss.tools.jst.web.kb.el.MessagePropertyELSegmentImpl;
 import org.jboss.tools.jst.web.kb.taglib.INameSpace;
 import org.w3c.dom.Node;
 
@@ -196,7 +203,7 @@
 		
 		for (int i = 0; resolvers != null && i < resolvers.length; i++) {
 			ELResolution resolution = resolvers[i] == null ? null : resolvers[i].resolve(fContext, elOperand, fDocumentPosition);
-			if (resolution == null)
+			if (resolution == null || !resolution.isResolved())
 				continue;
 			
 			ELSegment segment = resolution.getLastSegment();
@@ -215,6 +222,75 @@
 				
 				ELInfoHoverBrowserInformationControlInput hover = JavaStringELInfoHover.getHoverInfo2Internal(javaElements, false);
 				return (hover == null ? null : hover.getHtml());
+			} else if (segment instanceof MessagePropertyELSegmentImpl) {
+				MessagePropertyELSegmentImpl mpSegment = (MessagePropertyELSegmentImpl)segment;
+				
+				String baseName = mpSegment.getBaseName();
+				String propertyName = ((MessagePropertyELSegment)segment).isBundle() ? null : trimQuotes(segment.getToken().getText());
+				
+				StringBuilder sb = new StringBuilder();
+				if (propertyName != null && propertyName.length() > 0) 
+					sb.append(MessageFormat.format(ELInfoHoverMessages.ELInfoHover_propertyName, 
+						propertyName));
+					
+				if (baseName != null && baseName.length() > 0)
+					sb.append(MessageFormat.format(ELInfoHoverMessages.ELInfoHover_baseName, 
+							baseName));
+				sb.append(ELInfoHoverMessages.ELInfoHover_newLine);
+				
+				List<XModelObject> objects = (List<XModelObject>)mpSegment.getObjects();
+				for (XModelObject o : objects) {
+					IFile propFile = (IFile)o.getAdapter(IFile.class);
+					String propFilePath = null;
+					if (propFile != null) {
+						propFilePath = propFile.getFullPath().toString();
+					} else {
+						XModelObject parent = o.getFileType() == XModelObject.FILE ? o : o.getParent();
+						String path = parent.getPath();
+						while (parent != null && parent.getFileType() != XModelObject.SYSTEM) {
+							parent = parent.getParent();
+						}
+						if (parent instanceof JarSystemImpl) {
+							String sysPath = parent.getPath();
+							path = path.substring(sysPath.length());
+
+							String jarPath = ((JarSystemImpl) parent).getLocation();
+							
+							IResource jar = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(jarPath));
+							
+							if (jar != null) {
+								jarPath = jar.getFullPath().toString();
+							}
+							
+							propFilePath = jarPath + "!" + path; //$NON-NLS-1$
+						}
+					}
+					sb.append(MessageFormat.format(ELInfoHoverMessages.ELInfoHover_resourceBundle, 
+							propFilePath != null ? propFilePath : ELInfoHoverMessages.ELInfoHover_resourceBundleNotDefined));
+					
+					if (propertyName != null) {
+						String value = o.get("VALUE");  //$NON-NLS-1$
+						boolean addCut = false;
+						if (value != null) {
+							if (value.length() > 100) {
+								// Get first words of value
+								int lastSpace = value.lastIndexOf(' ', 99);
+								if (lastSpace != -1) {
+									value = value.substring(0, lastSpace);
+								} else { // cut as is
+									value = value.substring(0, 100);
+								}
+								addCut = true;
+							}
+						}
+						sb.append(MessageFormat.format(ELInfoHoverMessages.ELInfoHover_resourceBundlePropertyValue, 
+								value != null ? value : ELInfoHoverMessages.ELInfoHover_resourceBundlePropertyValueNotDefined,
+										addCut ? ELInfoHoverMessages.ELInfoHover_treeDots : "")); //$NON-NLS-1$
+						sb.append(ELInfoHoverMessages.ELInfoHover_newLine);
+					}
+				}
+
+				return sb.toString();
 			}
 		}
 		
@@ -436,4 +512,18 @@
 		};
 	}
 
+	private String trimQuotes(String value) {
+		if(value == null)
+			return null;
+
+		if(value.startsWith("'") || value.startsWith("\"")) {  //$NON-NLS-1$ //$NON-NLS-2$
+			value = value.substring(1);
+		} 
+		
+		if(value.endsWith("'") || value.endsWith("\"")) { //$NON-NLS-1$ //$NON-NLS-2$
+			value = value.substring(0, value.length() - 1);
+		}
+		return value;
+	}
+
 }

Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/el/MessagePropertyELSegmentImpl.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/el/MessagePropertyELSegmentImpl.java	2011-10-11 18:19:55 UTC (rev 35551)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/el/MessagePropertyELSegmentImpl.java	2011-10-11 18:30:47 UTC (rev 35552)
@@ -100,6 +100,10 @@
 		objects.add(object);
 	}
 
+	public List<XModelObject> getObjects() {
+		return objects;
+	}
+	
 	public IOpenableReference[] getOpenable() {
 		if(objects != null) {
 			IOpenableReference[] result = new IOpenableReference[objects.size()];
@@ -114,8 +118,8 @@
 					
 					@Override
 					public String getLabel() {
-						XModelObject p = o;
-						while(p != null && p.getFileType() < XModelObject.FILE) p = p.getParent();
+//						XModelObject p = o;
+//						while(p != null && p.getFileType() < XModelObject.FILE) p = p.getParent();
 						
 						// Improve label - add a locale for a resource bundle
 						String baseName = getBaseName();



More information about the jbosstools-commits mailing list