@Override public void discardDerivedState(final DerivedStateAwareResource resource) { boolean _isEmpty = resource.getContents().isEmpty(); boolean _not = (!_isEmpty); if (_not) { EObject _head = IterableExtensions.<EObject>head(resource.getContents()); if ((_head instanceof Configuration)) { EObject _head_1 = IterableExtensions.<EObject>head(resource.getContents()); final Configuration configuration = ((Configuration) _head_1); EList<Resource> _resources = configuration.getResources(); for (final Resource resourceOcci : _resources) { resourceOcci.getRlinks().clear(); } } } }
/** * copies contents of a resource set into a new one */ public static <T extends ResourceSet> T clone(T target, ResourceSet source) { EList<Resource> resources = source.getResources(); EcoreUtil.Copier copier = new EcoreUtil.Copier(); for (Resource resource : resources) { Resource targetResource = target.createResource(resource.getURI()); targetResource.getContents().addAll(copier.copyAll(resource.getContents())); // mark all resources as fully initialized if (resource instanceof DerivedStateAwareResource && targetResource instanceof DerivedStateAwareResource) { ((DerivedStateAwareResource) targetResource).setFullyInitialized(((DerivedStateAwareResource) resource) .isFullyInitialized()); } } copier.copyReferences(); return target; }
/** {@inheritDoc} */ @Override public void installDerivedState(final DerivedStateAwareResource resource, final boolean isPreLinkingPhase) { if (resource.getContents().isEmpty()) { return; } EObject eObject = resource.getContents().get(0); try { IModelInferrer inferrer = inferrerProvider.get(); inferrer.inferTargetModel(eObject, createAcceptor(resource), isPreLinkingPhase); // CHECKSTYLE:OFF } catch (RuntimeException e) { // CHECKSTYLE:ON LOGGER.error("Failed to install derived state for resource " + resource.getURI(), e); //$NON-NLS-1$ } }
/** * Creates a new acceptor for the given resource. * * @param resource * resource, must not be {@code null} * @return new acceptor, never {@code null} */ protected IAcceptor<EObject> createAcceptor(final DerivedStateAwareResource resource) { return new IAcceptor<EObject>() { private InferenceContainer container; @Override public void accept(final EObject t) { if (t != null) { if (container == null) { container = ModelInferenceFactory.eINSTANCE.createInferenceContainer(); resource.getContents().add(container); } container.getContents().add(t); } } }; }
private void performIssueValidationFixingWithoutAutomatedStateCalculation(Collection<Issue> detectedIssues, Resource documentResource) { int fixAttempts = 0; Collection<IAutomatedIssueResolution> issueResolutions = Collections.emptyList(); do { if (fixAttempts++ > MAX_AUTOMATED_FIX_ATTEMPTS) { break; } issueResolutions.forEach(IAutomatedIssueResolution::resolve); if (documentResource instanceof DerivedStateAwareResource) { resourceStateHandler.cleanState(documentResource); resourceStateHandler.initState(documentResource); resourceStateHandler.calculateState(documentResource); } detectedIssues.clear(); detectedIssues .addAll(resourceValidator.validate(documentResource, CheckMode.ALL, CancelIndicator.NullImpl)); issueResolutions = automatedIssueResolutionProvider.get(documentResource, detectedIssues); } while (issueResolutions.stream().anyMatch(IAutomatedIssueResolution::resolvePossible)); }
@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()); } }
@Override protected void validate(Resource resource, CheckMode mode, CancelIndicator monitor, IAcceptor<Issue> acceptor) { getOperationCanceledManager().checkCanceled(monitor); if (resource instanceof DerivedStateAwareResource) { List<EObject> contents = resource.getContents(); if (!contents.isEmpty()) { validate(resource, contents.get(0), mode, monitor, acceptor); } } else { super.validate(resource, mode, monitor, acceptor); } }
@Test public void testSerialize_ExtrasIssue164() throws Exception { DerivedStateAwareResource resource = (DerivedStateAwareResource) newResource("org.eclipse.xtext.xbase.tests.serializer.SerializerTest.Demo.demo"); XMemberFeatureCall call = (XMemberFeatureCall) resource.getContents().get(0); ISerializer serializer = get(ISerializer.class); call.eAdapters().clear(); String string = serializer.serialize(call); assertEquals("org.eclipse.xtext.xbase.tests.serializer.SerializerTest.Demo.demo", string); }
@Test public void testSerialize_ExtrasIssue164_02() throws Exception { DerivedStateAwareResource resource = (DerivedStateAwareResource) newResource("org.eclipse.xtext.xbase.tests.serializer.SerializerTest.Demo.getDemo2(1)"); XMemberFeatureCall call = (XMemberFeatureCall) resource.getContents().get(0); ISerializer serializer = get(ISerializer.class); call.eAdapters().clear(); String string = serializer.serialize(call); assertEquals("org.eclipse.xtext.xbase.tests.serializer.SerializerTest.Demo.getDemo2(1)", string); }
@Override public void installDerivedState(DerivedStateAwareResource resource, boolean preLinkingPhase) { if (preLinkingPhase) return; GrammarResource castedResource = (GrammarResource)resource; castedResource.superDoLinking(); }
@Test public void testClone_2() throws Exception { ResourceSetImpl sourceSet = new DerivedStateAwareResourceSet(); DerivedStateAwareResource resource = (DerivedStateAwareResource) sourceSet.createResource(URI .createURI("http://derived.res")); boolean stateToCheck = !resource.isFullyInitialized(); resource.setFullyInitialized(stateToCheck); Resource targetRes = EcoreUtil2.clone(new DerivedStateAwareResourceSet(), sourceSet).getResources().get(0); assertTrue(targetRes instanceof DerivedStateAwareResource); assertEquals("FullyInitialized flag not copied ", stateToCheck, ((DerivedStateAwareResource) targetRes).isFullyInitialized()); }
public ContentAssistContext[] create(String document, ITextRegion selection, int offset, XtextResource resource) { this.document = document; this.selection = selection; this.resource = resource; //This is called to make sure late initialization is done. if (resource instanceof DerivedStateAwareResource) { resource.getContents(); } this.parseResult = resource.getParseResult(); if (parseResult == null) throw new NullPointerException("parseResult is null"); return doCreateContexts(offset); }
@Override public void installDerivedState(final DerivedStateAwareResource resource, final boolean isPreLinkingPhase) { super.installDerivedState(resource, isPreLinkingPhase); if (additionalInferrers != null) { additionalInferrers.inferTargetModel(resource.getContents().get(0), createAcceptor(resource), isPreLinkingPhase); } }
/** {@inheritDoc} */ @Override public void discardDerivedState(final DerivedStateAwareResource resource) { List<EObject> derived = newArrayList(); EList<EObject> resourcesContentsList = resource.getContents(); for (int i = 1; i < resourcesContentsList.size(); i++) { EObject eObject = resourcesContentsList.get(i); unloader.unloadRoot(eObject); derived.add(eObject); } resourcesContentsList.removeAll(derived); getSourceToInferredModelMap(resource).clear(); }
public ContentAssistContext[] create(ITextViewer viewer, int offset, XtextResource resource) throws BadLocationException { this.viewer = viewer; this.resource = resource; //This is called to make sure late initialization is done. if (resource instanceof DerivedStateAwareResource) { resource.getContents(); } this.parseResult = resource.getParseResult(); if (parseResult == null) throw new NullPointerException("parseResult is null"); return doCreateContexts(offset); }
private void performIssueValidationFixing(Collection<Issue> detectedIssues, Resource documentResource) { final AutomatedIssueResolutionOngoingAdapter adapter = new AutomatedIssueResolutionOngoingAdapter(); Optional<DerivedStateAwareResource> stateAwareResource = Optional.of(documentResource) .filter(DerivedStateAwareResource.class::isInstance).map(DerivedStateAwareResource.class::cast); try { documentResource.eAdapters().add(adapter); stateAwareResource.ifPresent(s -> s.setDerivedStateComputer(null)); performIssueValidationFixingWithoutAutomatedStateCalculation(detectedIssues, documentResource); } finally { stateAwareResource.ifPresent(r -> r.setDerivedStateComputer(derivedStateComputer)); documentResource.eAdapters().remove(adapter); } }
@Override public void installDerivedState(DerivedStateAwareResource resource, boolean preLinkingPhase) { if (preLinkingPhase) { return; } if (resource.getContents().isEmpty() || resource.getContents().stream().allMatch(o -> o.eResource() != resource)) { // prohibits the derived state calculator from calculating stuff before the contained elements belong to the // resource return; } resource.getContents().forEach(derivedStateProcessor::calculateState); }
@Override public void saveModels(EList<Resource> resources, IProgressMonitor monitor) { BasicEList<Resource> filteredResources = new BasicEList<>( resources.stream().filter(r -> !"pathmap".equals(r.getURI().scheme())).collect(Collectors.toList())); resources.stream().filter(DerivedStateAwareResource.class::isInstance) .map(DerivedStateAwareResource.class::cast).forEach(PathmapFilteringTransferSystem::calculateState); transferSystem.saveModels(filteredResources, monitor); }
/** * This method will create a ResourceName instance for each ResourceByName element found within the context of a Rule, Query or Test. * The ResourceName will have a name which is prefixed by the name of its context container and are installed to the root of the * resource's contents. */ private void installResourceNamesForVariables (DerivedStateAwareResource resource) { Model m = (Model) resource.getContents().get(0); /** Filter for type Rule,Query or Test*/ final Predicate<EObject> filter = new Predicate<EObject>() { private final Set<EClass> filteredEClasses = Sets.newHashSet(SadlPackage.Literals.RULE, SadlPackage.Literals.TEST, SadlPackage.Literals.QUERY); @Override public boolean apply(EObject input) { return filteredEClasses.contains(input.eClass()); } }; List<ResourceName> result = Lists.newArrayList(); // Iterate over elements of type Rule,Test,Query for (EObject ctx: Iterables.filter(m.getElements(), filter)) { QualifiedName qn = qnProvider.getFullyQualifiedName(ctx); for (ResourceByName rbn: EcoreUtil2.eAllOfType(ctx, ResourceByName.class)) { ResourceName rn = SadlFactory.eINSTANCE.createResourceName(); String rbnName = NodeModelUtils.getTokenText(NodeModelUtils.getNode(rbn)); String name = qn.toString()+"_"+rbnName; rn.setName(name); result.add(rn); } } // now install ResourceNames into resource m.eResource().getContents().addAll(result); }
@Override public Class<? extends XtextResource> bindXtextResource() { return DerivedStateAwareResource.class; }
@Override public void discardDerivedState(DerivedStateAwareResource resource) { cleanAssociationState(resource); }
public JvmDeclaredTypeAcceptor(DerivedStateAwareResource resource) { this.resource = resource; }
@Override public void discardDerivedState(DerivedStateAwareResource resource) { }
@Override public Resource createResource(URI uri) { DerivedStateAwareResource result = new DerivedStateAwareResource(); getResources().add(result); return result; }
@Override public void discardDerivedState(DerivedStateAwareResource resource) { return; }
private static void calculateState(DerivedStateAwareResource resource) { resource.discardDerivedState(); resource.installDerivedState(false); }
@Override public void installDerivedState(DerivedStateAwareResource resource, boolean preLinkingPhase) { installResourceNamesForVariables(resource); }
@Override public void discardDerivedState(DerivedStateAwareResource resource) { if (resource.getContents().isEmpty()) return; List<ResourceName> toRemove = Lists.newArrayList(Iterables.filter(resource.getContents(), ResourceName.class)); resource.getContents().removeAll(toRemove); }