use of org.eclipse.xtext.common.types.JvmGenericArrayTypeReference in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method computeFieldName.
/* @Nullable */
protected String computeFieldName(XtendField field) {
if (field.getName() != null)
return field.getName();
JvmTypeReference type = field.getType();
String name = null;
if (type != null) {
while (type instanceof JvmGenericArrayTypeReference) {
type = ((JvmGenericArrayTypeReference) type).getComponentType();
}
if (type instanceof JvmParameterizedTypeReference) {
List<INode> nodes = NodeModelUtils.findNodesForFeature(type, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
if (!nodes.isEmpty()) {
String typeName = nodes.get(0).getText().trim();
int lastDot = typeName.lastIndexOf('.');
if (lastDot != -1) {
typeName = typeName.substring(lastDot + 1);
}
name = "_" + Strings.toFirstLower(typeName);
}
}
}
return name;
}
use of org.eclipse.xtext.common.types.JvmGenericArrayTypeReference in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method test_arrayParameterized_02.
@Test
public void test_arrayParameterized_02() {
JvmOperation arrayParameterized = getMethodFromParameterizedMethods("arrayParameterized(java.util.List[])");
JvmTypeReference paramType = arrayParameterized.getParameters().get(0).getParameterType();
assertEquals("java.util.List<T>[]", paramType.getIdentifier());
assertTrue(paramType.getType() instanceof JvmArrayType);
JvmArrayType arrayType = (JvmArrayType) paramType.getType();
assertTrue(arrayType.getComponentType() instanceof JvmDeclaredType);
assertTrue(paramType instanceof JvmGenericArrayTypeReference);
assertTrue(((JvmGenericArrayTypeReference) paramType).getComponentType() instanceof JvmParameterizedTypeReference);
}
use of org.eclipse.xtext.common.types.JvmGenericArrayTypeReference in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method testVarArgs_02.
@Test
public void testVarArgs_02() {
String typeName = ClassWithVarArgs.class.getName();
JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
JvmOperation method = getMethodFromType(type, ClassWithVarArgs.class, "method(java.lang.String[])");
assertTrue(method.isVarArgs());
assertEquals(1, method.getParameters().size());
assertTrue(method.getParameters().get(0).getParameterType() instanceof JvmGenericArrayTypeReference);
}
use of org.eclipse.xtext.common.types.JvmGenericArrayTypeReference in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method test_arrayWildcard_02.
@Test
public void test_arrayWildcard_02() {
JvmOperation arrayWildcard = getMethodFromParameterizedMethods("arrayWildcard(java.util.List[])");
JvmTypeReference paramType = arrayWildcard.getParameters().get(0).getParameterType();
assertEquals("java.util.List<? extends java.lang.Object>[]", paramType.getIdentifier());
assertTrue(paramType.getType() instanceof JvmArrayType);
JvmArrayType arrayType = (JvmArrayType) paramType.getType();
assertTrue(arrayType.getComponentType() instanceof JvmDeclaredType);
assertTrue(paramType instanceof JvmGenericArrayTypeReference);
assertTrue(((JvmGenericArrayTypeReference) paramType).getComponentType() instanceof JvmParameterizedTypeReference);
}
use of org.eclipse.xtext.common.types.JvmGenericArrayTypeReference in project xtext-eclipse by eclipse.
the class XtypeProposalProvider method appendParameters.
protected void appendParameters(StyledString result, JvmExecutable executable, int insignificantParameters, LightweightTypeReferenceFactory ownedConverter) {
List<JvmFormalParameter> declaredParameters = executable.getParameters();
List<JvmFormalParameter> relevantParameters = declaredParameters.subList(Math.min(insignificantParameters, declaredParameters.size()), declaredParameters.size());
for (int i = 0; i < relevantParameters.size(); i++) {
JvmFormalParameter parameter = relevantParameters.get(i);
if (i != 0)
result.append(", ");
if (i == relevantParameters.size() - 1 && executable.isVarArgs() && parameter.getParameterType() instanceof JvmGenericArrayTypeReference) {
JvmGenericArrayTypeReference parameterType = (JvmGenericArrayTypeReference) parameter.getParameterType();
result.append(ownedConverter.toLightweightReference(parameterType.getComponentType()).getHumanReadableName());
result.append("...");
} else {
if (parameter.getParameterType() != null) {
String simpleName = ownedConverter.toLightweightReference(parameter.getParameterType()).getHumanReadableName();
if (// is null if the file is not on the class path
simpleName != null)
result.append(simpleName);
}
}
result.append(' ');
result.append(notNull(parameter.getName()));
}
}
Aggregations