use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class CodeBuilderQuickfix method getXtendModification.
protected IModification getXtendModification(final ICodeBuilder.Xtend builder) {
final IModification _function = (IModificationContext it) -> {
final XtendTypeDeclaration xtendClass = builder.getXtendType();
final IEditorPart editor = this.editorOpener.open(EcoreUtil.getURI(xtendClass), false);
if ((!(editor instanceof XtextEditor))) {
return;
}
final XtextEditor xtextEditor = ((XtextEditor) editor);
final IXtextDocument document = xtextEditor.getDocument();
final Wrapper<Integer> wrapper = Wrapper.<Integer>forType(Integer.class);
final IUnitOfWork<ReplacingAppendable, XtextResource> _function_1 = (XtextResource resource) -> {
ReplacingAppendable _xblockexpression = null;
{
int offset = builder.getInsertOffset(resource);
wrapper.set(Integer.valueOf(offset));
final int typeIndentation = this.getTypeIndentation(resource, document, xtendClass);
DocumentSourceAppender.Factory.OptionalParameters _optionalParameters = new DocumentSourceAppender.Factory.OptionalParameters();
final Procedure1<DocumentSourceAppender.Factory.OptionalParameters> _function_2 = (DocumentSourceAppender.Factory.OptionalParameters it_1) -> {
int _indentationLevel = builder.getIndentationLevel();
int _plus = (_indentationLevel + typeIndentation);
it_1.baseIndentationLevel = _plus;
it_1.ensureEmptyLinesAround = true;
};
DocumentSourceAppender.Factory.OptionalParameters _doubleArrow = ObjectExtensions.<DocumentSourceAppender.Factory.OptionalParameters>operator_doubleArrow(_optionalParameters, _function_2);
_xblockexpression = this.appendableFactory.create(document, resource, offset, 0, _doubleArrow);
}
return _xblockexpression;
};
final ReplacingAppendable appendable = document.<ReplacingAppendable>readOnly(_function_1);
Integer offset = wrapper.get();
builder.build(appendable);
appendable.commitChanges();
xtextEditor.setHighlightRange(((offset).intValue() + 1), appendable.length(), true);
};
return _function;
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class XtendProposalProvider method completeMember_Members.
@Override
public void completeMember_Members(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
if (isValidTypeForOverriding(model)) {
INode node = context.getCurrentNode();
EObject eObject = NodeModelUtils.findActualSemanticObjectFor(node);
if (!(eObject instanceof AnonymousClass)) {
overrideAssist.createOverrideProposals((XtendTypeDeclaration) model, context, acceptor, getConflictHelper());
return;
}
} else if (model instanceof XtendField) {
/*
* class C {
* static class C2 {
* toS<|>
* }
* }
*
* At this cursor position, we get a field without a name and the type 'toS' as the context.
* If there's a field decl preceding the cursor position, the field will have a name.
*/
XtendField field = (XtendField) model;
if (isValidTypeForOverriding(field.eContainer())) {
overrideAssist.createOverrideProposals((XtendTypeDeclaration) field.eContainer(), context, acceptor, getConflictHelper());
return;
}
} else if (model instanceof XtendExecutable && context.getPrefix().length() == 0 && isValidTypeForOverriding(model.eContainer())) {
overrideAssist.createOverrideProposals((XtendTypeDeclaration) model.eContainer(), context, acceptor, getConflictHelper());
return;
} else if (model instanceof XExpression) {
XtendMember member = EcoreUtil2.getContainerOfType(model, XtendMember.class);
INode memberNode = NodeModelUtils.findActualNodeFor(member);
if (memberNode.getTotalEndOffset() <= context.getOffset()) {
if (isValidTypeForOverriding(member.eContainer())) {
overrideAssist.createOverrideProposals((XtendTypeDeclaration) member.eContainer(), context, acceptor, getConflictHelper());
return;
}
}
}
INode node = context.getCurrentNode();
EObject eObject = NodeModelUtils.findActualSemanticObjectFor(node);
if (isValidTypeForOverriding(eObject))
overrideAssist.createOverrideProposals((XtendTypeDeclaration) eObject, context, acceptor, getConflictHelper());
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class XtendProposalProvider method completeXConstructorCall_Members.
@Override
public void completeXConstructorCall_Members(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
if (model instanceof AnonymousClass) {
overrideAssist.createOverrideProposals((AnonymousClass) model, context, acceptor, getConflictHelper());
return;
} else if (model instanceof XtendField) {
/*
* class C {
* val x = new Object() {
* toS<|>
* }
* }
*
* At this cursor position, we get a field without a name and the type 'toS' as the context.
* If there's a field decl preceding the cursor position, the field will have a name.
*/
XtendField field = (XtendField) model;
if (field.eContainer() instanceof AnonymousClass) {
overrideAssist.createOverrideProposals((AnonymousClass) field.eContainer(), context, acceptor, getConflictHelper());
return;
}
} else if (model instanceof XtendExecutable && context.getPrefix().length() == 0 && model.eContainer() instanceof AnonymousClass) {
overrideAssist.createOverrideProposals((AnonymousClass) model.eContainer(), context, acceptor, getConflictHelper());
return;
} else if (model instanceof XExpression) {
XtendMember member = EcoreUtil2.getContainerOfType(model, XtendMember.class);
INode memberNode = NodeModelUtils.findActualNodeFor(member);
if (memberNode.getTotalEndOffset() <= context.getOffset()) {
if (member.eContainer() instanceof AnonymousClass) {
overrideAssist.createOverrideProposals((AnonymousClass) member.eContainer(), context, acceptor, getConflictHelper());
return;
}
}
}
INode node = context.getCurrentNode();
EObject eObject = NodeModelUtils.findActualSemanticObjectFor(node);
if (eObject instanceof AnonymousClass)
overrideAssist.createOverrideProposals((XtendTypeDeclaration) eObject, context, acceptor, getConflictHelper());
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class CreateXtendTypeQuickfixes method newLocalXtendClassQuickfix.
protected void newLocalXtendClassQuickfix(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) {
AbstractClassBuilder classBuilder = codeBuilderFactory.createClassBuilder(inferredType);
classBuilder.setClassName(typeName);
classBuilder.setVisibility(JvmVisibility.PUBLIC);
classBuilder.setContext(xtendType);
classBuilder.setImage("xtend_file.png");
codeBuilderQuickfix.addQuickfix(classBuilder, "Create local Xtend class '" + typeName + "'", issue, issueResolutionAcceptor);
}
}
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class CreateXtendTypeQuickfixes method newLocalXtendAnnotationQuickfix.
protected void newLocalXtendAnnotationQuickfix(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) {
AbstractAnnotationBuilder annotationBuilder = codeBuilderFactory.createAnnotationBuilder(inferredType);
annotationBuilder.setAnnotationName(typeName);
annotationBuilder.setVisibility(JvmVisibility.PUBLIC);
annotationBuilder.setContext(xtendType);
codeBuilderQuickfix.addQuickfix(annotationBuilder, "Create local Xtend annotation '@" + typeName + "'", issue, issueResolutionAcceptor);
}
}
}
Aggregations