@Override protected void updateInternalState(IParseResult oldParseResult, IParseResult newParseResult) { if (fullyInitialized) { discardDerivedState(); } super.updateInternalState(oldParseResult, newParseResult); }
@Override protected void doDiscardDerivedState() { this.jvmMemberInitializers = null; this.hasJvmMemberInitializers = false; super.doDiscardDerivedState(); }
/** * {@inheritDoc} * <p> * As soon as an external client tries to access the content of the resource, * the {@link IDerivedStateComputer derived state} will be added to the content of this resource. */ @Override public synchronized EList<EObject> getContents() { if (isLoaded && !isLoading && !isInitializing && !isUpdating && !fullyInitialized) { try { eSetDeliver(false); installDerivedState(false); } finally { eSetDeliver(true); } } return doGetContents(); }
IDefaultResourceDescriptionStrategy strategy) { DerivedStateAwareResource res = (DerivedStateAwareResource) resource; if (!res.isLoaded()) { try { res.load(res.getResourceSet().getLoadOptions()); } catch (IOException e) { throw new RuntimeIOException(e); try { if (!isInitialized) { res.eSetDeliver(false); res.installDerivedState(true); if (log.isDebugEnabled()) log.debug("Discarding inferred state for "+resource.getURI()); res.discardDerivedState(); res.eSetDeliver(true);
@Override protected void validateResourceState(Resource resource) { super.validateResourceState(resource); if (resource instanceof DerivedStateAwareResource && ((DerivedStateAwareResource) resource).isInitializing()) { LOG.error("Discouraged attempt to compute types during model inference. Resource was : "+resource.getURI(), new Exception()); } if (resource instanceof JvmMemberInitializableResource && ((JvmMemberInitializableResource) resource).isInitializingJvmMembers()) { LOG.error("Discouraged attempt to compute types during JvmMember initialization. Resource was : "+resource.getURI(), new Exception()); } }
private EPackage findEPackageInResource(String packageUri, Resource resource) { if (resource instanceof DerivedStateAwareResource && !((DerivedStateAwareResource) resource).isFullyInitialized()) { return null; } TreeIterator<EObject> it = resource.getAllContents(); while (it.hasNext()) { EObject obj = it.next(); if (obj instanceof EPackage) { if (Objects.equals(((EPackage) obj).getNsURI(), packageUri)) { return (EPackage) obj; } } else { it.prune(); } } return null; }
@Override public void run() { for (EObject object : resource.getContents()) { if (object instanceof JvmIdentifiableElement) { JvmIdentifiableElement element = (JvmIdentifiableElement) object; completer.complete(element); } } } };
public void installDerivedState(boolean preIndexingPhase) { if (!isLoaded) throw new IllegalStateException("The resource must be loaded, before installDerivedState can be called."); if (!fullyInitialized && !isInitializing) { try { isInitializing = true; if (derivedStateComputer != null) derivedStateComputer.installDerivedState(this, preIndexingPhase); fullyInitialized = true; } finally { isInitializing = false; getCache().clear(this); } } }
protected void calculateDerivedVariableObjects(DerivedStateAwareResource resource) { TreeIterator<EObject> it = resource.getAllContents(); while(it.hasNext()) { EObject obj = it.next(); if (obj instanceof Pattern) { Pattern pattern = (Pattern) obj; for (PatternBody body : pattern.getBodies()) { EList<Variable> variables = body.getVariables(); variables.addAll(getAllVariablesInBody(body, variables)); } for (Annotation annotation : pattern.getAnnotations()) { for (AnnotationParameter parameter : annotation.getParameters()) { if ((parameter.getValue()) instanceof VariableReference) { final VariableReference reference = (VariableReference) parameter.getValue(); setDeclaredParameter(pattern, reference); } else if ((parameter.getValue()) instanceof ListValue) { ListValue listValue = (ListValue) (parameter.getValue()); for (VariableReference reference : Iterables.filter(listValue.getValues(), VariableReference.class)) { setDeclaredParameter(pattern, reference); } } } } it.prune(); } } }
/** * Performs the actual linking. */ protected void superDoLinking() { super.doLinking(); }
/** * Checks the internal state of the resource and logs if type resolution was triggered unexpectedly. * If such a condition is detected, an {@link IllegalStateException exception} is thrown. * * @throws IllegalStateException if the resource is in an unexpected state. */ @Override protected void validateResourceState(Resource resource) { if (resource instanceof StorageAwareResource && ((StorageAwareResource) resource).isLoadedFromStorage()) { throw new IllegalStateException("Discouraged attempt to compute types for resource that was loaded from storage. Resource was : "+resource.getURI()); } if (resource instanceof DerivedStateAwareResource && ((DerivedStateAwareResource) resource).isInitializing()) { throw new IllegalStateException("Discouraged attempt to compute types during model inference. Resource was : "+resource.getURI()); } if (resource instanceof JvmMemberInitializableResource && ((JvmMemberInitializableResource) resource).isInitializingJvmMembers()) { throw new IllegalStateException("Discouraged attempt to compute types during JvmMember initialization. Resource was : "+resource.getURI()); } }
private EPackage findEPackageInResource(String packageUri, Resource resource) { if (resource instanceof DerivedStateAwareResource && !((DerivedStateAwareResource) resource).isFullyInitialized()) { return null; } TreeIterator<EObject> it = resource.getAllContents(); while (it.hasNext()) { EObject obj = it.next(); if (obj instanceof EPackage) { if (((EPackage) obj).getNsURI().equals(packageUri)) { return (EPackage) obj; } } else { it.prune(); } } return null; }
@Override @SuppressWarnings("unchecked") public <T extends JvmDeclaredType> void accept(T type, Procedure1<? super T> lateInitialization) { if (type != null && type.eContainer() == null) resource.getContents().add(type); if (lateInitialization != null && type != null) { later.add(new Pair<JvmDeclaredType, Procedure1<? super JvmDeclaredType>>(type, (Procedure1<? super JvmDeclaredType>) lateInitialization)); } }
/** * Overridden to make sure that the cache is initialized during {@link #isLoading() loading}. */ @Override protected void updateInternalState(IParseResult newParseResult) { super.updateInternalState(newParseResult); // make sure that the cache adapter is installed on this resource IResourceScopeCache cache = getCache(); if (cache instanceof OnChangeEvictingCache) { ((OnChangeEvictingCache) cache).getOrCreate(this); } }
/** * @since 1.4 */ protected void calculateAggregateTypes(DerivedStateAwareResource resource) { TreeIterator<EObject> it = resource.getAllContents(); while (it.hasNext()) { EObject obj = it.next(); if (obj instanceof AggregatedValue) { AggregatedValue aggregatedValue = (AggregatedValue) obj; if (AggregatorUtil.mustHaveAggregatorVariables(aggregatedValue)) { VariableReference aggregateParameter = AggregatorUtil.getAggregatorVariable(aggregatedValue); if (aggregateParameter == null) { aggregatedValue.setAggregateType(typeReferences.findDeclaredType(Void.class, aggregatedValue)); } else { JvmTypeReference jvmType = typeInferrer.getJvmType(aggregateParameter, aggregatedValue); aggregatedValue.setAggregateType(jvmType.getType()); } } } else if (obj instanceof JvmType) { it.prune(); } } } }
/** * @since 2.4 */ @Override protected void clearInternalState() { if (fullyInitialized) { discardDerivedState(); } super.clearInternalState(); }
@Override @SuppressWarnings("unchecked") public <T extends JvmDeclaredType> IPostIndexingInitializing<T> accept(T type) { if (type != null && type.eContainer() == null) resource.getContents().add(type); return (IPostIndexingInitializing<T>) new JvmPostIndexingInitializing(type); }
public void discardDerivedState() { if (isLoaded && fullyInitialized && !isInitializing) { try { isInitializing = true; if (derivedStateComputer != null) derivedStateComputer.discardDerivedState(this); fullyInitialized = false; } finally { isInitializing = false; getCache().clear(this); } } }
protected <T> T getAssociatedElement(Class<T> expectedType, EObject dslObject, Resource resource) { for (final EObject obj : this.associations.getJvmElements(dslObject)) { if (expectedType.isInstance(obj)) { return expectedType.cast(obj); } } if (resource instanceof DerivedStateAwareResource) { ((DerivedStateAwareResource) resource).discardDerivedState(); resource.getContents(); return getAssociatedElement(expectedType, dslObject, null); } throw new IllegalStateException("No JvmFormalParameter associated to " + dslObject + " in " + dslObject.eContainer()); }
@Override public void installDerivedState(final DerivedStateAwareResource resource, boolean preIndexingPhase) { if (resource.getContents().isEmpty()) return; EObject eObject = resource.getContents().get(0);