Skip to content

Commit

Permalink
Fix for #5
Browse files Browse the repository at this point in the history
Added an index method to fetch the name
removed NonStoringBatchLinkableResourceStorageFacade
  • Loading branch information
ghaith committed Apr 30, 2017
1 parent 96175f0 commit 6ee3a92
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -262,7 +262,7 @@ public void configureIResourceDescriptions(com.google.inject.Binder binder) {
}

public Class<? extends IResourceStorageFacade> bindResourceStorageFacade() {
return NonStoringBatchLinkableResourceStorageFacade.class;
return BatchLinkableResourceStorageFacade.class;
}

// TODO NO_XTEND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -245,7 +245,7 @@ public void configureIResourceDescriptions(com.google.inject.Binder binder) {
}

public Class<? extends IResourceStorageFacade> bindResourceStorageFacade() {
return NonStoringBatchLinkableResourceStorageFacade.class;
return BatchLinkableResourceStorageFacade.class;
}

// @Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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){
Expand Down Expand Up @@ -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<IEObjectDescription> 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('<');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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)
}
}
}
}

Expand All @@ -36,4 +45,8 @@ class SpecResourceDescriptionStrategy extends JnarioResourceDescriptionStrategy
}
}

static def getTypeName(IEObjectDescription specDescription) {
specDescription.getUserData(EXAMPLE_TYPE)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<String, String> 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());
}
}
}
}

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -229,7 +229,7 @@ public void configureIResourceDescriptions(com.google.inject.Binder binder) {
}

public Class<? extends IResourceStorageFacade> bindResourceStorageFacade() {
return NonStoringBatchLinkableResourceStorageFacade.class;
return BatchLinkableResourceStorageFacade.class;
}

@Override
Expand Down

This file was deleted.

0 comments on commit 6ee3a92

Please sign in to comment.