From 6ee3a929a65067e169024f79b9a25375cbe35047 Mon Sep 17 00:00:00 2001 From: Ghaith Hachem Date: Mon, 1 May 2017 00:57:51 +0200 Subject: [PATCH] Fix for #5 Added an index method to fetch the name removed NonStoringBatchLinkableResourceStorageFacade --- .../jnario/feature/FeatureRuntimeModule.java | 4 ++-- .../org/jnario/spec/SpecRuntimeModule.java | 4 ++-- .../spec/naming/ExampleNameProvider.java | 21 ++++++++++++++++ .../SpecResourceDescriptionStrategy.xtend | 13 ++++++++++ .../SpecResourceDescriptionStrategy.java | 24 ++++++++++++++++--- .../org/jnario/suite/SuiteRuntimeModule.java | 4 ++-- ...ingBatchLinkableResourceStorageFacade.java | 18 -------------- 7 files changed, 61 insertions(+), 27 deletions(-) delete mode 100644 plugins/org.jnario/src/org/jnario/resource/NonStoringBatchLinkableResourceStorageFacade.java diff --git a/plugins/org.jnario.feature/src/org/jnario/feature/FeatureRuntimeModule.java b/plugins/org.jnario.feature/src/org/jnario/feature/FeatureRuntimeModule.java index ecd3dda26..90e70255f 100644 --- a/plugins/org.jnario.feature/src/org/jnario/feature/FeatureRuntimeModule.java +++ b/plugins/org.jnario.feature/src/org/jnario/feature/FeatureRuntimeModule.java @@ -38,6 +38,7 @@ import org.eclipse.xtext.xbase.formatting.NodeModelAccess; import org.eclipse.xtext.xbase.jvmmodel.IJvmModelInferrer; import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder; +import org.eclipse.xtext.xbase.resource.BatchLinkableResourceStorageFacade; import org.eclipse.xtext.xbase.scoping.batch.ImplicitlyImportedFeatures; import org.eclipse.xtext.xbase.typesystem.computation.ITypeComputer; import org.eclipse.xtext.xbase.typesystem.internal.ScopeProviderAccess; @@ -73,7 +74,6 @@ import org.jnario.jvmmodel.JnarioSignatureHashBuilder; import org.jnario.report.Executable2ResultMapping; import org.jnario.report.HashBasedSpec2ResultMapping; -import org.jnario.resource.NonStoringBatchLinkableResourceStorageFacade; import org.jnario.scoping.JnarioImplicitlyImportedFeatures; import org.jnario.scoping.JnarioResourceDescriptionStrategy; import org.jnario.typing.JnarioTypeComputer; @@ -262,7 +262,7 @@ public void configureIResourceDescriptions(com.google.inject.Binder binder) { } public Class bindResourceStorageFacade() { - return NonStoringBatchLinkableResourceStorageFacade.class; + return BatchLinkableResourceStorageFacade.class; } // TODO NO_XTEND diff --git a/plugins/org.jnario.spec/src/org/jnario/spec/SpecRuntimeModule.java b/plugins/org.jnario.spec/src/org/jnario/spec/SpecRuntimeModule.java index 76738f7da..fe2d1df42 100644 --- a/plugins/org.jnario.spec/src/org/jnario/spec/SpecRuntimeModule.java +++ b/plugins/org.jnario.spec/src/org/jnario/spec/SpecRuntimeModule.java @@ -35,6 +35,7 @@ import org.eclipse.xtext.xbase.formatting.NodeModelAccess; import org.eclipse.xtext.xbase.jvmmodel.IJvmModelInferrer; import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder; +import org.eclipse.xtext.xbase.resource.BatchLinkableResourceStorageFacade; import org.eclipse.xtext.xbase.scoping.batch.ImplicitlyImportedFeatures; import org.eclipse.xtext.xbase.scoping.batch.XbaseBatchScopeProvider; import org.eclipse.xtext.xbase.typesystem.computation.ITypeComputer; @@ -58,7 +59,6 @@ import org.jnario.linking.JnarioLinkingService; import org.jnario.report.Executable2ResultMapping; import org.jnario.report.HashBasedSpec2ResultMapping; -import org.jnario.resource.NonStoringBatchLinkableResourceStorageFacade; import org.jnario.scoping.JnarioImplicitlyImportedFeatures; import org.jnario.spec.compiler.SpecBatchCompiler; import org.jnario.spec.conversion.SpecValueConverterService; @@ -245,7 +245,7 @@ public void configureIResourceDescriptions(com.google.inject.Binder binder) { } public Class bindResourceStorageFacade() { - return NonStoringBatchLinkableResourceStorageFacade.class; + return BatchLinkableResourceStorageFacade.class; } // @Override diff --git a/plugins/org.jnario.spec/src/org/jnario/spec/naming/ExampleNameProvider.java b/plugins/org.jnario.spec/src/org/jnario/spec/naming/ExampleNameProvider.java index 07f7f73e6..b77133148 100755 --- a/plugins/org.jnario.spec/src/org/jnario/spec/naming/ExampleNameProvider.java +++ b/plugins/org.jnario.spec/src/org/jnario/spec/naming/ExampleNameProvider.java @@ -20,15 +20,21 @@ import java.util.List; import java.util.Stack; +import java.util.stream.StreamSupport; import org.eclipse.emf.ecore.EObject; import org.eclipse.xtext.common.types.JvmParameterizedTypeReference; import org.eclipse.xtext.common.types.JvmTypeReference; import org.eclipse.xtext.common.types.TypesPackage; import org.eclipse.xtext.naming.QualifiedName; +import org.eclipse.xtext.resource.IEObjectDescription; +import org.eclipse.xtext.resource.IResourceDescription; +import org.eclipse.xtext.resource.IResourceDescriptions; +import org.eclipse.xtext.resource.IResourceDescriptions.IContextAware; import org.jnario.ExampleTable; import org.jnario.JnarioClass; import org.jnario.jvmmodel.JnarioNameProvider; +import org.jnario.spec.scoping.SpecResourceDescriptionStrategy; import org.jnario.spec.spec.After; import org.jnario.spec.spec.Before; import org.jnario.spec.spec.Example; @@ -52,6 +58,8 @@ public class ExampleNameProvider extends JnarioNameProvider{ @Inject private OperationNameProvider operationNameProvider; + @Inject + private IResourceDescriptions index; protected String internalToMethodName(EObject eObject){ if(eObject == null){ @@ -256,6 +264,19 @@ private boolean hasTargetOperation(ExampleGroup exampleGroup) { } private String resolveProxyTypeName(ExampleGroup exampleGroup) { + if (index instanceof IContextAware) { + //FIXME : Only for tests / non ui not sure why + ((IContextAware) index).setContext(exampleGroup); + } + IResourceDescription localizedIndex = index.getResourceDescription(exampleGroup.eResource().getURI()); + if (localizedIndex != null) { + Iterable result = localizedIndex.getExportedObjectsByObject(exampleGroup); + return StreamSupport.stream(result.spliterator(), false).findFirst().map(SpecResourceDescriptionStrategy::getTypeName).orElse(retrieveNameFromNodeModel(exampleGroup)); + } + return retrieveNameFromNodeModel(exampleGroup); + } + + private String retrieveNameFromNodeModel(ExampleGroup exampleGroup) { String text = textForFeature(exampleGroup, SpecPackage.Literals.EXAMPLE_GROUP__TARGET_TYPE); int begin = max(text.lastIndexOf('.'), text.lastIndexOf('$')) + 1; int end = text.indexOf('<'); diff --git a/plugins/org.jnario.spec/src/org/jnario/spec/scoping/SpecResourceDescriptionStrategy.xtend b/plugins/org.jnario.spec/src/org/jnario/spec/scoping/SpecResourceDescriptionStrategy.xtend index 464822e82..598d3895a 100755 --- a/plugins/org.jnario.spec/src/org/jnario/spec/scoping/SpecResourceDescriptionStrategy.xtend +++ b/plugins/org.jnario.spec/src/org/jnario/spec/scoping/SpecResourceDescriptionStrategy.xtend @@ -13,18 +13,27 @@ import org.jnario.scoping.JnarioResourceDescriptionStrategy import org.jnario.spec.spec.ExampleGroup import static java.lang.String.* +import org.eclipse.xtext.resource.IEObjectDescription +import org.eclipse.xtext.common.types.JvmVoid class SpecResourceDescriptionStrategy extends JnarioResourceDescriptionStrategy { public static val ROOT_SPEC = "root" public static val TRUE = "1" public static val FALSE = "0" + public static val EXAMPLE_TYPE = "type" override createUserData(EObject eObject, ImmutableMap.Builder userData) { super.createUserData(eObject, userData); if (eObject instanceof ExampleGroup){ val exampleGroup = eObject as ExampleGroup userData.put(ROOT_SPEC, valueOf(exampleGroup.isRoot)) + if (exampleGroup.targetType !== null) { + val targetType = exampleGroup.targetType + if (!(targetType.type instanceof JvmVoid)) { + userData.put(EXAMPLE_TYPE,exampleGroup.targetType.simpleName) + } + } } } @@ -36,4 +45,8 @@ class SpecResourceDescriptionStrategy extends JnarioResourceDescriptionStrategy } } + static def getTypeName(IEObjectDescription specDescription) { + specDescription.getUserData(EXAMPLE_TYPE) + } + } \ No newline at end of file diff --git a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/scoping/SpecResourceDescriptionStrategy.java b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/scoping/SpecResourceDescriptionStrategy.java index 07bb2ad87..f39aedef8 100644 --- a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/scoping/SpecResourceDescriptionStrategy.java +++ b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/scoping/SpecResourceDescriptionStrategy.java @@ -9,6 +9,10 @@ import com.google.common.collect.ImmutableMap; import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.common.types.JvmType; +import org.eclipse.xtext.common.types.JvmTypeReference; +import org.eclipse.xtext.common.types.JvmVoid; +import org.eclipse.xtext.resource.IEObjectDescription; import org.jnario.scoping.JnarioResourceDescriptionStrategy; import org.jnario.spec.spec.ExampleGroup; @@ -20,14 +24,24 @@ public class SpecResourceDescriptionStrategy extends JnarioResourceDescriptionSt public final static String FALSE = "0"; + public final static String EXAMPLE_TYPE = "type"; + @Override public void createUserData(final EObject eObject, final ImmutableMap.Builder userData) { super.createUserData(eObject, userData); if ((eObject instanceof ExampleGroup)) { final ExampleGroup exampleGroup = ((ExampleGroup) eObject); - String _isRoot = this.isRoot(exampleGroup); - String _valueOf = String.valueOf(_isRoot); - userData.put(SpecResourceDescriptionStrategy.ROOT_SPEC, _valueOf); + userData.put(SpecResourceDescriptionStrategy.ROOT_SPEC, String.valueOf(this.isRoot(exampleGroup))); + JvmTypeReference _targetType = exampleGroup.getTargetType(); + boolean _tripleNotEquals = (_targetType != null); + if (_tripleNotEquals) { + final JvmTypeReference targetType = exampleGroup.getTargetType(); + JvmType _type = targetType.getType(); + boolean _not = (!(_type instanceof JvmVoid)); + if (_not) { + userData.put(SpecResourceDescriptionStrategy.EXAMPLE_TYPE, exampleGroup.getTargetType().getSimpleName()); + } + } } } @@ -42,4 +56,8 @@ public String isRoot(final ExampleGroup exampleGroup) { } return _xifexpression; } + + public static String getTypeName(final IEObjectDescription specDescription) { + return specDescription.getUserData(SpecResourceDescriptionStrategy.EXAMPLE_TYPE); + } } diff --git a/plugins/org.jnario.suite/src/org/jnario/suite/SuiteRuntimeModule.java b/plugins/org.jnario.suite/src/org/jnario/suite/SuiteRuntimeModule.java index 781cd4f53..6a38898e1 100644 --- a/plugins/org.jnario.suite/src/org/jnario/suite/SuiteRuntimeModule.java +++ b/plugins/org.jnario.suite/src/org/jnario/suite/SuiteRuntimeModule.java @@ -34,6 +34,7 @@ import org.eclipse.xtext.xbase.compiler.output.TraceAwarePostProcessor; import org.eclipse.xtext.xbase.jvmmodel.IJvmModelInferrer; import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder; +import org.eclipse.xtext.xbase.resource.BatchLinkableResourceStorageFacade; import org.jnario.compiler.JnarioBatchCompiler; import org.jnario.conversion.JnarioJavaIDValueConverter; import org.jnario.doc.AbstractDocGenerator; @@ -47,7 +48,6 @@ import org.jnario.jvmmodel.JnarioSignatureHashBuilder; import org.jnario.report.Executable2ResultMapping; import org.jnario.report.HashBasedSpec2ResultMapping; -import org.jnario.resource.NonStoringBatchLinkableResourceStorageFacade; import org.jnario.scoping.JnarioResourceDescriptionStrategy; import org.jnario.suite.compiler.SuiteBatchCompiler; import org.jnario.suite.conversion.SuiteValueConverterService; @@ -229,7 +229,7 @@ public void configureIResourceDescriptions(com.google.inject.Binder binder) { } public Class bindResourceStorageFacade() { - return NonStoringBatchLinkableResourceStorageFacade.class; + return BatchLinkableResourceStorageFacade.class; } @Override diff --git a/plugins/org.jnario/src/org/jnario/resource/NonStoringBatchLinkableResourceStorageFacade.java b/plugins/org.jnario/src/org/jnario/resource/NonStoringBatchLinkableResourceStorageFacade.java deleted file mode 100644 index 705942dc8..000000000 --- a/plugins/org.jnario/src/org/jnario/resource/NonStoringBatchLinkableResourceStorageFacade.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.jnario.resource; - -import org.eclipse.xtext.resource.persistence.StorageAwareResource; -import org.eclipse.xtext.xbase.resource.BatchLinkableResourceStorageFacade; - -/** - * disables the storage feature of the new {@link StorageAwareResource} - * this is due to a missing NodeModel if the resource was loaded from storage - * TODO NO_XTEND: This is meant as a temp solution. A real solution should remove the references to NodeModelUtils - * (e.g. The suites will now fail to load the spec's type name if there is no symentic model attached to the resource) - * see org.jnario.spec.naming.ExampleNameProvider#resolveProxyTypeName - */ -public class NonStoringBatchLinkableResourceStorageFacade extends BatchLinkableResourceStorageFacade { - @Override - public boolean shouldLoadFromStorage(StorageAwareResource resource) { - return false; - } -}