protected String expressionTypes(Iterable<XExpression> expressions) { Iterator<XExpression> iterator = expressions.iterator(); if (iterator.hasNext()) { XExpression expression = iterator.next(); IResolvedTypes resolvedTypes = typeResolver.resolveTypes(expression); LightweightTypeReference reference = resolvedTypes.getActualType(expression); if (!iterator.hasNext()) { return referenceToString(reference); } StringBuilder result = new StringBuilder(reference.toString()); while (iterator.hasNext()) { reference = resolvedTypes.getActualType(iterator.next()); result.append(", "); result.append(referenceToString(reference)); } return result.toString(); } else { return ""; } }
@Override public IResolvedTypes reentrantResolve(CancelIndicator monitor) { if (resolving) { throw new UnsupportedOperationException("TODO: import a functional handle on the type resolution that delegates to the best available (current, but evolving) result"); } StoppedTask task = Stopwatches.forTask("DefaultReentrantTypeResolver.resolve"); try { task.start(); resolving = true; return resolve(monitor); } catch(Throwable e) { clear(); if (operationCanceledManager.isOperationCanceledException(e)) { operationCanceledManager.propagateAsErrorIfCancelException(e); } throw Throwables.propagate(e); } finally { resolving = false; task.stop(); } }
@Override public void resolvesFeatureCallsTo(final String expression, final String... types) { final String expressionWithQualifiedNames = expression.replace("$$", "org::eclipse::xtext::xbase::lib::"); final List<XAbstractFeatureCall> featureCalls = this.findFeatureCalls(expressionWithQualifiedNames); final IResolvedTypes resolvedTypes = this.getTypeResolver().resolveTypes(IterableExtensions.<XAbstractFeatureCall>head(featureCalls)); final Iterable<XAbstractFeatureCall> actualFeatureCalls = this.filterTypeLiteralsAndPackageFragments(featureCalls); Assert.assertFalse(IterableExtensions.isEmpty(actualFeatureCalls)); Assert.assertEquals(("" + actualFeatureCalls), ((List<String>)Conversions.doWrapArray(types)).size(), IterableExtensions.size(actualFeatureCalls)); final Procedure2<XAbstractFeatureCall, Integer> _function = (XAbstractFeatureCall featureCall, Integer index) -> { final LightweightTypeReference type = resolvedTypes.getActualType(featureCall); StringConcatenation _builder = new StringConcatenation(); _builder.append("failed for feature call at "); _builder.append(index); Assert.assertEquals(_builder.toString(), types[(index).intValue()], type.getSimpleName()); }; IterableExtensions.<XAbstractFeatureCall>forEach(actualFeatureCalls, _function); }
public LightweightTypeReference getSwitchVariableType(final XSwitchExpression it) { @Extension final IResolvedTypes resolvedTypes = this._iBatchTypeResolver.resolveTypes(it); final JvmFormalParameter declaredParam = it.getDeclaredParam(); if ((declaredParam == null)) { return resolvedTypes.getActualType(it.getSwitch()); } final LightweightTypeReference paramType = resolvedTypes.getActualType(declaredParam); LightweightTypeReference _elvis = null; if (paramType != null) { _elvis = paramType; } else { LightweightTypeReference _actualType = resolvedTypes.getActualType(it.getSwitch()); _elvis = _actualType; } return _elvis; }
@Override public void applyToModel(IResolvedTypes resolvedTypes) { Resource resource = getExpression().eResource(); if (resource instanceof LazyLinkingResource) { LazyLinkingResource lazyLinkingResource = (LazyLinkingResource) resource; TypeAwareLinkingDiagnosticContext context = new TypeAwareLinkingDiagnosticContext(this, resolvedTypes); DiagnosticMessage message = lazyLinkingResource.getDiagnosticMessageProvider() .getUnresolvedProxyMessage(context); if (message != null) { List<Resource.Diagnostic> diagnostics = getDiagnosticList(lazyLinkingResource, message); Diagnostic diagnostic = createDiagnostic(message); diagnostics.add(diagnostic); } EObject referenced = (InternalEObject) getExpression().eGet(getReference(), false); lazyLinkingResource.markUnresolvable(referenced); } }
protected IResolvedTypes withFlattenedReassignedTypes() { final Map<JvmIdentifiableElement, LightweightTypeReference> flattened = getFlattenedReassignedTypes(); if (flattened != null) return new ForwardingResolvedTypes() { @Override /* @Nullable */ public LightweightTypeReference getActualType(JvmIdentifiableElement identifiable) { LightweightTypeReference reassigned = flattened.get(identifiable); if (reassigned != null) return reassigned; return super.getActualType(identifiable); } @Override protected IResolvedTypes delegate() { return ResolvedTypes.this; } }; return this; }
protected void createLocalVariableAndImplicitProposals(final EObject model, final IExpressionScope.Anchor anchor, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) { String prefix = context.getPrefix(); if (((prefix.length() > 0) && (!Character.isJavaIdentifierStart(prefix.charAt(0))))) { return; } IResolvedTypes _xifexpression = null; if ((model != null)) { _xifexpression = this.typeResolver.resolveTypes(model); } else { _xifexpression = this.typeResolver.resolveTypes(context.getResource()); } final IResolvedTypes resolvedTypes = _xifexpression; final IExpressionScope expressionScope = resolvedTypes.getExpressionScope(model, anchor); final IScope scope = expressionScope.getFeatureScope(); this.getCrossrefProposalProvider().lookupCrossReference(scope, this._xbaseGrammarAccess.getXFeatureCallAccess().getFeatureJvmIdentifiableElementCrossReference_2_0(), context, acceptor, this.featureDescriptionPredicate); }
@Override /* @NonNull */ protected IResolvedTypes doResolveTypes(final /* @Nullable */ EObject object, final /* @Nullable */ CancelIndicator monitor) { // TODO: remove when we switch to an Xtend scope provider without artificial feature calls EObject nonArtificialObject = object; if(object.eResource() == null && object instanceof XAbstractFeatureCall) { nonArtificialObject = ((XAbstractFeatureCall) object).getFeature(); } // TODO final Resource resource = nonArtificialObject.eResource(); final LazyResolvedTypes result = cache.get(CachingBatchTypeResolver.class, resource, new Provider<LazyResolvedTypes>() { @Override public LazyResolvedTypes get() { final IReentrantTypeResolver resolver = delegate.getTypeResolver(object); return new LazyResolvedTypes(resolver, resource); } }); cache.execWithoutCacheClear(resource, new IUnitOfWork.Void<Resource>() { @Override public void process(Resource state) throws Exception { // trigger the actual resolution after the thing was cached result.resolveTypes(monitor == null ? CancelIndicator.NullImpl : monitor); } }); return result; }
private boolean mustInsertTypeCast(XExpression expression, LightweightTypeReference actualType) { IResolvedTypes resolvedTypes = getResolvedTypes(expression); if (mustCheckForMandatoryTypeCast(resolvedTypes, expression)) { if (expression instanceof XAbstractFeatureCall) { LightweightTypeReference featureType = resolvedTypes.getActualType(((XAbstractFeatureCall) expression).getFeature()); if (featureType != null && !featureType.isMultiType() && actualType.isAssignableFrom(featureType)) { return false; } } if (expression.eContainer() instanceof XCastedExpression) { XCastedExpression castedExpression = (XCastedExpression) expression.eContainer(); LightweightTypeReference castedExpressionType = getResolvedTypes(castedExpression).getActualType(castedExpression); if (castedExpressionType != null) { return actualType.getType() != castedExpressionType.getType(); } } return true; } return false; }
/** * This method serves as an entry point for the content assist scoping for simple feature calls. * @param context the context e.g. a for loop expression, a block or a catch clause */ public IScope createSimpleFeatureCallScope(EObject context, IFeatureScopeSession session, IResolvedTypes resolvedTypes) { IScope root = IScope.NULLSCOPE; if (context instanceof XFeatureCall) { XFeatureCall featureCall = (XFeatureCall) context; if (!featureCall.isExplicitOperationCallOrBuilderSyntax()) { root = createTypeLiteralScope(context, QualifiedName.EMPTY, root, session, resolvedTypes); if (isDefiniteTypeLiteral(featureCall)) { return root; } } } IScope staticImports = createStaticFeaturesScope(context, root, session); IScope staticMembers = createStaticScope(asAbstractFeatureCall(context), null, null, staticImports, session, resolvedTypes); IScope staticExtensions = createStaticExtensionsScope(null, null, context, staticMembers, session, resolvedTypes); // we don't want to use captured instances of 'IT' as dynamic extension implicit argument // thus the dynamic extension scope only works for the *real* local variables IScope dynamicExtensions = createDynamicExtensionsScope(null, null, context, staticExtensions, session, resolvedTypes); IScope localVariables = createImplicitFeatureCallAndLocalVariableScope(context, dynamicExtensions, session, resolvedTypes); return localVariables; }
protected LightweightTypeReference getTypeForVariableDeclaration(XExpression expr) { IResolvedTypes resolvedTypes = getResolvedTypes(expr); LightweightTypeReference actualType = resolvedTypes.getActualType(expr); if (actualType.isPrimitiveVoid()) { LightweightTypeReference expectedType = resolvedTypes.getExpectedType(expr); if (expectedType == null) { expectedType = resolvedTypes.getExpectedReturnType(expr); if (expectedType == null) { expectedType = resolvedTypes.getReturnType(expr); } } if (expectedType != null && !expectedType.isPrimitiveVoid()) { actualType = expectedType; } } return actualType; }
protected IScope createStaticExtensionsScope(XExpression receiver, LightweightTypeReference receiverType, EObject featureCall, IScope parent, IFeatureScopeSession session, IResolvedTypes resolvedTypes) { IFeatureScopeSession nextCaptureLayer = session.getNextCaptureLayer(); if (nextCaptureLayer != null) { parent = createStaticExtensionsScope(receiver, receiverType, featureCall, parent, nextCaptureLayer, resolvedTypes); } IScope result = parent; if (receiver == null) { // 'this' is a valid implicit first argument, e.g. implementations of Iterable may use #filter on themselves result = createImplicitExtensionScope(THIS, featureCall, session, resolvedTypes, result); // 'it' has a higher priority than 'this' as implicit first argument result = createImplicitExtensionScope(IT, featureCall, session, resolvedTypes, result); return result; } else { if (receiverType == null) { throw new IllegalStateException("Unknown receiver type"); } result = createStaticExtensionsScope(featureCall, receiver, receiverType, false, parent, session); } return result; }
protected IScope createDynamicExtensionsScope(XExpression firstArgument, LightweightTypeReference firstArgumentType, EObject featureCall, IScope parent, IFeatureScopeSession captureLayer, IFeatureScopeSession session, IResolvedTypes resolvedTypes) { IFeatureScopeSession nextCaptureLayer = captureLayer.getNextCaptureLayer(); if (nextCaptureLayer != null) { parent = createDynamicExtensionsScope(firstArgument, firstArgumentType, featureCall, parent, nextCaptureLayer, session, resolvedTypes); } List<ExpressionBucket> extensionProviders = captureLayer.getExtensionProviders(); if (extensionProviders.isEmpty()) { return parent; } IScope result = parent; if (firstArgument == null) { result = createDynamicExtensionsScope(THIS, featureCall, captureLayer, session, resolvedTypes, result, true); result = createDynamicExtensionsScope(IT, featureCall, captureLayer, session, resolvedTypes, result, false); return result; } else { result = createDynamicExtensionsScope(featureCall, firstArgument, firstArgumentType, false, parent, captureLayer); } return result; }
protected IScope createImplicitFeatureCallScope(QualifiedName implicitName, EObject featureCall, IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent) { IEObjectDescription thisDescription = session.getLocalElement(implicitName); if (thisDescription != null) { JvmIdentifiableElement thisElement = (JvmIdentifiableElement) thisDescription.getEObjectOrProxy(); boolean validStaticScope = true; if (thisElement instanceof JvmType && THIS.equals(implicitName) && !session.isInstanceContext()) { validStaticScope = false; } LightweightTypeReference type = resolvedTypes.getActualType(thisElement); if (type !=null && !type.isUnknown()) { XFeatureCall implicitReceiver = xbaseFactory.createXFeatureCall(); implicitReceiver.setFeature(thisElement); return createFeatureScopeForTypeRef(implicitReceiver, type, true, featureCall, session, thisElement, parent, validStaticScope); } } return parent; }
public void assertIdentifiableTypeIsResolved(final JvmIdentifiableElement identifiable, final IResolvedTypes types) { String _simpleName = identifiable.getSimpleName(); boolean _tripleEquals = (_simpleName == null); if (_tripleEquals) { return; } final LightweightTypeReference type = types.getActualType(identifiable); Assert.assertNotNull(identifiable.toString(), type); String _string = identifiable.toString(); String _plus = (_string + " / "); String _plus_1 = (_plus + type); Assert.assertNotNull(_plus_1, type.getIdentifier()); }
protected boolean isConformantReturnTypes(final String leftExpression, final String rightExpression, boolean ignoreGenerics) throws Exception { XExpression leftParse = parseHelper.parse(leftExpression); IResolvedTypes leftTypes = typeResolver.resolveTypes(leftParse); XExpression rightParse = parseHelper.parse(rightExpression, leftParse.eResource().getResourceSet()); LightweightTypeReference leftType = leftTypes.getActualType(leftParse); IResolvedTypes rightTypes = typeResolver.resolveTypes(rightParse); LightweightTypeReference rightType = rightTypes.getActualType(rightParse); if (rightType == null) { throw new IllegalStateException("rightType may not be null"); } boolean conformant = leftType.isAssignableFrom(rightType, new TypeConformanceComputationArgument(ignoreGenerics, false, true, true, false, true)); return conformant; }
protected IResolvedTypes resolve(CancelIndicator monitor) { operationCanceledManager.checkCanceled(monitor); if (isInvalidRoot()) { return IResolvedTypes.NULL; } RootResolvedTypes result = createResolvedTypes(monitor); IFeatureScopeSession session = batchScopeProvider.newSession(root.eResource()); computeTypes(result, session); result.resolveUnboundTypeParameters(); result.resolveProxies(); result.addDiagnostics(root.eResource()); result.processDeferredLogic(); return result; }
/** * Provide the error message for mutable variables that may not be captured in lambdas. * * @param variable the writable variable declaration * @param featureCall the reference to the variable * @param resolvedTypes type information */ protected String getInvalidWritableVariableAccessMessage(XVariableDeclaration variable, XAbstractFeatureCall featureCall, IResolvedTypes resolvedTypes) { // TODO this should be part of a separate validation service XClosure containingClosure = EcoreUtil2.getContainerOfType(featureCall, XClosure.class); if (containingClosure != null && !EcoreUtil.isAncestor(containingClosure, variable)) { return String.format("Cannot %srefer to the non-final variable %s inside a lambda expression", getImplicitlyMessagePart(featureCall), variable.getSimpleName()); } return null; }
@Override public IResolvedTypes resolveTypes(/* @NonNull */ Resource resource, /* @Nullable */ CancelIndicator monitor) { validateResourceState(resource); List<EObject> resourceContents = resource.getContents(); if (resourceContents.isEmpty()) { IFeatureScopeSession session = scopeProvider.newSession(resource); return new EmptyResolvedTypes(session, featureScopes, new StandardTypeReferenceOwner(services, resource)); } else { return resolveTypes(resourceContents.get(0), monitor); } }
public void assertExpressionTypeIsResolved(final XExpression expression, final IResolvedTypes types) { final LightweightTypeReference type = types.getActualType(expression); String _string = expression.toString(); String _plus = ("Type is not resolved. Expression: " + _string); Assert.assertNotNull(_plus, type); String _string_1 = expression.toString(); String _plus_1 = (_string_1 + " / "); String _plus_2 = (_plus_1 + type); Assert.assertNotNull(_plus_2, type.getIdentifier()); final LightweightTypeReference expectedType = types.getExpectedType(expression); Assert.assertNotNull(expression.toString(), String.valueOf(expectedType)); }
@Test public void testProxy() throws Exception { final XFeatureCall proxy = XbaseFactory.eINSTANCE.createXFeatureCall(); ((InternalEObject) proxy).eSetProxyURI(URI.createURI("path#fragment")); final IResolvedTypes typeResolution = this.getTypeResolver().resolveTypes(proxy); Assert.assertNotNull(typeResolution); Assert.assertEquals(IResolvedTypes.NULL, typeResolution); }
private void resolveTypes(final XExpression expression) { final Resource resource = expression.eResource(); IResolvedTypes resolvedTypes = this.resolvedTypesPerResource.get(resource); if ((resolvedTypes == null)) { resolvedTypes = this.typeResolver.resolveTypes(expression); this.resolvedTypesPerResource.put(resource, resolvedTypes); } this.resolvedTypesStack.push(resolvedTypes); }
public void assertExpressionTypeIsResolved(final XExpression expression, final IResolvedTypes types) { final LightweightTypeReference type = types.getActualType(expression); String _string = expression.toString(); String _plus = ("Type is not resolved. Expression: " + _string); Assert.assertNotNull(_plus, type); String _string_1 = expression.toString(); String _plus_1 = (_string_1 + " / "); String _plus_2 = (_plus_1 + type); Assert.assertNotNull(_plus_2, type.getIdentifier()); }
@Override public Collection<AbstractDiagnostic> getQueuedDiagnostics() { List<AbstractDiagnostic> result = Lists.newArrayList(); for(IResolvedTypes delegate: this) { result.addAll(delegate.getQueuedDiagnostics()); } return result; }
@Override public Collection<ILinkingCandidate> getFollowUpErrors() { List<ILinkingCandidate> result = Lists.newArrayList(); for(IResolvedTypes delegate: this) { result.addAll(delegate.getFollowUpErrors()); } return result; }
public void assertExpressionTypeIsResolved(final XExpression expression, final IResolvedTypes types) { final LightweightTypeReference type = types.getActualType(expression); Assert.assertNotNull(expression.toString(), type); String _string = expression.toString(); String _plus = (_string + " / "); String _plus_1 = (_plus + type); Assert.assertNotNull(_plus_1, type.getIdentifier()); }
protected IResolvedTypes getDelegate(XExpression expression) { for(int i = 0; i < resolvers.size(); i++) { AbstractRootedReentrantTypeResolver resolver = resolvers.get(i); if (resolver.isHandled(expression)) { return getDelegate(i); } } return IResolvedTypes.NULL; }
public void resolvesStringLiteralsTo(final String expression, final String... types) { final String expressionWithQualifiedNames = expression.replace("$$", "org::eclipse::xtext::xbase::lib::"); final List<XStringLiteral> featureCalls = this.findLiterals(expressionWithQualifiedNames); Assert.assertFalse(featureCalls.isEmpty()); Assert.assertEquals(((List<String>)Conversions.doWrapArray(types)).size(), featureCalls.size()); final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(IterableExtensions.<XStringLiteral>head(featureCalls)); final Procedure2<XStringLiteral, Integer> _function = (XStringLiteral featureCall, Integer index) -> { final LightweightTypeReference type = resolvedTypes.getActualType(featureCall); StringConcatenation _builder = new StringConcatenation(); _builder.append("failed for literal at "); _builder.append(index); Assert.assertEquals(_builder.toString(), types[(index).intValue()], type.getSimpleName()); }; IterableExtensions.<XStringLiteral>forEach(featureCalls, _function); }
/** * Returns <code>true</code> if the given feature call can be a type literal (structurally). * Otherwise <code>false</code>. */ public boolean isPotentialTypeLiteral(XExpression featureCall, /* @Nullable */ IResolvedTypes resolvedTypes) { if (featureCall instanceof XMemberFeatureCall) { return isPotentialTypeLiteralImpl(featureCall, resolvedTypes, ((XMemberFeatureCall) featureCall).isExplicitStatic()); } return isPotentialTypeLiteralImpl(featureCall, resolvedTypes, false); }
@Override public JvmIdentifiableElement getLinkedFeature(/* @Nullable */ XAbstractFeatureCall featureCall) { if (featureCall == null) return null; IResolvedTypes delegate = getDelegate(featureCall); return delegate.getLinkedFeature(featureCall); }
@Override public JvmIdentifiableElement getLinkedFeature(/* @Nullable */ XConstructorCall constructorCall) { if (constructorCall == null) return null; IResolvedTypes delegate = getDelegate(constructorCall); return delegate.getLinkedFeature(constructorCall); }
@Override public IConstructorLinkingCandidate getLinkingCandidate(/* @Nullable */ XConstructorCall constructorCall) { if (constructorCall == null) return null; IResolvedTypes delegate = getDelegate(constructorCall); return delegate.getLinkingCandidate(constructorCall); }
public void assertIdentifiableTypeIsResolved(final JvmIdentifiableElement identifiable, final IResolvedTypes types) { final LightweightTypeReference type = types.getActualType(identifiable); Assert.assertNotNull(identifiable.toString(), type); String _string = identifiable.toString(); String _plus = (_string + " / "); String _plus_1 = (_plus + type); Assert.assertNotNull(_plus_1, type.getIdentifier()); }
@Override public IScope getScope(EObject context, EReference reference, IResolvedTypes types) { if (getFeatureScopes().isFeatureCallScope(reference)) { return createFeatureCallScope(context, reference, types); } else if (getConstructorScopes().isConstructorCallScope(reference)) { return createConstructorScope(context, reference, types); } else if (getTypeScopes().isTypeScope(reference)) { return createTypeScope(context, reference, types); } else { return getDefaultScopeProvider().getScope(context, reference); } }
public void doResolvesTo(final String expression, final String type) { try { final XExpression parsedExpression = this.expression(expression, false); final IResolvedTypes resolvedTypes = this.getTypeResolver().resolveTypes(parsedExpression); final LightweightTypeReference resolvedType = resolvedTypes.getReturnType(parsedExpression); Assert.assertEquals(expression, type, resolvedType.getSimpleName()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
protected JvmTypeReference doGetTypReferenceWithAnotherTypeReference() { IResolvedTypes resolveTypes = typeResolver.resolveTypes(expression); LightweightTypeReference actualType = returnType ? resolveTypes.getReturnType(expression) : resolveTypes.getActualType(expression); if (actualType == null) { actualType = returnType ? resolvedTypes.getExpectedReturnType(expression) : resolvedTypes.getExpectedType(expression); } if (actualType == null) return null; return toJavaCompliantTypeReference(convertLocalType(actualType), session); }
@Override protected IResolvedTypes doResolveTypes(/* @Nullable */ EObject object, /* @Nullable */ CancelIndicator monitor) { Resource resource = object.eResource(); if (resource instanceof StorageAwareResource) { if (((StorageAwareResource) resource).isLoadedFromStorage()) { throw new IllegalStateException("Type resolution is not supported on a storage-loaded resource : "+resource.getURI()); } } // TODO: remove when we switch to an Xtend scope provider without artificial feature calls EObject nonArtificialObject = getNonArtificialObject(object); // TODO end IReentrantTypeResolver reentrantResolver = getTypeResolver(nonArtificialObject); return reentrantResolver.reentrantResolve(monitor == null ? CancelIndicator.NullImpl : monitor); }
protected LightweightTypeReference toTypeReference(final CharSequence reference) { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("null as "); _builder.append(reference); final String expression = _builder.toString(); XExpression _expression = this.expression(expression); final XCastedExpression castExpression = ((XCastedExpression) _expression); final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(castExpression); return resolvedTypes.getActualType(castExpression); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Override public void applyToModel(IResolvedTypes resolvedTypes) { Resource resource = getExpression().eResource(); if (resource instanceof LazyLinkingResource) { LazyLinkingResource lazyLinkingResource = (LazyLinkingResource) resource; EObject referenced = (InternalEObject) getExpression().eGet(getReference(), false); lazyLinkingResource.markUnresolvable(referenced); } }