use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class XtendUIValidationTests method testForbiddenConstructorCallInnerClass.
@Test
public void testForbiddenConstructorCallInnerClass() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import org.eclipse.xtend.core.tests.restricted.RestrictedClass$InnerRestrictedClass");
_builder.newLine();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("InnerRestrictedClass x = new InnerRestrictedClass");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.testHelper.xtendFile("Clazz.xtend", _builder.toString());
this.helper.assertError(xtendFile.getImportSection().getImportDeclarations().get(0), XtypePackage.Literals.XIMPORT_DECLARATION, org.eclipse.xtext.xbase.validation.IssueCodes.FORBIDDEN_REFERENCE);
XtendMember _head = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers());
final XtendField field = ((XtendField) _head);
this.helper.assertError(field.getType(), TypesPackage.Literals.JVM_TYPE_REFERENCE, org.eclipse.xtext.xbase.validation.IssueCodes.FORBIDDEN_REFERENCE);
this.helper.assertError(field.getInitialValue(), XbasePackage.Literals.XCONSTRUCTOR_CALL, org.eclipse.xtext.xbase.validation.IssueCodes.FORBIDDEN_REFERENCE);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class XtendProposalProvider method completeMember_Name.
@Override
public void completeMember_Name(final EObject model, Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
if (announceProcessing(Lists.newArrayList("completeMember_Name", model, assignment.getFeature()))) {
EObject previousModel = context.getPreviousModel();
if (previousModel instanceof XExpression) {
if (!(previousModel instanceof XBlockExpression)) {
return;
}
}
if (model instanceof XtendField) {
// TODO go up type hierarchy and collect all local fields
final List<XtendField> siblings = EcoreUtil2.getSiblingsOfType(model, XtendField.class);
Set<String> alreadyTaken = Sets.newHashSet();
for (XtendField sibling : siblings) {
alreadyTaken.add(sibling.getName());
}
alreadyTaken.addAll(getAllKeywords());
completions.getVariableProposals(model, XtendPackage.Literals.XTEND_FIELD__TYPE, VariableType.INSTANCE_FIELD, alreadyTaken, new JdtVariableCompletions.CompletionDataAcceptor() {
@Override
public void accept(String replaceText, StyledString label, Image img) {
acceptor.accept(createCompletionProposal(replaceText, label, img, context));
}
});
} else if (model instanceof XtendFunction) {
for (QualifiedName operator : operatorMapping.getOperators()) {
StyledString displayString = new StyledString(operator.getFirstSegment());
displayString.append(" " + operatorMapping.getMethodName(operator), StyledString.DECORATIONS_STYLER);
acceptor.accept(createCompletionProposal(operator.getFirstSegment(), displayString, getImage(model), context));
}
super.completeMember_Name(model, assignment, context, acceptor);
} else {
super.completeMember_Name(model, assignment, context, acceptor);
}
}
}
use of org.eclipse.xtend.core.xtend.XtendField 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.XtendField 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.XtendField in project xtext-xtend by eclipse.
the class XtendHyperlinkHelper method createHyperlinksByOffset.
@Override
public void createHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) {
super.createHyperlinksByOffset(resource, offset, acceptor);
if (canShowMany(acceptor)) {
final EObject element = getEObjectAtOffsetHelper().resolveElementAt(resource, offset);
if (element instanceof XtendField) {
XtendField member = (XtendField) element;
ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
if (isNameNode(member, XtendPackage.Literals.XTEND_FIELD__NAME, node) && member.getType() == null) {
EObject jvmElement = associations.getPrimaryJvmElement(member);
if (jvmElement instanceof JvmIdentifiableElement) {
addOpenInferredTypeHyperlink(resource, (JvmIdentifiableElement) jvmElement, node, acceptor);
}
}
}
if (element instanceof XtendFunction) {
XtendFunction member = (XtendFunction) element;
ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
if (isNameNode(member, XtendPackage.Literals.XTEND_FUNCTION__NAME, node)) {
EObject jvmElement = associations.getPrimaryJvmElement(member);
if (jvmElement instanceof JvmIdentifiableElement) {
JvmIdentifiableElement identifiableElement = (JvmIdentifiableElement) jvmElement;
if (member.getReturnType() == null) {
addOpenInferredTypeHyperlink(resource, identifiableElement, node, acceptor);
}
IJavaElement javaElement = javaElementFinder.findExactElementFor(identifiableElement);
if (sourceViewer != null && javaElement != null && (javaElement.getElementType() == IJavaElement.METHOD && canBeOverridden((IMethod) javaElement))) {
Region region = new Region(node.getOffset(), node.getLength());
acceptor.accept(new XbaseImplementatorsHyperlink(javaElement, region, sourceViewer, implOpener));
}
}
}
}
}
}
Aggregations