[jbosstools-commits] JBoss Tools SVN: r43611 - in trunk: common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Tue Sep 11 20:25:41 EDT 2012


Author: dgolovin
Date: 2012-09-11 20:25:40 -0400 (Tue, 11 Sep 2012)
New Revision: 43611

Modified:
   trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/src/org/jboss/tools/cdi/seam/core/international/el/CDIInternationalMessagesELResolver.java
   trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/StringUtil.java
   trunk/common/tests/org.jboss.tools.common.test/src/org/jboss/tools/common/util/test/StringUtilTest.java
Log:
JBIDE-12589 o.j.t.jsf.ui.test.* JUnit tests fail
StringUtil is fixed and new JUnit tests were added


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	2012-09-12 00:15:16 UTC (rev 43610)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/src/org/jboss/tools/cdi/seam/core/international/el/CDIInternationalMessagesELResolver.java	2012-09-12 00:25:40 UTC (rev 43611)
@@ -517,7 +517,7 @@
 	 */
 	private boolean isRelevant(ELInvocationExpression expr, Variable variable) {
 		LexicalToken t = expr.getFirstToken();
-		StringBuffer sb = new StringBuffer();
+		StringBuilder sb = new StringBuilder();
 		sb.append(t.getText());
 		boolean ok = sb.toString().equals(variable.name);
 		while(!ok && t != null && t != expr.getLastToken()) {
@@ -540,23 +540,24 @@
 					return;
 
 				String propertyName = segment.getToken().getText();
-
+				
 				IProperty prop = bundle.getProperty(StringUtil.trimQuotes(propertyName));
-				if(prop == null) continue;
-				Map<String, LocalizedValue> values = ((PropertyImpl)prop).getValues();
-				for (LocalizedValue value: values.values()) {
-					XModelObject p = value.getObject();
-					segment.addObject(p);
-					segment.setBaseName(variable.basename);
-
-					PositionHolder h = PositionHolder.getPosition(p, null);
-					h.update();
-					segment.setMessagePropertySourceReference(h.getStart(), prop.getName().length());
-
-					IFile propFile = (IFile)p.getAdapter(IFile.class);
-					if(propFile == null)
-						continue;
-					segment.setMessageBundleResource(propFile);
+				if(prop != null) {
+					Map<String, LocalizedValue> values = ((PropertyImpl)prop).getValues();
+					for (LocalizedValue value: values.values()) {
+						XModelObject p = value.getObject();
+						segment.addObject(p);
+						segment.setBaseName(variable.basename);
+	
+						PositionHolder h = PositionHolder.getPosition(p, null);
+						h.update();
+						segment.setMessagePropertySourceReference(h.getStart(), prop.getName().length());
+	
+						IFile propFile = (IFile)p.getAdapter(IFile.class);
+						if(propFile == null)
+							continue;
+						segment.setMessageBundleResource(propFile);
+					}
 				}
 			}
 		}

Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/StringUtil.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/StringUtil.java	2012-09-12 00:15:16 UTC (rev 43610)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/StringUtil.java	2012-09-12 00:25:40 UTC (rev 43611)
@@ -29,17 +29,19 @@
 	 * @return Non-quoted text value
 	 */
 	public static String trimQuotes(String result) {
-		if (result == null || result.length() == 0)
-			return result;
-		int start = 0, end = result.length();
-		char first = result.charAt(start);
-		char last = result.charAt(end - 1);
-		if (first == APO || first == QUOT) {
-			start++;
+		String temp = result;
+		if(!temp.isEmpty()) {
+			int start = 0, end = result.length();
+			char first = result.charAt(start);
+			char last = result.charAt(end - 1);
+			if (first == APO || first == QUOT) {
+				start++;
+			}
+			if ((last == APO || last == QUOT) && end>1) {
+				end--;
+			}
+			temp = result.substring(start, end);
 		}
-		if (last == APO || last == QUOT) {
-			end--;
-		}
-		return result.substring(start, end);
+		return temp;
 	}
 }

Modified: trunk/common/tests/org.jboss.tools.common.test/src/org/jboss/tools/common/util/test/StringUtilTest.java
===================================================================
--- trunk/common/tests/org.jboss.tools.common.test/src/org/jboss/tools/common/util/test/StringUtilTest.java	2012-09-12 00:15:16 UTC (rev 43610)
+++ trunk/common/tests/org.jboss.tools.common.test/src/org/jboss/tools/common/util/test/StringUtilTest.java	2012-09-12 00:25:40 UTC (rev 43611)
@@ -8,10 +8,11 @@
 
 public class StringUtilTest extends TestCase{
 
+	final String[] OPTIONS = new String[] {"","'","\""};
+	
 	@Test
 	public void testTrimQuotes() {
-		String text = "text";
-		final String[] OPTIONS = new String[] {"","'","\""}; 
+		String text = "t";
 		for(int i = 0;i<OPTIONS.length;i++) {
 			for(int j = 0;j<OPTIONS.length;j++) {
 				String target = OPTIONS[i] + text + OPTIONS[j];
@@ -21,4 +22,10 @@
 		}
 	}
 
+	public void testTrimForStringLength0to1() {
+		for (String charq: OPTIONS) {
+			assertTrue("".equals(StringUtil.trimQuotes(charq)));	
+		}
+	}
+	
 }



More information about the jbosstools-commits mailing list