use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class CreateXtendTypeQuickfixes method newLocalXtendInterfaceQuickfix.
protected void newLocalXtendInterfaceQuickfix(String typeName, XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
EObject eObject = resource.getEObject(issue.getUriToProblem().fragment());
XtendTypeDeclaration xtendType = getAnnotationTarget(eObject);
if (xtendType != null) {
JvmDeclaredType inferredType = associations.getInferredType(xtendType);
if (inferredType != null) {
AbstractInterfaceBuilder interfaceBuilder = codeBuilderFactory.createInterfaceBuilder(inferredType);
interfaceBuilder.setInterfaceName(typeName);
interfaceBuilder.setVisibility(JvmVisibility.PUBLIC);
interfaceBuilder.setContext(xtendType);
interfaceBuilder.setImage("xtend_file.png");
codeBuilderQuickfix.addQuickfix(interfaceBuilder, "Create local Xtend interface '" + typeName + "'", issue, issueResolutionAcceptor);
}
}
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class XtendQuickfixProvider method doOverrideMethods.
protected void doOverrideMethods(final Issue issue, IssueResolutionAcceptor acceptor, String label, final String[] operationUris) {
acceptor.accept(issue, label, label, "fix_indent.gif", new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
XtendTypeDeclaration clazz = (XtendTypeDeclaration) element;
JvmGenericType inferredType = (JvmGenericType) associations.getInferredType(clazz);
ResolvedFeatures resolvedOperations = overrideHelper.getResolvedFeatures(inferredType);
IXtextDocument document = context.getXtextDocument();
final int offset = insertionOffsets.getNewMethodInsertOffset(null, clazz);
int currentIndentation = appendableFactory.getIndentationLevelAtOffset(offset, document, (XtextResource) clazz.eResource());
final int indentationToUse = clazz.getMembers().isEmpty() ? currentIndentation + 1 : currentIndentation;
ReplacingAppendable appendable = appendableFactory.create(document, (XtextResource) clazz.eResource(), offset, 0, new OptionalParameters() {
{
ensureEmptyLinesAround = true;
baseIndentationLevel = indentationToUse;
}
});
boolean isFirst = true;
for (String operationUriAsString : operationUris) {
URI operationURI = URI.createURI(operationUriAsString);
EObject overridden = clazz.eResource().getResourceSet().getEObject(operationURI, true);
if (overridden instanceof JvmOperation) {
if (!isFirst)
appendable.newLine().newLine();
isFirst = false;
superMemberImplementor.appendOverrideFunction(clazz, resolvedOperations.getResolvedOperation((JvmOperation) overridden), appendable);
}
}
appendable.commitChanges();
}
});
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class InsertionOffsetTest method checkTypeInsertionOffset.
protected void checkTypeInsertionOffset(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.getNewTypeInsertOffset(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 checkConstructorInsertionOffset.
protected void checkConstructorInsertionOffset(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.getNewConstructorInsertOffset(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 XtendHoverSignatureProviderTest method testInterfaceReference.
@Test
public void testInterfaceReference() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package testPackage");
_builder.newLine();
_builder.append("class Bar implements Foo {");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("interface Foo { }");
_builder.newLine();
final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
final JvmType in = IterableExtensions.<JvmTypeReference>head(((XtendClass) _head).getImplements()).getType();
Assert.assertEquals("Foo", this.signatureProvider.getSignature(in));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations