Search in sources :

Example 66 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName 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);
        }
    }
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) QualifiedName(org.eclipse.xtext.naming.QualifiedName) JdtVariableCompletions(org.eclipse.xtext.common.types.xtext.ui.JdtVariableCompletions) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Image(org.eclipse.swt.graphics.Image) XtendField(org.eclipse.xtend.core.xtend.XtendField) EObject(org.eclipse.emf.ecore.EObject) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 67 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-xtend by eclipse.

the class CreateMemberQuickfixes method getOperatorMethodName.

/* @Nullable */
protected String getOperatorMethodName(XAbstractFeatureCall call) {
    for (INode node : NodeModelUtils.findNodesForFeature(call, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE)) {
        for (ILeafNode leafNode : node.getLeafNodes()) {
            if (!leafNode.isHidden()) {
                String symbol = leafNode.getText();
                QualifiedName methodName = operatorMapping.getMethodName(QualifiedName.create(symbol));
                if (methodName != null)
                    return methodName.getFirstSegment();
            }
        }
    }
    return null;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) QualifiedName(org.eclipse.xtext.naming.QualifiedName)

Example 68 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-xtend by eclipse.

the class CreateXtendTypeQuickfixes method isTypeMissing.

protected boolean isTypeMissing(EObject referenceOwner, String typeName, String explicitPackage) {
    QualifiedName typeQName = (!isEmpty(explicitPackage)) ? converter.toQualifiedName(explicitPackage).append(typeName) : converter.toQualifiedName(typeName);
    final IScope typeScope = scopeProvider.getScope(referenceOwner, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
    return typeScope.getSingleElement(typeQName) == null;
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) IScope(org.eclipse.xtext.scoping.IScope)

Example 69 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-xtend by eclipse.

the class ImportedNamesTest method testNestedTypesIncluded.

@Test
public void testNestedTypesIncluded() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("val foo = types.StaticOuterClass.StaticMiddleClass.StaticInnerClass.CONSTANT");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.file(_builder.toString());
        final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource());
        final Iterable<QualifiedName> importedNames = description.getImportedNames();
        final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
            String _string = it.toString();
            String _lowerCase = "types.StaticOuterClass$StaticMiddleClass$StaticInnerClass".toLowerCase();
            return Boolean.valueOf(Objects.equal(_string, _lowerCase));
        };
        Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 70 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-xtend by eclipse.

the class ImportedNamesTest method testAnonymousClass.

@Test
public void testAnonymousClass() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("val foo = new Runnable() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("override run() {}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.file(_builder.toString());
        final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource());
        final Iterable<QualifiedName> importedNames = description.getImportedNames();
        final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
            return Boolean.valueOf(it.getLastSegment().equals("runnable"));
        };
        Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Aggregations

QualifiedName (org.eclipse.xtext.naming.QualifiedName)97 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)32 Test (org.junit.Test)31 EObject (org.eclipse.emf.ecore.EObject)27 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)16 EClass (org.eclipse.emf.ecore.EClass)12 Resource (org.eclipse.emf.ecore.resource.Resource)12 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)12 IScope (org.eclipse.xtext.scoping.IScope)10 Set (java.util.Set)9 URI (org.eclipse.emf.common.util.URI)7 XtextResource (org.eclipse.xtext.resource.XtextResource)7 StringInputStream (org.eclipse.xtext.util.StringInputStream)7 JvmType (org.eclipse.xtext.common.types.JvmType)6 Function (com.google.common.base.Function)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 InternalEObject (org.eclipse.emf.ecore.InternalEObject)4 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4