protected void computeTypes(ResolvedTypes resolvedTypes, IFeatureScopeSession session, EObject element) { if (element instanceof XExpression) { _computeTypes(resolvedTypes, session, (XExpression) element); } else { throw new IllegalArgumentException("element: " + element); } }
@Override protected void clear() { rootedInstances.clear(); super.clear(); }
protected void computeTypes(ResolvedTypes resolvedTypes, IFeatureScopeSession session) { computeTypes(resolvedTypes, session, root); }
public Shared(DefaultReentrantTypeResolver resolver, CancelIndicator monitor) { this.resolver = resolver; this.monitor = monitor; this.featureScopeTracker = resolver.createFeatureScopeTracker(); this.issueSeverities = resolver.getIssueSeverities(); }
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; }
@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); } Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } finally { resolving = false; task.stop(); } }
@Override public boolean validate(IAcceptor<? super AbstractDiagnostic> result) { JvmIdentifiableElement implicitFeature = getFeature(); if (implicitFeature instanceof XVariableDeclaration) { XVariableDeclaration casted = (XVariableDeclaration) implicitFeature; if (casted.isWriteable()) { String message = getState().getResolver().getInvalidWritableVariableAccessMessage(casted, getFeatureCall(), getState().getResolvedTypes()); if (message != null) { AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.INVALID_MUTABLE_VARIABLE_ACCESS, message, getOwner(), XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, -1, null); result.accept(diagnostic); return false; } } if (EcoreUtil.isAncestor(casted, getFeatureCall())) { String message = String.format("The implicitly referenced variable %s may not have been initialized", implicitFeature.getSimpleName()); AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.ILLEGAL_FORWARD_REFERENCE, message, getOwner(), XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, -1, null); result.accept(diagnostic); return false; } } return true; }
@Override public IBatchScopeProvider getBatchScopeProvider() { return super.getBatchScopeProvider(); } }
protected void initializeArgumentTypeComputation() { if (arguments != null) return; getTypeParameterMapping(); // trigger lazy init arguments = state.getResolver().getExpressionArgumentFactory().createExpressionArguments(expression, this); }
/** * 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 void addExpressionScope(ResolvedTypes current, EObject context, IFeatureScopeSession session, Anchor anchor) { EnumMap<Anchor, ExpressionScope> recordedScopes = featureScopeSessions.get(context); if (recordedScopes == null) { recordedScopes = Maps.newEnumMap(Anchor.class); featureScopeSessions.put(context, recordedScopes); } ExpressionScope scope = recordedScopes.get(anchor); if (scope == null) { scope = new ExpressionScope(current.getResolver().getFeatureScopes(), context, anchor, current.getReferenceOwner()); recordedScopes.put(anchor, scope); } scope.addData(session, current.withFlattenedReassignedTypes()); }
XVariableDeclaration casted = (XVariableDeclaration) feature; if (casted.isWriteable()) { String message = getState().getResolver().getInvalidWritableVariableAccessMessage(casted, getFeatureCall(), getState().getResolvedTypes()); if (message != null) { AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(Severity.ERROR,
@Override protected void computeTypes(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, EObject element) { if (element instanceof JvmConstructor) { throw new IllegalStateException(); } else if (element instanceof JvmField) { throw new IllegalStateException(); } else if (element instanceof JvmOperation) { throw new IllegalStateException(); } else if (element instanceof JvmDeclaredType) { throw new IllegalStateException(); } else { super.computeTypes(resolvedTypes, featureScopeSession, element); } }
@Override protected void computeTypes(ResolvedTypes resolvedTypes, IFeatureScopeSession session) { EObject root = getRoot(); if (root instanceof JvmType) { Map<JvmIdentifiableElement, ResolvedTypes> preparedResolvedTypes = prepare(resolvedTypes, session); computeTypes(preparedResolvedTypes, resolvedTypes, session, root); } else { super.computeTypes(resolvedTypes, session); } }