Search in sources :

Example 41 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.

the class XbaseHoverDocumentationProvider method getResolvedDeclarator.

protected JvmDeclaredType getResolvedDeclarator(String name) {
    JvmDeclaredType jvmDeclaredType = null;
    if (Strings.isEmpty(name) || name.trim().length() == 0) {
        jvmDeclaredType = getDeclaringType(context);
    } else {
        HoverReference reference = new HoverReference(TypesPackage.Literals.JVM_TYPE);
        IScope scope = scopeProvider.getScope(context, reference);
        IEObjectDescription declarator = scope.getSingleElement(qualifiedNameConverter.toQualifiedName(name));
        if (declarator != null && EcoreUtil2.isAssignableFrom(TypesPackage.eINSTANCE.getJvmGenericType(), declarator.getEClass())) {
            jvmDeclaredType = (JvmDeclaredType) context.eResource().getResourceSet().getEObject(declarator.getEObjectURI(), true);
        }
    }
    return jvmDeclaredType;
}
Also used : JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) IScope(org.eclipse.xtext.scoping.IScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 42 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.

the class JavaTypeQuickfixes method addQuickfixes.

@Override
public void addQuickfixes(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, IXtextDocument xtextDocument, XtextResource resource, EObject referenceOwner, EReference unresolvedReference) throws Exception {
    String issueString = xtextDocument.get(issue.getOffset(), issue.getLength());
    IScope scope = scopeProvider.getScope(referenceOwner, unresolvedReference);
    boolean useJavaSearch = isUseJavaSearch(unresolvedReference, issue);
    if (useJavaSearch) {
        JvmDeclaredType jvmType = importsConfiguration.getContextJvmDeclaredType(referenceOwner);
        IJavaSearchScope javaSearchScope = getJavaSearchScope(referenceOwner);
        boolean proposeImports = true;
        if (isConstructorReference(unresolvedReference))
            proposeImports = !createConstructorProposals(jvmType, issue, issueString, javaSearchScope, issueResolutionAcceptor);
        if (proposeImports)
            createImportProposals(jvmType, issue, issueString, javaSearchScope, issueResolutionAcceptor);
        scope = getImportedTypesScope(referenceOwner, issueString, scope, javaSearchScope);
    }
    List<IEObjectDescription> discardedDescriptions = Lists.newArrayList();
    Set<String> proposedSolutions = Sets.newHashSet();
    int addedDescriptions = 0;
    int checkedDescriptions = 0;
    for (IEObjectDescription referableElement : scope.getAllElements()) {
        String solution = qualifiedNameConverter.toString(referableElement.getName());
        if (!equal(issueString, solution) && proposedSolutions.add(solution)) {
            if (useJavaSearch || similarityMatcher.isSimilar(issueString, solution)) {
                addedDescriptions++;
                createResolution(issue, issueResolutionAcceptor, issueString, referableElement);
                proposedSolutions.add(solution);
            } else {
                discardedDescriptions.add(referableElement);
            }
        }
        checkedDescriptions++;
        if (checkedDescriptions > 100)
            break;
    }
    if (discardedDescriptions.size() + addedDescriptions <= 5) {
        for (IEObjectDescription referableElement : discardedDescriptions) {
            createResolution(issue, issueResolutionAcceptor, issueString, referableElement);
        }
    }
}
Also used : IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) IScope(org.eclipse.xtext.scoping.IScope) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 43 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.

the class AbstractHierarchyBuilderTest method toExpectation.

protected String toExpectation(final IHierarchyNode node, final IHierarchyBuilder builder) {
    StringConcatenation _builder = new StringConcatenation();
    IEObjectDescription _element = node.getElement();
    _builder.append(_element);
    _builder.append(" {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    String _internalToExpectation = this.internalToExpectation(node, builder);
    _builder.append(_internalToExpectation, "\t");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    _builder.newLine();
    return _builder.toString();
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 44 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.

the class RefactoringCrossReferenceSerializer method getCrossRefText.

public String getCrossRefText(EObject owner, CrossReference crossref, EObject target, RefTextEvaluator refTextEvaluator, ITextRegion linkTextRegion, StatusWrapper status) {
    try {
        final EReference ref = GrammarUtil.getReference(crossref, owner.eClass());
        final IScope scope = scopeProvider.getScope(owner, ref);
        if (scope == null) {
            throw new IllegalStateException("Could not create scope for the given cross reference.");
        }
        String ruleName = linkingHelper.getRuleNameFrom(crossref);
        Iterable<IEObjectDescription> descriptionsForCrossRef = scope.getElements(target);
        String bestRefText = null;
        List<String> badNames = new ArrayList<String>();
        for (IEObjectDescription desc : descriptionsForCrossRef) {
            try {
                String unconvertedRefText = qualifiedNameConverter.toString(desc.getName());
                String convertedRefText = valueConverter.toString(unconvertedRefText, ruleName);
                if (refTextEvaluator.isValid(desc) && (bestRefText == null || refTextEvaluator.isBetterThan(convertedRefText, bestRefText)))
                    bestRefText = convertedRefText;
            } catch (ValueConverterException e) {
                // this is a problem only if we don't find any matching value
                badNames.add(desc.getName().toString());
            }
        }
        if (bestRefText == null && !badNames.isEmpty()) {
            status.add(WARNING, "Misconfigured language: New reference text has invalid syntax. Following names are in the scope: " + IterableExtensions.join(badNames, ", "), owner, linkTextRegion);
        }
        return bestRefText;
    } catch (Exception exc) {
        log.error(exc.getMessage(), exc);
        status.add(ERROR, exc.getMessage(), owner, linkTextRegion);
        return null;
    }
}
Also used : ArrayList(java.util.ArrayList) IScope(org.eclipse.xtext.scoping.IScope) ValueConverterException(org.eclipse.xtext.conversion.ValueConverterException) EReference(org.eclipse.emf.ecore.EReference) ValueConverterException(org.eclipse.xtext.conversion.ValueConverterException) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 45 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.

the class OpenXtextElementHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Shell activeShell = HandlerUtil.getActiveShell(event);
    ListDialog searchDialog = createSearchDialog(event, activeShell, searchEngine);
    int result = searchDialog.open();
    if (result == Window.OK) {
        try {
            Object[] selections = searchDialog.getResult();
            if (selections != null && selections.length > 0) {
                Object selection = selections[0];
                if (selection instanceof IEObjectDescription) {
                    IEObjectDescription selectedObjectDescription = (IEObjectDescription) selection;
                    uriEditorOpener.open(selectedObjectDescription.getEObjectURI(), true);
                }
            }
        } catch (Exception e) {
            LOG.error("Error opening editor", e);
            throw new ExecutionException("Error opening editor", e);
        }
    }
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ExecutionException(org.eclipse.core.commands.ExecutionException) ListDialog(org.eclipse.ui.dialogs.ListDialog) ExecutionException(org.eclipse.core.commands.ExecutionException) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)324 Test (org.junit.Test)95 EObject (org.eclipse.emf.ecore.EObject)82 QualifiedName (org.eclipse.xtext.naming.QualifiedName)79 IScope (org.eclipse.xtext.scoping.IScope)56 URI (org.eclipse.emf.common.util.URI)41 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)33 EClass (org.eclipse.emf.ecore.EClass)30 Resource (org.eclipse.emf.ecore.resource.Resource)28 EObjectDescription (org.eclipse.xtext.resource.EObjectDescription)22 AliasedEObjectDescription (org.eclipse.xtext.resource.impl.AliasedEObjectDescription)22 ArrayList (java.util.ArrayList)19 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)14 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)12 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)12 StyledString (org.eclipse.jface.viewers.StyledString)12 XtextResource (org.eclipse.xtext.resource.XtextResource)11 StringInputStream (org.eclipse.xtext.util.StringInputStream)11 EReference (org.eclipse.emf.ecore.EReference)10 List (java.util.List)9