Search in sources :

Example 1 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class CompilationUnitImpl method toXtendMemberDeclaration.

public MemberDeclaration toXtendMemberDeclaration(final XtendMember delegate) {
    final Function1<XtendMember, XtendMemberDeclarationImpl<? extends XtendMember>> _function = (XtendMember it) -> {
        XtendMemberDeclarationImpl<? extends XtendMember> _switchResult = null;
        boolean _matched = false;
        if (delegate instanceof XtendTypeDeclaration) {
            _matched = true;
            _switchResult = this.toXtendTypeDeclaration(((XtendTypeDeclaration) delegate));
        }
        if (!_matched) {
            if (delegate instanceof XtendFunction) {
                _matched = true;
                XtendMethodDeclarationImpl _xtendMethodDeclarationImpl = new XtendMethodDeclarationImpl();
                final Procedure1<XtendMethodDeclarationImpl> _function_1 = (XtendMethodDeclarationImpl it_1) -> {
                    it_1.setDelegate(((XtendFunction) delegate));
                    it_1.setCompilationUnit(this);
                };
                _switchResult = ObjectExtensions.<XtendMethodDeclarationImpl>operator_doubleArrow(_xtendMethodDeclarationImpl, _function_1);
            }
        }
        if (!_matched) {
            if (delegate instanceof XtendConstructor) {
                _matched = true;
                XtendConstructorDeclarationImpl _xtendConstructorDeclarationImpl = new XtendConstructorDeclarationImpl();
                final Procedure1<XtendConstructorDeclarationImpl> _function_1 = (XtendConstructorDeclarationImpl it_1) -> {
                    it_1.setDelegate(((XtendConstructor) delegate));
                    it_1.setCompilationUnit(this);
                };
                _switchResult = ObjectExtensions.<XtendConstructorDeclarationImpl>operator_doubleArrow(_xtendConstructorDeclarationImpl, _function_1);
            }
        }
        if (!_matched) {
            if (delegate instanceof XtendField) {
                _matched = true;
                XtendMemberDeclarationImpl<XtendField> _xifexpression = null;
                EObject _eContainer = ((XtendField) delegate).eContainer();
                if ((_eContainer instanceof XtendAnnotationType)) {
                    XtendAnnotationTypeElementDeclarationImpl _xtendAnnotationTypeElementDeclarationImpl = new XtendAnnotationTypeElementDeclarationImpl();
                    final Procedure1<XtendAnnotationTypeElementDeclarationImpl> _function_1 = (XtendAnnotationTypeElementDeclarationImpl it_1) -> {
                        it_1.setDelegate(((XtendField) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<XtendAnnotationTypeElementDeclarationImpl>operator_doubleArrow(_xtendAnnotationTypeElementDeclarationImpl, _function_1);
                } else {
                    XtendFieldDeclarationImpl _xtendFieldDeclarationImpl = new XtendFieldDeclarationImpl();
                    final Procedure1<XtendFieldDeclarationImpl> _function_2 = (XtendFieldDeclarationImpl it_1) -> {
                        it_1.setDelegate(((XtendField) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<XtendFieldDeclarationImpl>operator_doubleArrow(_xtendFieldDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        if (!_matched) {
            if (delegate instanceof XtendEnumLiteral) {
                _matched = true;
                XtendEnumerationValueDeclarationImpl _xtendEnumerationValueDeclarationImpl = new XtendEnumerationValueDeclarationImpl();
                final Procedure1<XtendEnumerationValueDeclarationImpl> _function_1 = (XtendEnumerationValueDeclarationImpl it_1) -> {
                    it_1.setDelegate(((XtendEnumLiteral) delegate));
                    it_1.setCompilationUnit(this);
                };
                _switchResult = ObjectExtensions.<XtendEnumerationValueDeclarationImpl>operator_doubleArrow(_xtendEnumerationValueDeclarationImpl, _function_1);
            }
        }
        return _switchResult;
    };
    return this.<XtendMember, XtendMemberDeclarationImpl<? extends XtendMember>>getOrCreate(delegate, _function);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendMethodDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendMethodDeclarationImpl) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XtendEnumerationValueDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendEnumerationValueDeclarationImpl) XtendConstructorDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendConstructorDeclarationImpl) XtendField(org.eclipse.xtend.core.xtend.XtendField) XtendFieldDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendFieldDeclarationImpl) XtendAnnotationType(org.eclipse.xtend.core.xtend.XtendAnnotationType) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XtendAnnotationTypeElementDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendAnnotationTypeElementDeclarationImpl) XtendEnumLiteral(org.eclipse.xtend.core.xtend.XtendEnumLiteral) XtendMemberDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendMemberDeclarationImpl)

Example 2 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class AbstractMultiModeOutlineTreeProvider method computeDecoratedText.

protected Object computeDecoratedText(final Object modelElement, final int inheritanceDepth) {
    Object supertext = super.getText(modelElement);
    if (!(supertext instanceof StyledString)) {
        return supertext;
    }
    StyledString styledText = (StyledString) supertext;
    if (inheritanceDepth > 0) {
        styledText = applyStylerToFirstSegment(styledText, ColoringLabelProvider.INHERITED_STYLER);
    }
    if (modelElement instanceof JvmIdentifiableElement) {
        JvmIdentifiableElement jvmElement = (JvmIdentifiableElement) modelElement;
        if (!getAssociations().getSourceElements(jvmElement).isEmpty() && !getAssociations().isPrimaryJvmElement(jvmElement)) {
            styledText = applyStylerToFirstSegment(styledText, StyledString.QUALIFIER_STYLER);
        }
    }
    if (isShowInherited()) {
        if (modelElement instanceof IResolvedFeature) {
            String qualifier = createQualifier((IResolvedFeature) modelElement);
            appendQualifier(styledText, qualifier);
        } else if (modelElement instanceof JvmMember) {
            String qualifier = createQualifier((JvmMember) modelElement);
            appendQualifier(styledText, qualifier);
        } else if (modelElement instanceof XtendMember) {
            XtendMember xtendMember = (XtendMember) modelElement;
            if (xtendMember.eContainer() instanceof XtendTypeDeclaration) {
                String qualifiedName = createQualifier((XtendTypeDeclaration) xtendMember.eContainer(), '.');
                appendQualifier(styledText, qualifiedName);
            } else if (xtendMember instanceof XtendTypeDeclaration) {
                XtendFile xtendFile = EcoreUtil2.getContainerOfType(xtendMember, XtendFile.class);
                String qualifiedName = xtendFile.getPackage() == null ? "(default package)" : xtendFile.getPackage();
                appendQualifier(styledText, qualifiedName);
            }
        }
    }
    return styledText;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) EObject(org.eclipse.emf.ecore.EObject) JvmMember(org.eclipse.xtext.common.types.JvmMember) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) IResolvedFeature(org.eclipse.xtext.xbase.typesystem.override.IResolvedFeature)

Example 3 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class AbstractMultiModeOutlineTreeProvider method createQualifier.

private String createQualifier(XtendTypeDeclaration xtendType, char innerClassDelimiter) {
    if (xtendType.getName() == null)
        return null;
    XtendTypeDeclaration declaringType = null;
    if (xtendType.eContainer() instanceof XtendTypeDeclaration) {
        declaringType = (XtendTypeDeclaration) xtendType.eContainer();
    }
    if (declaringType == null) {
        return xtendType.getName();
    }
    String qualifier = xtendType.getName();
    while (xtendType.eContainer() instanceof XtendTypeDeclaration) {
        XtendTypeDeclaration parent = (XtendTypeDeclaration) xtendType.eContainer();
        qualifier = parent.getName() + innerClassDelimiter + qualifier;
        xtendType = parent;
    }
    return qualifier;
}
Also used : XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) StyledString(org.eclipse.jface.viewers.StyledString)

Example 4 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class XtendJavaElementDelegateJunitLaunch method getXtendClass.

/**
 * @param resource the Xtext resource to parse
 * @return if the resource contains exactly one class, returns the IJavaElement associated with that class,
 *			otherwise returns null
 */
private IJavaElement getXtendClass(XtextResource resource) {
    IParseResult parseResult = resource.getParseResult();
    if (parseResult == null) {
        return null;
    }
    EObject root = parseResult.getRootASTElement();
    if (root instanceof XtendFile) {
        XtendFile xtendFile = (XtendFile) root;
        EList<XtendTypeDeclaration> xtendTypes = xtendFile.getXtendTypes();
        if (xtendTypes.size() == 1) {
            XtendTypeDeclaration element = xtendTypes.get(0);
            JvmIdentifiableElement jvmElement = findAssociatedJvmElement(element);
            if (jvmElement == null) {
                return null;
            }
            IJavaElement javaElement = elementFinder.findElementFor(jvmElement);
            return javaElement;
        }
    }
    return null;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IJavaElement(org.eclipse.jdt.core.IJavaElement) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) IParseResult(org.eclipse.xtext.parser.IParseResult)

Example 5 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class XtendFileRenameParticipant method createRenameElementContexts.

@Override
protected List<? extends IRenameElementContext> createRenameElementContexts(Object element) {
    if (super.getNewName().endsWith(".xtend")) {
        IFile file = (IFile) element;
        final IPath filePath = file.getFullPath();
        final IPath newPath = file.getFullPath().removeLastSegments(1).append(getNewName() + ".xtend");
        String className = trimFileExtension(file.getName());
        if (className != null) {
            ResourceSet resourceSet = resourceSetProvider.get(file.getProject());
            URI resourceURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
            Resource resource = resourceSet.getResource(resourceURI, true);
            if (resource != null && !resource.getContents().isEmpty()) {
                for (XtendTypeDeclaration type : EcoreUtil2.eAllOfType(resource.getContents().get(0), XtendTypeDeclaration.class)) {
                    if (equal(className, type.getName())) {
                        IRenameElementContext renameElementContext = renameContextFactory.createRenameElementContext(type, null, null, (XtextResource) resource);
                        if (renameElementContext instanceof IChangeRedirector.Aware)
                            ((IChangeRedirector.Aware) renameElementContext).setChangeRedirector(new IChangeRedirector() {

                                @Override
                                public IPath getRedirectedPath(IPath source) {
                                    return source.equals(filePath) ? newPath : source;
                                }
                            });
                        return singletonList(renameElementContext);
                    }
                }
            }
        }
    }
    return super.createRenameElementContexts(element);
}
Also used : IFile(org.eclipse.core.resources.IFile) IChangeRedirector(org.eclipse.xtext.ui.refactoring.IChangeRedirector) IPath(org.eclipse.core.runtime.IPath) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) IRenameElementContext(org.eclipse.xtext.ui.refactoring.ui.IRenameElementContext) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Aggregations

XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)137 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)100 Test (org.junit.Test)92 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)76 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)57 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)39 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)39 XExpression (org.eclipse.xtext.xbase.XExpression)36 EObject (org.eclipse.emf.ecore.EObject)35 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)29 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)20 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)13 Resource (org.eclipse.emf.ecore.resource.Resource)12 XtendField (org.eclipse.xtend.core.xtend.XtendField)11 JvmType (org.eclipse.xtext.common.types.JvmType)11 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)10 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)9 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)8 XtextResource (org.eclipse.xtext.resource.XtextResource)8