use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class InsertionOffsetTest method checkMethodInsertionOffset.
protected void checkMethodInsertionOffset(final CharSequence model) {
try {
final String modelAsString = model.toString();
final int caretOffset = modelAsString.replace("$", "").indexOf("|");
final int expectedOffset = modelAsString.replace("|", "").indexOf("$");
XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.parseHelper.parse(modelAsString.replace("|", "").replace("$", "")).getXtendTypes());
final XtendClass xtendClass = ((XtendClass) _head);
Resource _eResource = xtendClass.eResource();
final XtextResource xtextResource = ((XtextResource) _eResource);
final EObject caretElement = this._eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, caretOffset);
Assert.assertEquals(expectedOffset, this._insertionOffsets.getNewMethodInsertOffset(caretElement, xtendClass));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class InsertionOffsetTest method checkFieldInsertionOffset.
protected void checkFieldInsertionOffset(final CharSequence model) {
try {
final String modelAsString = model.toString();
final int caretOffset = modelAsString.replace("$", "").indexOf("|");
final int expectedOffset = modelAsString.replace("|", "").indexOf("$");
XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.parseHelper.parse(modelAsString.replace("|", "").replace("$", "")).getXtendTypes());
final XtendClass xtendClass = ((XtendClass) _head);
Resource _eResource = xtendClass.eResource();
final XtextResource xtextResource = ((XtextResource) _eResource);
final EObject caretElement = this._eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, caretOffset);
Assert.assertEquals(expectedOffset, this._insertionOffsets.getNewFieldInsertOffset(caretElement, xtendClass));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class DependentElementsCalculatorTests method testDependentElements.
@Test
public void testDependentElements() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("def Foo foo() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("new Foo()");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.testHelper.xtendFile("Foo", _builder.toString());
XtendTypeDeclaration _get = file.getXtendTypes().get(0);
final XtendClass fooClass = ((XtendClass) _get);
NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
final Iterable<URI> dependentElementURIs = this.dependentElementsCalculator.getDependentElementURIs(fooClass, _nullProgressMonitor);
Assert.assertEquals(3, IterableExtensions.size(dependentElementURIs));
XtendMember _get_1 = fooClass.getMembers().get(0);
final XtendFunction fooFunction = ((XtendFunction) _get_1);
final Consumer<EObject> _function = (EObject it) -> {
final Function1<URI, Boolean> _function_1 = (URI element) -> {
URI _uRI = EcoreUtil.getURI(it);
return Boolean.valueOf(Objects.equal(element, _uRI));
};
Assert.assertTrue(it.toString(), IterableExtensions.<URI>exists(dependentElementURIs, _function_1));
};
CollectionLiterals.<EObject>newArrayList(fooFunction, this.associations.getInferredType(fooClass), this.associations.getInferredConstructor(fooClass)).forEach(_function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration 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.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class AbstractMultiModeOutlineTreeProvider method createQualifier.
private String createQualifier(XtendTypeDeclaration xtendType, char innerClassDelimiter) {
if (xtendType.getName() == null)
return null;
XtendTypeDeclaration declaringType = null;
if (xtendType.eContainer() instanceof XtendTypeDeclaration) {
declaringType = (XtendTypeDeclaration) xtendType.eContainer();
}
if (declaringType == null) {
return xtendType.getName();
}
String qualifier = xtendType.getName();
while (xtendType.eContainer() instanceof XtendTypeDeclaration) {
XtendTypeDeclaration parent = (XtendTypeDeclaration) xtendType.eContainer();
qualifier = parent.getName() + innerClassDelimiter + qualifier;
xtendType = parent;
}
return qualifier;
}
Aggregations