Search in sources :

Example 1 with IResolvedConstructor

use of org.eclipse.xtext.xbase.typesystem.override.IResolvedConstructor in project xtext-xtend by eclipse.

the class CompilationUnitImpl method toResolvedConstructor.

public ResolvedConstructor toResolvedConstructor(final IResolvedConstructor delegate) {
    final Function1<IResolvedConstructor, ResolvedConstructorImpl> _function = (IResolvedConstructor it) -> {
        ResolvedConstructorImpl _resolvedConstructorImpl = new ResolvedConstructorImpl();
        final Procedure1<ResolvedConstructorImpl> _function_1 = (ResolvedConstructorImpl it_1) -> {
            it_1.setDelegate(delegate);
            it_1.setCompilationUnit(this);
        };
        return ObjectExtensions.<ResolvedConstructorImpl>operator_doubleArrow(_resolvedConstructorImpl, _function_1);
    };
    return this.<IResolvedConstructor, ResolvedConstructorImpl>getOrCreate(delegate, _function);
}
Also used : Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) ResolvedConstructorImpl(org.eclipse.xtend.core.macro.declaration.ResolvedConstructorImpl) IResolvedConstructor(org.eclipse.xtext.xbase.typesystem.override.IResolvedConstructor)

Example 2 with IResolvedConstructor

use of org.eclipse.xtext.xbase.typesystem.override.IResolvedConstructor in project xtext-xtend by eclipse.

the class ImplementMemberFromSuperAssist method createOverrideMethodProposal.

protected ICompletionProposal createOverrideMethodProposal(XtendTypeDeclaration model, IResolvedExecutable overrideable, final ContentAssistContext context, IProposalConflictHelper conflictHelper) {
    IXtextDocument document = context.getDocument();
    XtextResource resource = (XtextResource) model.eResource();
    int offset = context.getReplaceRegion().getOffset();
    int currentIndentation = appendableFactory.getIndentationLevelAtOffset(offset, document, resource);
    final int indentationLevel = currentIndentation == 0 ? 1 : currentIndentation;
    ReplacingAppendable appendable = appendableFactory.create(document, resource, offset, context.getReplaceRegion().getLength(), new OptionalParameters() {

        {
            ensureEmptyLinesAround = true;
            baseIndentationLevel = indentationLevel;
        }
    });
    final String simpleName;
    JvmExecutable declaration = overrideable.getDeclaration();
    if (overrideable instanceof IResolvedOperation) {
        implementor.appendOverrideFunction(model, (IResolvedOperation) overrideable, appendable);
        simpleName = overrideable.getDeclaration().getSimpleName();
    } else if (model instanceof XtendClass) {
        implementor.appendConstructorFromSuper((XtendClass) model, (IResolvedConstructor) overrideable, appendable);
        simpleName = "new";
    } else {
        return null;
    }
    String code = appendable.getCode();
    if (!isValidProposal(code.trim(), context, conflictHelper) && !isValidProposal(simpleName, context, conflictHelper))
        return null;
    ImageDescriptor imageDescriptor = images.forOperation(declaration.getVisibility(), adornments.getOverrideAdornment(declaration));
    ImportOrganizingProposal completionProposal = createCompletionProposal(appendable, context.getReplaceRegion(), getLabel(overrideable), imageHelper.getImage(imageDescriptor));
    Matcher matcher = bodyExpressionPattern.matcher(code);
    if (matcher.find()) {
        int bodyExpressionLength = matcher.end(1) - matcher.start(1);
        int bodyExpressionStart = matcher.start(1) + appendable.getTotalOffset() - completionProposal.getReplacementOffset();
        if (bodyExpressionLength == 0) {
            completionProposal.setCursorPosition(bodyExpressionStart);
        } else {
            completionProposal.setSelectionStart(completionProposal.getReplacementOffset() + bodyExpressionStart);
            completionProposal.setSelectionLength(bodyExpressionLength);
            completionProposal.setAutoInsertable(false);
            completionProposal.setCursorPosition(bodyExpressionStart + bodyExpressionLength);
            completionProposal.setSimpleLinkedMode(context.getViewer(), '\t');
        }
    }
    completionProposal.setPriority(getPriority(model, declaration, context));
    completionProposal.setMatcher(new PrefixMatcher() {

        @Override
        public boolean isCandidateMatchingPrefix(String name, String prefix) {
            PrefixMatcher delegate = context.getMatcher();
            boolean result = delegate.isCandidateMatchingPrefix(simpleName, prefix);
            return result;
        }
    });
    return completionProposal;
}
Also used : PrefixMatcher(org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher) PrefixMatcher(org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher) Matcher(java.util.regex.Matcher) XtextResource(org.eclipse.xtext.resource.XtextResource) ReplacingAppendable(org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable) StyledString(org.eclipse.jface.viewers.StyledString) IResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation) IResolvedConstructor(org.eclipse.xtext.xbase.typesystem.override.IResolvedConstructor) OptionalParameters(org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender.Factory.OptionalParameters) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ImportOrganizingProposal(org.eclipse.xtext.xbase.ui.contentassist.ImportOrganizingProposal) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 3 with IResolvedConstructor

use of org.eclipse.xtext.xbase.typesystem.override.IResolvedConstructor in project xtext-xtend by eclipse.

the class AbstractXtendOutlineTreeBuilder method buildInheritedMembers.

protected void buildInheritedMembers(final JvmDeclaredType inferredType, final IXtendOutlineContext context) {
    ResourceSet _resourceSet = inferredType.eResource().getResourceSet();
    final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, _resourceSet);
    final LightweightTypeReference typeReference = owner.toLightweightTypeReference(inferredType);
    final List<LightweightTypeReference> superTypes = typeReference.getAllSuperTypes();
    IXtendOutlineContext superTypeContext = context;
    for (final LightweightTypeReference superTypeRef : superTypes) {
        {
            superTypeContext = superTypeContext.increaseInheritanceDepth();
            final ResolvedFeatures resolvedFeatures = new ResolvedFeatures(superTypeRef);
            List<IResolvedField> _declaredFields = resolvedFeatures.getDeclaredFields();
            for (final IResolvedField jvmField : _declaredFields) {
                boolean _skipFeature = this.skipFeature(jvmField.getDeclaration());
                boolean _not = (!_skipFeature);
                if (_not) {
                    this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, jvmField, superTypeContext);
                }
            }
            List<IResolvedConstructor> _declaredConstructors = resolvedFeatures.getDeclaredConstructors();
            for (final IResolvedConstructor constructor : _declaredConstructors) {
                boolean _skipFeature_1 = this.skipFeature(constructor.getDeclaration());
                boolean _not_1 = (!_skipFeature_1);
                if (_not_1) {
                    this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, constructor, superTypeContext);
                }
            }
            List<IResolvedOperation> _declaredOperations = resolvedFeatures.getDeclaredOperations();
            for (final IResolvedOperation operation : _declaredOperations) {
                if (((!this.skipFeature(operation.getDeclaration())) && (!superTypeContext.isProcessed(operation.getDeclaration())))) {
                    this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, operation, superTypeContext);
                }
            }
            final JvmType declaredType = superTypeRef.getType();
            if ((declaredType instanceof JvmDeclaredType)) {
                final IXtendOutlineContext nestedTypeContext = superTypeContext.hideInherited();
                final Consumer<JvmDeclaredType> _function = (JvmDeclaredType it) -> {
                    this.buildJvmType(it, nestedTypeContext);
                };
                Iterables.<JvmDeclaredType>filter(((JvmDeclaredType) declaredType).getMembers(), JvmDeclaredType.class).forEach(_function);
            }
        }
    }
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) ResolvedFeatures(org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures) IResolvedField(org.eclipse.xtext.xbase.typesystem.override.IResolvedField) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) JvmType(org.eclipse.xtext.common.types.JvmType) IResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation) IResolvedConstructor(org.eclipse.xtext.xbase.typesystem.override.IResolvedConstructor) Consumer(java.util.function.Consumer) IXtendOutlineContext(org.eclipse.xtend.ide.common.outline.IXtendOutlineContext) EList(org.eclipse.emf.common.util.EList) List(java.util.List) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Aggregations

IResolvedConstructor (org.eclipse.xtext.xbase.typesystem.override.IResolvedConstructor)3 IResolvedOperation (org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation)2 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Matcher (java.util.regex.Matcher)1 EList (org.eclipse.emf.common.util.EList)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 StyledString (org.eclipse.jface.viewers.StyledString)1 ResolvedConstructorImpl (org.eclipse.xtend.core.macro.declaration.ResolvedConstructorImpl)1 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)1 IXtendOutlineContext (org.eclipse.xtend.ide.common.outline.IXtendOutlineContext)1 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)1 JvmExecutable (org.eclipse.xtext.common.types.JvmExecutable)1 JvmType (org.eclipse.xtext.common.types.JvmType)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 PrefixMatcher (org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher)1 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)1 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)1 IResolvedField (org.eclipse.xtext.xbase.typesystem.override.IResolvedField)1