use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredFunction_02.
@Test
public void testInferredFunction_02() throws Exception {
XtendFile xtendFile = file("class Foo { def create result: newArrayList(s) newList(String s) {} }");
JvmGenericType inferredType = getInferredType(xtendFile);
XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
EList<JvmMember> jvmMembers = inferredType.getMembers();
assertEquals(4, jvmMembers.size());
JvmMember jvmMember = jvmMembers.get(1);
assertTrue(jvmMember instanceof JvmOperation);
XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0);
assertEquals(xtendFunction.getName(), jvmMember.getSimpleName());
assertEquals(JvmVisibility.PUBLIC, jvmMember.getVisibility());
assertEquals("java.util.ArrayList<java.lang.String>", ((JvmOperation) jvmMember).getReturnType().getIdentifier());
JvmField cacheVar = (JvmField) jvmMembers.get(2);
assertEquals("_createCache_" + xtendFunction.getName(), cacheVar.getSimpleName());
assertEquals(JvmVisibility.PRIVATE, cacheVar.getVisibility());
assertEquals("java.util.HashMap<java.util.ArrayList<? extends java.lang.Object>, java.util.ArrayList<java.lang.String>>", cacheVar.getType().getIdentifier());
JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3);
assertEquals("_init_" + xtendFunction.getName(), privateInitializer.getSimpleName());
assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility());
assertEquals("java.util.ArrayList<java.lang.String>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredJvmConstructor.
@Test
public void testInferredJvmConstructor() throws Exception {
XtendFile xtendFile = file("class Foo { }");
JvmGenericType inferredType = getInferredType(xtendFile);
XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
assertEquals(1, inferredType.getMembers().size());
JvmMember inferredFirstMember = inferredType.getMembers().get(0);
assertTrue(inferredFirstMember instanceof JvmConstructor);
assertEquals(JvmVisibility.PUBLIC, inferredFirstMember.getVisibility());
assertEquals(associations.getInferredConstructor(xtendClass), inferredFirstMember);
}
use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.
the class AbstractMultiModeOutlineTreeProvider method computeDecoratedText.
protected Object computeDecoratedText(final Object modelElement, final int inheritanceDepth) {
Object supertext = super.getText(modelElement);
if (!(supertext instanceof StyledString)) {
return supertext;
}
StyledString styledText = (StyledString) supertext;
if (inheritanceDepth > 0) {
styledText = applyStylerToFirstSegment(styledText, ColoringLabelProvider.INHERITED_STYLER);
}
if (modelElement instanceof JvmIdentifiableElement) {
JvmIdentifiableElement jvmElement = (JvmIdentifiableElement) modelElement;
if (!getAssociations().getSourceElements(jvmElement).isEmpty() && !getAssociations().isPrimaryJvmElement(jvmElement)) {
styledText = applyStylerToFirstSegment(styledText, StyledString.QUALIFIER_STYLER);
}
}
if (isShowInherited()) {
if (modelElement instanceof IResolvedFeature) {
String qualifier = createQualifier((IResolvedFeature) modelElement);
appendQualifier(styledText, qualifier);
} else if (modelElement instanceof JvmMember) {
String qualifier = createQualifier((JvmMember) modelElement);
appendQualifier(styledText, qualifier);
} else if (modelElement instanceof XtendMember) {
XtendMember xtendMember = (XtendMember) modelElement;
if (xtendMember.eContainer() instanceof XtendTypeDeclaration) {
String qualifiedName = createQualifier((XtendTypeDeclaration) xtendMember.eContainer(), '.');
appendQualifier(styledText, qualifiedName);
} else if (xtendMember instanceof XtendTypeDeclaration) {
XtendFile xtendFile = EcoreUtil2.getContainerOfType(xtendMember, XtendFile.class);
String qualifiedName = xtendFile.getPackage() == null ? "(default package)" : xtendFile.getPackage();
appendQualifier(styledText, qualifiedName);
}
}
}
return styledText;
}
use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.
the class DependentElementsCalculatorTests method testPolymorphicDispatch.
@Test
public void testPolymorphicDispatch() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("def dispatch foo(Number it) {");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("def dispatch foo(String it) {");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile fooFile = this.testHelper.xtendFile("Foo", _builder.toString());
IResourcesSetupUtil.waitForBuild();
XtendTypeDeclaration _get = fooFile.getXtendTypes().get(0);
final XtendClass fooClass = ((XtendClass) _get);
final XtendMember fooMethod1 = fooClass.getMembers().get(1);
NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
final Iterable<URI> dependentElementURIs = this.dependentElementsCalculator.getDependentElementURIs(fooMethod1, _nullProgressMonitor);
Assert.assertEquals(5, IterableExtensions.size(dependentElementURIs));
EList<XtendMember> _members = fooClass.getMembers();
EList<JvmMember> _members_1 = this.associations.getInferredType(fooClass).getMembers();
final Function1<EObject, Boolean> _function = (EObject it) -> {
return Boolean.valueOf((!(it instanceof JvmConstructor)));
};
final Consumer<EObject> _function_1 = (EObject it) -> {
final Function1<URI, Boolean> _function_2 = (URI element) -> {
URI _uRI = EcoreUtil.getURI(it);
return Boolean.valueOf(Objects.equal(element, _uRI));
};
Assert.assertTrue(it.toString(), IterableExtensions.<URI>exists(dependentElementURIs, _function_2));
};
IterableExtensions.<EObject>toList(IterableExtensions.<EObject>filter(Iterables.<EObject>concat(_members, _members_1), _function)).forEach(_function_1);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.
the class AbstractKnownTypesScope method findNestedType.
protected JvmType findNestedType(JvmType result, int index, QualifiedName name) {
List<String> segments = name.getSegmentCount() == 1 ? Strings.split(name.getFirstSegment(), '$') : name.getSegments();
for (int i = 1; i < segments.size() && result instanceof JvmDeclaredType; i++) {
JvmDeclaredType declaredType = (JvmDeclaredType) result;
String simpleName = segments.get(i);
// TODO handle ambiguous types
for (JvmMember member : declaredType.findAllNestedTypesByName(simpleName)) {
result = (JvmType) member;
break;
}
if (declaredType == result) {
return null;
}
}
return result;
}
Aggregations