Search in sources :

Example 6 with JvmFeature

use of org.eclipse.xtext.common.types.JvmFeature in project xtext-xtend by eclipse.

the class DispatchHelper method getAllDispatchMethods.

protected List<JvmOperation> getAllDispatchMethods(DispatchSignature signature, JvmDeclaredType type, ContextualVisibilityHelper contextualVisibilityHelper) {
    List<JvmOperation> allOperations = Lists.newArrayListWithExpectedSize(5);
    Iterable<JvmFeature> allFeatures = type.findAllFeaturesByName(signature.getDispatchCaseName());
    for (JvmFeature feature : allFeatures) {
        if (feature instanceof JvmOperation) {
            JvmOperation operationByName = (JvmOperation) feature;
            if (signature.isDispatchCase(operationByName) && contextualVisibilityHelper.isVisible(operationByName)) {
                allOperations.add(operationByName);
            }
        }
    }
    sort(allOperations);
    return allOperations;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmFeature(org.eclipse.xtext.common.types.JvmFeature)

Example 7 with JvmFeature

use of org.eclipse.xtext.common.types.JvmFeature in project xtext-xtend by eclipse.

the class AbstractXtendOutlineTreeBuilder method buildMembers.

protected void buildMembers(final JvmDeclaredType inferredType, final JvmDeclaredType baseType, @Extension final IXtendOutlineContext context) {
    EList<JvmMember> _members = inferredType.getMembers();
    for (final JvmMember member : _members) {
        boolean _isProcessed = context.isProcessed(member);
        boolean _not = (!_isProcessed);
        if (_not) {
            if ((member instanceof JvmDeclaredType)) {
                boolean _isShowInherited = context.isShowInherited();
                if (_isShowInherited) {
                    final IXtendOutlineContext typeContext = context.newContext();
                    final EObject sourceElement = this._iXtendJvmAssociations.getPrimarySourceElement(member);
                    if ((sourceElement instanceof XtendTypeDeclaration)) {
                        this.buildType(sourceElement, typeContext);
                    } else {
                        this.buildJvmType(((JvmDeclaredType) member), typeContext);
                    }
                } else {
                    this.buildJvmType(((JvmDeclaredType) member), context);
                }
            } else {
                if ((member instanceof JvmFeature)) {
                    boolean _skipFeature = this.skipFeature(((JvmFeature) member));
                    boolean _not_1 = (!_skipFeature);
                    if (_not_1) {
                        final IXtendOutlineContext featureContext = this.buildFeature(baseType, ((JvmFeature) member), member, context);
                        final Consumer<JvmGenericType> _function = (JvmGenericType it) -> {
                            this.buildJvmType(it, featureContext.newContext());
                        };
                        ((JvmFeature) member).getLocalClasses().forEach(_function);
                    }
                }
            }
            context.markAsProcessed(member);
        }
    }
    boolean _isShowInherited_1 = context.isShowInherited();
    if (_isShowInherited_1) {
        this.buildInheritedMembers(inferredType, context);
    }
}
Also used : JvmFeature(org.eclipse.xtext.common.types.JvmFeature) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember)

Example 8 with JvmFeature

use of org.eclipse.xtext.common.types.JvmFeature in project xtext-eclipse by eclipse.

the class XbaseReferenceUpdater method resolveNameConflict.

@Override
protected String resolveNameConflict(EObject referringElement, EReference reference, EObject newTargetElement, IRefactoringUpdateAcceptor updateAcceptor) {
    if (EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_IDENTIFIABLE_ELEMENT, reference.getEReferenceType())) {
        if (newTargetElement instanceof JvmType) {
            JvmType type = (JvmType) newTargetElement;
            if (canLinkJvmType(referringElement, type)) {
                return toString(qualifiedNameProvider.getFullyQualifiedName(type));
            }
        }
        if (newTargetElement instanceof JvmFeature) {
            JvmFeature feature = (JvmFeature) newTargetElement;
            if (feature.isStatic() && !isStaticExtensionFeatureCall(referringElement, reference, newTargetElement)) {
                JvmDeclaredType declaringType = feature.getDeclaringType();
                if (canLinkJvmType(referringElement, declaringType)) {
                    JvmDeclaredType parentType = declaringType;
                    List<String> segments = new LinkedList<String>();
                    segments.add(feature.getSimpleName());
                    segments.add(0, parentType.getSimpleName());
                    while (!hasImportedType(updateAcceptor, parentType)) {
                        parentType = parentType.getDeclaringType();
                        if (parentType == null) {
                            return toString(qualifiedNameProvider.getFullyQualifiedName(feature));
                        }
                        segments.add(0, parentType.getSimpleName());
                    }
                    return toString(QualifiedName.create(segments));
                }
            }
        }
    }
    return super.resolveNameConflict(referringElement, reference, newTargetElement, updateAcceptor);
}
Also used : JvmFeature(org.eclipse.xtext.common.types.JvmFeature) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmType(org.eclipse.xtext.common.types.JvmType) LinkedList(java.util.LinkedList)

Example 9 with JvmFeature

use of org.eclipse.xtext.common.types.JvmFeature in project xtext-eclipse by eclipse.

the class XbaseHoverDocumentationProvider method handleLink.

protected void handleLink(List<?> fragments) {
    if (fragments == null || fragments.isEmpty()) {
        return;
    }
    URI elementURI = null;
    String firstFragment = fragments.get(0).toString();
    int hashIndex = firstFragment.indexOf("#");
    if (hashIndex != -1) {
        JvmDeclaredType resolvedDeclarator = getResolvedDeclarator(firstFragment.substring(0, hashIndex));
        if (resolvedDeclarator != null && !resolvedDeclarator.eIsProxy()) {
            String signature = firstFragment.substring(hashIndex + 1);
            int indexOfOpenBracket = signature.indexOf("(");
            int indexOfClosingBracket = signature.indexOf(")");
            String simpleNameOfFeature = indexOfOpenBracket != -1 ? signature.substring(0, indexOfOpenBracket) : signature;
            Iterable<JvmFeature> possibleCandidates = resolvedDeclarator.findAllFeaturesByName(simpleNameOfFeature);
            List<String> parameterNames = null;
            if (indexOfOpenBracket != -1 && indexOfClosingBracket != -1) {
                parameterNames = Strings.split(signature.substring(indexOfOpenBracket + 1, indexOfClosingBracket), ",");
            }
            Iterator<JvmFeature> featureIterator = possibleCandidates.iterator();
            while (elementURI == null && featureIterator.hasNext()) {
                JvmFeature feature = featureIterator.next();
                boolean valid = false;
                if (feature instanceof JvmField) {
                    valid = true;
                } else if (feature instanceof JvmExecutable) {
                    JvmExecutable executable = (JvmExecutable) feature;
                    EList<JvmFormalParameter> parameters = executable.getParameters();
                    if (parameterNames == null) {
                        valid = true;
                    } else if (parameters.size() == parameterNames.size()) {
                        valid = true;
                        for (int i = 0; (i < parameterNames.size() && valid); i++) {
                            URI parameterTypeURI = EcoreUtil.getURI(parameters.get(i).getParameterType().getType());
                            IEObjectDescription expectedParameter = scopeProvider.getScope(context, new HoverReference(TypesPackage.Literals.JVM_TYPE)).getSingleElement(qualifiedNameConverter.toQualifiedName(parameterNames.get(i)));
                            if (expectedParameter == null || !expectedParameter.getEObjectURI().equals(parameterTypeURI)) {
                                valid = false;
                            }
                        }
                    }
                }
                if (valid)
                    elementURI = EcoreUtil.getURI(feature);
            }
        }
    } else {
        IScope scope = scopeProvider.getScope(context, new HoverReference(TypesPackage.Literals.JVM_TYPE));
        IEObjectDescription singleElement = scope.getSingleElement(qualifiedNameConverter.toQualifiedName(firstFragment));
        if (singleElement != null)
            elementURI = singleElement.getEObjectURI();
    }
    String label = "";
    if (fragments.size() > 1) {
        for (int i = 1; i < fragments.size(); i++) {
            String portentialLabel = fragments.get(i).toString();
            if (portentialLabel.trim().length() > 0)
                label += portentialLabel;
        }
    }
    if (label.length() == 0)
        label = firstFragment;
    if (elementURI == null)
        buffer.append(label);
    else {
        buffer.append(createLinkWithLabel(XtextElementLinks.XTEXTDOC_SCHEME, elementURI, label));
    }
}
Also used : JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) EList(org.eclipse.emf.common.util.EList) JvmFeature(org.eclipse.xtext.common.types.JvmFeature) IScope(org.eclipse.xtext.scoping.IScope) JvmField(org.eclipse.xtext.common.types.JvmField)

Example 10 with JvmFeature

use of org.eclipse.xtext.common.types.JvmFeature in project xtext-eclipse by eclipse.

the class XbaseHyperLinkHelper method createHyperlinksByOffset.

@Override
public void createHyperlinksByOffset(final XtextResource resource, final int offset, final IHyperlinkAcceptor acceptor) {
    final EObject element = getEObjectAtOffsetHelper().resolveElementAt(resource, offset);
    if (element instanceof XImportDeclaration) {
        XImportDeclaration importDeclaration = (XImportDeclaration) element;
        if (importDeclaration.isStatic() && !importDeclaration.isWildcard()) {
            final ITextRegion textRegion = getTextRegion(importDeclaration, offset);
            if (textRegion != null) {
                final Region region = new Region(textRegion.getOffset(), textRegion.getLength());
                Iterable<JvmFeature> _allFeatures = staticImpMemberProvider.getAllFeatures(importDeclaration);
                for (final JvmFeature feature : _allFeatures) {
                    this.createHyperlinksTo(resource, region, feature, acceptor);
                }
            }
        }
    }
    super.createHyperlinksByOffset(resource, offset, acceptor);
    if (canShowMany(acceptor)) {
        if (element instanceof XVariableDeclaration) {
            XVariableDeclaration variableDeclaration = (XVariableDeclaration) element;
            ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
            if (isNameNode(element, XbasePackage.Literals.XVARIABLE_DECLARATION__NAME, node) && variableDeclaration.getType() == null) {
                addOpenInferredTypeHyperlink(resource, variableDeclaration, node, acceptor);
            }
        }
        if (element instanceof JvmFormalParameter) {
            JvmFormalParameter param = (JvmFormalParameter) element;
            ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
            if (isNameNode(element, TypesPackage.Literals.JVM_FORMAL_PARAMETER__NAME, node) && param.getParameterType() == null) {
                addOpenInferredTypeHyperlink(resource, param, node, acceptor);
            }
        }
    }
}
Also used : XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) JvmFeature(org.eclipse.xtext.common.types.JvmFeature) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) Region(org.eclipse.jface.text.Region) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration)

Aggregations

JvmFeature (org.eclipse.xtext.common.types.JvmFeature)12 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)6 EObject (org.eclipse.emf.ecore.EObject)4 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)3 XImportDeclaration (org.eclipse.xtext.xtype.XImportDeclaration)3 StyledString (org.eclipse.jface.viewers.StyledString)2 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)2 JvmMember (org.eclipse.xtext.common.types.JvmMember)2 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)2 LinkedList (java.util.LinkedList)1 EList (org.eclipse.emf.common.util.EList)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 JavaElementImageDescriptor (org.eclipse.jdt.ui.JavaElementImageDescriptor)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 Region (org.eclipse.jface.text.Region)1 Image (org.eclipse.swt.graphics.Image)1 CreateExtensionInfo (org.eclipse.xtend.core.xtend.CreateExtensionInfo)1 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)1 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)1