use of org.eclipse.xtend.core.xtend.XtendExecutable 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.XtendExecutable 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.XtendExecutable in project xtext-xtend by eclipse.
the class XtendQuickfixProvider method addThrowsDeclaration.
@Fix(org.eclipse.xtext.xbase.validation.IssueCodes.UNHANDLED_EXCEPTION)
public void addThrowsDeclaration(final Issue issue, IssueResolutionAcceptor acceptor) {
if (issue.getData() != null && issue.getData().length > 0)
acceptor.accept(issue, "Add throws declaration", "Add throws declaration", "fix_indent.gif", new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
String[] issueData = issue.getData();
XtendExecutable xtendExecutable = EcoreUtil2.getContainerOfType(element, XtendExecutable.class);
XtextResource xtextResource = (XtextResource) xtendExecutable.eResource();
List<JvmType> exceptions = getExceptions(issueData, xtextResource);
if (exceptions.size() > 0) {
int insertPosition;
if (xtendExecutable.getExpression() == null) {
ICompositeNode functionNode = NodeModelUtils.findActualNodeFor(xtendExecutable);
if (functionNode == null)
throw new IllegalStateException("functionNode may not be null");
insertPosition = functionNode.getEndOffset();
} else {
ICompositeNode expressionNode = NodeModelUtils.findActualNodeFor(xtendExecutable.getExpression());
if (expressionNode == null)
throw new IllegalStateException("expressionNode may not be null");
insertPosition = expressionNode.getOffset();
}
ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) xtendExecutable.eResource(), insertPosition, 0);
if (xtendExecutable.getExpression() == null)
appendable.append(" ");
EList<JvmTypeReference> thrownExceptions = xtendExecutable.getExceptions();
if (thrownExceptions.isEmpty())
appendable.append("throws ");
else
appendable.append(", ");
for (int i = 0; i < exceptions.size(); i++) {
appendable.append(exceptions.get(i));
if (i != exceptions.size() - 1) {
appendable.append(", ");
}
}
if (xtendExecutable.getExpression() != null)
appendable.append(" ");
appendable.commitChanges();
}
}
});
}
Aggregations