| /** |
| * Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Florian Pirchner - Initial implementation |
| */ |
| package org.eclipse.osbp.xtext.oxtype.resource; |
| |
| import java.util.Date; |
| |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.EStructuralFeature; |
| import org.eclipse.emf.ecore.InternalEObject; |
| import org.eclipse.osbp.xtext.oxtype.linking.JvmTypeAwareLinkingHelper; |
| import org.eclipse.xtext.resource.IDerivedStateComputer; |
| import org.eclipse.xtext.util.OnChangeEvictingCache; |
| import org.eclipse.xtext.xbase.resource.BatchLinkableResource; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| import com.google.inject.Inject; |
| |
| @SuppressWarnings("restriction") |
| public class SemanticLoadingResource extends BatchLinkableResource implements ISemanticLoadingResource { |
| |
| private static final Logger LOGGER = LoggerFactory.getLogger(SemanticLoadingResource.class); |
| |
| @Inject(optional = true) |
| private IDerivedStateComputer derivedStateComputer; |
| |
| @Inject |
| private JvmTypeAwareLinkingHelper jvmProxyLinkingHelper; |
| |
| @Inject |
| private OnChangeEvictingCache cache; |
| |
| private DerivedStateMetric stateMetric = DerivedStateMetric.getInstance(); |
| |
| public SemanticLoadingResource() { |
| |
| } |
| |
| @Override |
| public EObject getSemanticElement(String fragment) { |
| return super.getEObject(fragment); |
| } |
| |
| @Override |
| public EObject getSemanticElement() { |
| return getContents().isEmpty() ? null : getContents().get(0); |
| } |
| |
| protected void resolveLazyCrossReference(InternalEObject source, EStructuralFeature crossRef) { |
| // if (isPotentialLazyCrossReference(crossRef) && !isJvmHelperLink(source, crossRef)) { |
| // doResolveLazyCrossReference(source, crossRef); |
| // } |
| super.resolveLazyCrossReference(source, crossRef); |
| } |
| |
| protected boolean isJvmHelperLink(EObject source, EStructuralFeature crossRef) { |
| EStructuralFeature containingFeature = source.eContainingFeature(); |
| return jvmProxyLinkingHelper.isJvmLink(containingFeature); |
| } |
| |
| // public void installDerivedState(boolean preIndexingPhase) { |
| // if (!isLoaded) |
| // throw new IllegalStateException("The resource must be loaded, before installDerivedState can be called."); |
| // if (!fullyInitialized && !isInitializing) { |
| // try { |
| // if (!preIndexingPhase) { |
| // cache.execWithoutCacheClear(this, e -> { |
| // isInitializing = true; |
| // if (derivedStateComputer != null) { |
| // Date start = new Date(); |
| // derivedStateComputer.installDerivedState(this, preIndexingPhase); |
| // Date end = new Date(); |
| // stateMetric.addMetric(getURI().toString(), end.getTime() - start.getTime()); |
| // } |
| // fullyInitialized = true; |
| // return null; |
| // }); |
| // } else { |
| // isInitializing = true; |
| // if (derivedStateComputer != null) { |
| // Date start = new Date(); |
| // derivedStateComputer.installDerivedState(this, preIndexingPhase); |
| // Date end = new Date(); |
| // stateMetric.addMetric("preindexing-" + getURI().toString(), end.getTime() - start.getTime()); |
| // } |
| // fullyInitialized = true; |
| // } |
| // } finally { |
| // isInitializing = false; |
| // getCache().clear(this); |
| // } |
| // } |
| // super.installDerivedState(preIndexingPhase); |
| // } |
| |
| } |