Search in sources :

Example 6 with IResolvedOperation

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

the class XtendValidator method createExceptionMismatchError.

protected void createExceptionMismatchError(IResolvedOperation operation, EObject sourceElement, List<IResolvedOperation> exceptionMismatch) {
    List<LightweightTypeReference> exceptions = operation.getIllegallyDeclaredExceptions();
    StringBuilder message = new StringBuilder(100);
    message.append("The declared exception");
    if (exceptions.size() > 1) {
        message.append('s');
    }
    message.append(' ');
    for (int i = 0; i < exceptions.size(); i++) {
        if (i != 0) {
            if (i != exceptions.size() - 1)
                message.append(", ");
            else
                message.append(" and ");
        }
        message.append(exceptions.get(i).getHumanReadableName());
    }
    if (exceptions.size() > 1) {
        message.append(" are");
    } else {
        message.append(" is");
    }
    message.append(" not compatible with throws clause in ");
    for (int i = 0; i < exceptionMismatch.size(); i++) {
        if (i != 0) {
            if (i != exceptionMismatch.size() - 1)
                message.append(", ");
            else
                message.append(" and ");
        }
        IResolvedOperation resolvedOperation = exceptionMismatch.get(i);
        message.append(getDeclaratorName(resolvedOperation));
        message.append('.');
        message.append(exceptionMismatch.get(i).getSimpleSignature());
    }
    error(message.toString(), sourceElement, exceptionsFeature(sourceElement), INCOMPATIBLE_THROWS_CLAUSE);
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) ToStringBuilder(org.eclipse.xtext.xbase.lib.util.ToStringBuilder) IResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation)

Example 7 with IResolvedOperation

use of org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation 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 8 with IResolvedOperation

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

the class SuperMemberImplementorTest method checkOverrideMethodCode.

protected void checkOverrideMethodCode(String operationName, String overrideCode) {
    StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable();
    LightweightTypeReference contextType = getContextType();
    IResolvedOperation resolvedOperation = new BottomResolvedOperation((JvmOperation) findExecutable(implementedInterface, operationName), contextType, new OverrideTester());
    implementor.appendOverrideFunction(xtendClass, resolvedOperation, appendable);
    String code = appendable.toString();
    if (!equalsIgnoreWhitespace(overrideCode, code))
        assertEquals(overrideCode, code);
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) StringBuilderBasedAppendable(org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable) OverrideTester(org.eclipse.xtext.xbase.typesystem.override.OverrideTester) IResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation) BottomResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation)

Example 9 with IResolvedOperation

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

the class CompilationUnitImpl method toResolvedMethod.

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

Example 10 with IResolvedOperation

use of org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation 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

IResolvedOperation (org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation)10 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)4 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)3 RichString (org.eclipse.xtend.core.xtend.RichString)2 JvmType (org.eclipse.xtext.common.types.JvmType)2 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)2 ToStringBuilder (org.eclipse.xtext.xbase.lib.util.ToStringBuilder)2 BottomResolvedOperation (org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation)2 IResolvedConstructor (org.eclipse.xtext.xbase.typesystem.override.IResolvedConstructor)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 EObject (org.eclipse.emf.ecore.EObject)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 StyledString (org.eclipse.jface.viewers.StyledString)1 ResolvedMethodImpl (org.eclipse.xtend.core.macro.declaration.ResolvedMethodImpl)1 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)1 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)1