Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[xbase][validation] Fixing the name replies by UIStrings class for ty…
…pe references. The UIStrings class is able to reply the human-readable string for a JvmTypereference. When the JvmTypeReference is resolved, the simple name of the referred type is always replied. But, when the JvmTypeReference is not resolved, the replied name is directly extracted from the text of associated code. Consequently, the replied value may be a simple name or a fully qualified name of the type. This patch ensures that UIStrings class always reply the simple name of the type in all cases. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=443131 Change-Id: Ida292ba87e3ab1408f03c17973db0bdb3901c8de Signed-off-by: sgalland <galland@arakhne.org>
- Loading branch information
1 parent
aab8672
commit 50f5da7
Showing
3 changed files
with
232 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
...g.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/UIStringsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are 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 | ||
*******************************************************************************/ | ||
package org.eclipse.xtend.core.tests.validation; | ||
|
||
import org.eclipse.xtend.core.tests.AbstractXtendTestCase; | ||
import org.eclipse.xtend.core.xtend.XtendClass; | ||
import org.eclipse.xtend.core.xtend.XtendFile; | ||
import org.eclipse.xtend.core.xtend.XtendFunction; | ||
import org.eclipse.xtext.common.types.JvmTypeReference; | ||
import org.eclipse.xtext.xbase.XBlockExpression; | ||
import org.eclipse.xtext.xbase.XConstructorCall; | ||
import org.eclipse.xtext.xbase.XVariableDeclaration; | ||
import org.eclipse.xtext.xbase.validation.UIStrings; | ||
import org.junit.Test; | ||
|
||
import com.google.inject.Inject; | ||
|
||
/** | ||
* @author Stéphane Galland - Initial contribution and API | ||
*/ | ||
public class UIStringsTest extends AbstractXtendTestCase { | ||
|
||
@Inject | ||
protected UIStrings uiStrings; | ||
|
||
/** Only the simple name of the type is specified. | ||
* The JvmTypeReference is not a proxy. | ||
*/ | ||
@Test | ||
public void testReferenceToString_0() throws Exception { | ||
XtendFile file = file( | ||
"package org.eclipse.xtend.core.tests.validation.uistrings\n" | ||
+ "public interface InterfaceA { }\n" | ||
+ "public class ClassB implements InterfaceA { }\n" | ||
+ "public class ClassC extends ClassB {\n" | ||
+ "}\n" | ||
+ "class XtendClass1 {\n" | ||
+ " def test() {\n" | ||
+ " val x = new List<ClassC>\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
XtendClass clazz = (XtendClass) file.getXtendTypes().get(3); | ||
XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression(); | ||
XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0); | ||
XConstructorCall cons = (XConstructorCall) declaration.getRight(); | ||
JvmTypeReference reference = cons.getTypeArguments().get(0); | ||
assertNotNull(reference); | ||
assertNotNull(reference.getType()); | ||
assertFalse(reference.getType().eIsProxy()); | ||
assertNotNull(reference.eResource()); | ||
assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label")); | ||
} | ||
|
||
/** Only the simple name of the type is specified. | ||
* The JvmTypeReference is proxy. | ||
*/ | ||
@Test | ||
public void testReferenceToString_1() throws Exception { | ||
XtendFile file1 = file( | ||
"package org.eclipse.xtend.core.tests.validation.uistrings\n" | ||
+ "public interface InterfaceA { }\n" | ||
+ "public class ClassB implements InterfaceA { }\n" | ||
+ "public class ClassC extends ClassB {\n" | ||
+ "}\n"); | ||
assertNotNull(file1); | ||
XtendFile file2 = file( | ||
"package org.eclipse.xtend.core.tests.validation.uistrings\n" | ||
+ "class XtendClass1 {\n" | ||
+ " def test() {\n" | ||
+ " val x = new List<ClassC>\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
XtendClass clazz = (XtendClass) file2.getXtendTypes().get(0); | ||
XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression(); | ||
XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0); | ||
XConstructorCall cons = (XConstructorCall) declaration.getRight(); | ||
JvmTypeReference reference = cons.getTypeArguments().get(0); | ||
assertNotNull(reference); | ||
assertNotNull(reference.getType()); | ||
assertTrue(reference.getType().eIsProxy()); | ||
assertNotNull(reference.eResource()); | ||
assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label")); | ||
} | ||
|
||
/** The qualified name of the type is specified. | ||
* The JvmTypeReference is not a proxy. | ||
*/ | ||
@Test | ||
public void testReferenceToString_2() throws Exception { | ||
XtendFile file = file( | ||
"package org.eclipse.xtend.core.tests.validation.uistrings\n" | ||
+ "public interface InterfaceA { }\n" | ||
+ "public class ClassB implements InterfaceA { }\n" | ||
+ "public class ClassC extends ClassB {\n" | ||
+ "}\n" | ||
+ "class XtendClass1 {\n" | ||
+ " def test() {\n" | ||
+ " val x = new List<org.eclipse.xtend.core.tests.validation.uistrings.ClassC>\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
XtendClass clazz = (XtendClass) file.getXtendTypes().get(3); | ||
XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression(); | ||
XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0); | ||
XConstructorCall cons = (XConstructorCall) declaration.getRight(); | ||
JvmTypeReference reference = cons.getTypeArguments().get(0); | ||
assertNotNull(reference); | ||
assertNotNull(reference.getType()); | ||
assertFalse(reference.getType().eIsProxy()); | ||
assertNotNull(reference.eResource()); | ||
assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label")); | ||
} | ||
|
||
/** The qualified name of the type is specified. | ||
* The JvmTypeReference is proxy. | ||
*/ | ||
@Test | ||
public void testReferenceToString_3() throws Exception { | ||
XtendFile file1 = file( | ||
"package org.eclipse.xtend.core.tests.validation.uistrings\n" | ||
+ "public interface InterfaceA { }\n" | ||
+ "public class ClassB implements InterfaceA { }\n" | ||
+ "public class ClassC extends ClassB {\n" | ||
+ "}\n"); | ||
assertNotNull(file1); | ||
XtendFile file2 = file( | ||
"package org.eclipse.xtend.core.tests.validation.uistrings\n" | ||
+ "class XtendClass1 {\n" | ||
+ " def test() {\n" | ||
+ " val x = new List<org.eclipse.xtend.core.tests.validation.uistrings.ClassC>\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
XtendClass clazz = (XtendClass) file2.getXtendTypes().get(0); | ||
XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression(); | ||
XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0); | ||
XConstructorCall cons = (XConstructorCall) declaration.getRight(); | ||
JvmTypeReference reference = cons.getTypeArguments().get(0); | ||
assertNotNull(reference); | ||
assertNotNull(reference.getType()); | ||
assertTrue(reference.getType().eIsProxy()); | ||
assertNotNull(reference.eResource()); | ||
assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label")); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
...eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/validation/UIStringsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are 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 | ||
*******************************************************************************/ | ||
package org.eclipse.xtext.xbase.tests.validation; | ||
|
||
import org.eclipse.xtext.common.types.JvmType; | ||
import org.eclipse.xtext.common.types.JvmTypeReference; | ||
import org.eclipse.xtext.common.types.util.TypeReferences; | ||
import org.eclipse.xtext.xbase.XBlockExpression; | ||
import org.eclipse.xtext.xbase.XCastedExpression; | ||
import org.eclipse.xtext.xbase.XExpression; | ||
import org.eclipse.xtext.xbase.XTypeLiteral; | ||
import org.eclipse.xtext.xbase.XVariableDeclaration; | ||
import org.eclipse.xtext.xbase.tests.AbstractXbaseTestCase; | ||
import org.eclipse.xtext.xbase.validation.UIStrings; | ||
import org.junit.Test; | ||
|
||
import com.google.inject.Inject; | ||
|
||
/** | ||
* @author Stéphane Galland - Initial contribution and API | ||
*/ | ||
public class UIStringsTest extends AbstractXbaseTestCase { | ||
|
||
@Inject | ||
protected UIStrings uiStrings; | ||
|
||
@Inject | ||
protected TypeReferences typeReferences; | ||
|
||
@Test | ||
public void testReferenceToString_0() throws Exception { | ||
XExpression expr = expression("typeof(foo.String)", true); | ||
assertTrue(expr instanceof XTypeLiteral); | ||
XTypeLiteral operator = (XTypeLiteral) expr; | ||
JvmType type = operator.getType(); | ||
JvmTypeReference reference = this.typeReferences.createTypeRef(type); | ||
assertEquals("String", this.uiStrings.referenceToString(reference, "the-default-value")); | ||
} | ||
|
||
@Test | ||
public void testReferenceToString_1() throws Exception { | ||
XExpression expr = expression("typeof(String)", true); | ||
assertTrue(expr instanceof XTypeLiteral); | ||
XTypeLiteral operator = (XTypeLiteral) expr; | ||
JvmType type = operator.getType(); | ||
JvmTypeReference reference = this.typeReferences.createTypeRef(type); | ||
assertEquals("String", this.uiStrings.referenceToString(reference, "the-default-value")); | ||
} | ||
|
||
@Test | ||
public void testReferenceToString_2() throws Exception { | ||
XExpression expr = expression("null as foo.String", true); | ||
assertTrue(expr instanceof XCastedExpression); | ||
XCastedExpression operator = (XCastedExpression) expr; | ||
JvmTypeReference reference = operator.getType(); | ||
assertEquals("String", this.uiStrings.referenceToString(reference, "the-default-value")); | ||
} | ||
|
||
@Test | ||
public void testReferenceToString_3() throws Exception { | ||
XExpression expr = expression("{ var foo.String x }", false); | ||
assertNotNull(expr); | ||
XVariableDeclaration declaration = (XVariableDeclaration) (((XBlockExpression) expr).getExpressions().get(0)); | ||
JvmTypeReference reference = declaration.getType(); | ||
assertEquals("String", this.uiStrings.referenceToString(reference, "the-default-value")); | ||
} | ||
|
||
} |