How to serialise a generated PatternModel

Showing 1-12 of 12 messages
How to serialise a generated PatternModel Jan Reimann 10/24/12 8:22 AM
Hi all,
I try to load a base PatternModel (*.eiq file) which is based on our latest discussions here in the forum. Then I want to generate one additional paatern which should be added top the loaded PatternModel. This PatternModel then should be serialised but I get some strange errors. Attached to this mail you'll find first the generator test case. Second, you'll find the pattern which should be added to the PatternModel. Third, the pattern model which will be loaded initially. Can anybody help me with that?

best regards,
Jan

##############  generator test case (IncQueryGenerationTest.java) ###############

package org.emftext.refactoring.matching.incquery;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.viatra2.patternlanguage.EMFPatternLanguageRuntimeModule;
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.ParameterRef;
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.Pattern;
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.PatternBody;
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.PatternCall;
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.PatternCompositionConstraint;
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.PatternLanguageFactory;
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.Type;
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.Variable;
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.VariableReference;
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.VariableValue;
import org.eclipse.viatra2.patternlanguage.eMFPatternLanguage.EMFPatternLanguagePackage;
import org.eclipse.viatra2.patternlanguage.eMFPatternLanguage.PatternModel;
import org.eclipse.xtext.resource.IResourceFactory;
import org.junit.BeforeClass;
import org.junit.Test;

import com.google.inject.Guice;
import com.google.inject.Injector;

public class IncQueryGenerationTest {
   
    private static final String[] NAMES     = new String[]{"OrigContainer","ContainerContainer", "Extract", "NewContainer", "MovedReference"};
    private static final String[] relations = new String[]{
        "extracts:OrigContainer:Extract"
        ,"source:ContainerContainer:OrigContainer"
        , "target:ContainerContainer:NewContainer"
        , "referer:OrigContainer:MovedReference"
        , "moved:NewContainer:Extract"
        , "containerRef:MovedReference:NewContainer->"};

    private static final String TEMPLATE_FILE                = "base.eiq";
    private static final String OUTPUT_FOLDER                = ".";

    private static final String CONTAINMENT_PATTERN_NAME    = "containment";
    private static final String REFERENCE_PATTERN_NAME        = "reference";
   
    private static Resource patternResource;
    // a template will be loaded first which then can be extended
    private static PatternModel patternModel;
    // patterns to be referenced in generated pattern
    private static Pattern containmentPattern;
    private static Pattern referencePattern;
   
    @BeforeClass
    public static void init(){
        initLanguages();
        initModels();
        initReferencedPatterns();
    }

    @Test
    public void generatePatternTest(){
        PatternLanguageFactory factory = PatternLanguageFactory.eINSTANCE;
        Pattern pattern = factory.createPattern();
        pattern.setName("ExtractXWithRefClass");
        PatternBody patternBody = factory.createPatternBody();
        pattern.getBodies().add(patternBody);
        Map<String, Variable> variableNameMap = new HashMap<>();
        for (String name : NAMES) {
            Variable variable = factory.createVariable();
            variable.setName(name);
            Type type = factory.createType();
            type.setTypename(EClass.class.getSimpleName());
            variable.setType(type);
            variableNameMap.put(variable.getName(), variable);
            pattern.getParameters().add(variable);
        }
        for (String coll : relations) {
                String[] parts = coll.split(":");
                String name = parts[0];
                String source = parts[1];
                String target = parts[2];
                boolean isReference = target.endsWith("->");
                if(isReference){
                    target = target.substring(0, target.length() - 2);
                }
                Variable variable = factory.createVariable();
                variable.setName(name);
                Type type = factory.createType();
                type.setTypename(EReference.class.getSimpleName());
                variable.setType(type);
                pattern.getParameters().add(variable);
                PatternCall patternCall = factory.createPatternCall();
                Pattern calledPattern = null;
                if(isReference){
                    calledPattern = referencePattern;
                } else {
                    calledPattern = containmentPattern;
                }
                assertNotNull("calledPattern mustn't be null", calledPattern);
                patternCall.setPatternRef(calledPattern);
                VariableValue sourceValue = factory.createVariableValue();
                VariableValue targetValue = factory.createVariableValue();
                VariableReference sourceVariableReference = factory.createVariableReference();
                VariableReference targetVariableReference = factory.createVariableReference();
                ParameterRef sourceParameterRef = factory.createParameterRef();
                sourceParameterRef.setReferredParam(variableNameMap.get(source));
                sourceVariableReference.setVariable(sourceParameterRef);
                ParameterRef targetParameterRef = factory.createParameterRef();
                targetParameterRef.setReferredParam(variableNameMap.get(target));
                targetVariableReference.setVariable(targetParameterRef);
                sourceVariableReference.setVar(sourceParameterRef.getReferredParam().getName());
                targetVariableReference.setVar(targetParameterRef.getReferredParam().getName());
                sourceValue.setValue(sourceVariableReference);
                targetValue.setValue(targetVariableReference);
                patternCall.getParameters().add(sourceValue);
                if(isReference){
                    VariableValue referenceValue = factory.createVariableValue();
                    VariableReference referenceVariableReference = factory.createVariableReference();
                    sourceVariableReference.setVariable(variable);
                    referenceVariableReference.setVar(variable.getName());
                    referenceValue.setValue(referenceVariableReference);
                    patternCall.getParameters().add(referenceValue);
                }
                patternCall.getParameters().add(targetValue);
                PatternCompositionConstraint constraint = factory.createPatternCompositionConstraint();
                constraint.setCall(patternCall);
                patternBody.getConstraints().add(constraint);
        }
        patternModel.getPatterns().add(pattern);
        try {
            patternResource.save(Collections.EMPTY_MAP);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
   
    private static void initReferencedPatterns() {
        List<Pattern> patterns = patternModel.getPatterns();
        for (Pattern pattern : patterns) {
            if(pattern.getName().equals(CONTAINMENT_PATTERN_NAME)){
                containmentPattern = pattern;
            }
            if(pattern.getName().equals(REFERENCE_PATTERN_NAME)){
                referencePattern = pattern;
            }
            if(referencePattern != null && containmentPattern != null){
                break;
            }
        }
        assertNotNull("containment pattern mustn't be null", containmentPattern);
        assertNotNull("reference pattern mustn't be null", referencePattern);
    }
   
    public static void initModels() {
        ResourceSet rs = new ResourceSetImpl();

        // template file which will be extended by generated pattern
        File file = new File(TEMPLATE_FILE);
        assertTrue("template file " + file.getAbsolutePath() + " must exist", file.exists());
        URI uri = URI.createFileURI(file.getAbsolutePath());
        EObject model = rs.getResource(uri, true).getContents().get(0);
        assertTrue("must be a PatternModel", model instanceof PatternModel);
        patternModel = (PatternModel) model;
       
        // output model
        file = new File(OUTPUT_FOLDER + "/ExtractXWithRefClass." + uri.fileExtension());
        if(file.exists()){
            file.delete();
        }
        assertFalse("File " + file.getName() + " must not exist", file.exists());
        uri = URI.createFileURI(file.getAbsolutePath());
        patternResource = rs.createResource(uri);
        assertNotNull("Pattern resource mustn't be null", patternResource);
        patternResource.getContents().add(patternModel);
    }
   
    private static void initLanguages(){
        // XMI
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
        // Pattern language
        EPackage.Registry.INSTANCE.put(EMFPatternLanguagePackage.eNS_URI, EMFPatternLanguagePackage.eINSTANCE);
        Injector injector = Guice.createInjector(new EMFPatternLanguageRuntimeModule());
        IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("eiq", resourceFactory);
    }
   
   
}


##############  generated pattern which will be added to the PatternModel ###############

pattern ExtractXWithRefClass(OrigCont: EClass, ContCont: EClass, Extract:EClass, NewCont:EClass,
    MovedRef:EClass, extracts:EReference, source:EReference, target:EReference, referer:EReference,
    moved:EReference, containerRef:EReference){

    find containment(OrigCont, extracts, Extract);
    find containment(ContCont, source, OrigCont);
    find containment(ContCont, target, NewCont);
    find containment(OrigCont, referer, MovedRef);
    find containment(NewCont, moved, Extract);
    find reference(MovedRef, containerRef, NewCont);
}

##############  base template which will be extended by a generated pattern (base.eiq) ###############

import "http://www.eclipse.org/emf/2002/Ecore"

pattern containment(Source: EClass, reference: EReference, Target: EClass){
    find eAllContainments(PH_Source,reference);
    ETypedElement.eType(reference,PH_Target);
    find thisAndAllSuperTypes(Source, PH_Source);
    find thisAndAllSuperTypes(Target, PH_Target);
    neg find isEcore(Source);
}

pattern reference(Source: EClass, reference: EReference, Target: EClass){
    find eAllReferences(PH_Source,reference);
    ETypedElement.eType(reference,PH_Target);
    neg find isAggregation(reference);
    find thisAndAllSuperTypes(Source, PH_Source);
    find thisAndAllSuperTypes(Target, PH_Target);
    neg find isEcore(Source);
}

pattern canTransitivelyContain(Source : EClass, Target : EClass) {
    find canContain+(Source, Target);
}

pattern canContain(Source: EClass, Target : EClass) {
    find eAllContainments(Source,reference);
    EReference.eType(reference, Target);
}

@QueryExplorer(display = false)
pattern isEcore(Element){
    EClassifier.ePackage(Element,EP);
    EPackage(EP);
    EPackage.nsURI(EP,"http://www.eclipse.org/emf/2002/Ecore");
}

@QueryExplorer(display = false)
pattern isAggregation(ref:EReference){
    EReference.containment(ref,true);
}

// well-behaving ecore patterns

@QueryExplorer(display = false)
private pattern eStructuralFeatures(This : EClass, Target : EStructuralFeature){
    EClass.eStructuralFeatures(This, Target);
}

@QueryExplorer(display = false)
pattern eAttributes(This : EClass, Target : EAttribute){
    find eStructuralFeatures(This, Target);
}

@QueryExplorer(display = false)
pattern eReferences(This : EClass, Target : EReference){
    find eStructuralFeatures(This, Target);
}

@QueryExplorer(display = false)
private pattern eGenericSuperTypes(This : EClass, Target : EGenericType){
    EClass.eGenericSuperTypes(This, Target);
}

@QueryExplorer(display = false)
pattern eAllGenericSuperTypes(This : EClass, Target : EGenericType){
    find eSuperTypes+(This, Type);
    find eGenericSuperTypes(Type, Target);
} or {
    find eGenericSuperTypes(This, Target);
}

@QueryExplorer(display = false)
private pattern eRawType(This : EGenericType, Target : EClass){
    EGenericType.eRawType(This, Target);
}

@QueryExplorer(display = false)
pattern eSuperTypes(This : EClass, Target : EClass){
    find eGenericSuperTypes(This, GenericType);
    find eRawType(GenericType, Target);
}

@QueryExplorer(display = false)
pattern eAllSuperTypes(This : EClass, Target : EClass){
    find eAllGenericSuperTypes(This, GenericType);
    find eRawType(GenericType, Target);
}

@QueryExplorer(display = false)
private pattern thisAndAllSuperTypes(This : EClass, Target : EClass){
    find eAllSuperTypes(This, Target);
} or {
    This == Target;
}

@QueryExplorer(display = false)
pattern eAllStructuralFeatures(This : EClass, Target : EStructuralFeature){
    find thisAndAllSuperTypes(This, Type);
    find eStructuralFeatures(Type, Target);
}

@QueryExplorer(display = false)
pattern eAllAttributes(This : EClass, Target : EAttribute){
    find eAllStructuralFeatures(This, Target);
}

@QueryExplorer(display = false)
pattern eAllReferences(This : EClass, Target : EReference){
    find eAllStructuralFeatures(This, Target);
}

@QueryExplorer(display = false)
pattern eAllContainments(This : EClass, Target : EReference){
    find eAllReferences(This, Target);
    EReference.containment(Target, true);
}

@QueryExplorer(display = false)
private pattern eOperations(This : EClass, Target : EOperation){
    EClass.eOperations(This, Target);
}

@QueryExplorer(display = false)
pattern eAllOperations(This : EClass, Target : EOperation){
    find thisAndAllSuperTypes(This, Type);
    find eOperations(Type, Target);
}

// NOTE: EMF uses the first attribute with id = true from all supertypes...
@QueryExplorer(display = false)
pattern eIDAttribute(This : EClass, Target : EAttribute){
    find eAllAttributes(This, Target);
    EAttribute.iD(Target, true);
}
Re: [incquery-users] How to serialise a generated PatternModel Zoltán Ujhelyi 10/24/12 10:48 AM
Hi,

building the EMF models of our queries is an interesting challenge we have not really considered doing yet.

Basically, there are some issues you should be aware of when using EMF-IncQuery this way:
 * Be careful when instantiating Variables - as local variables (the ones contained in the PatternBody objects) are created automatically using a derived feature - so there is no need to create that manually for the defined variable references.
 * We have some issues in test environments when our patternlanguage.emf.ui project is loaded in the Run configuration. Consider unloading them if not needed.

I did not have time to set up your environment yet, so it is quite possible that I have missed something. If my ideas were not helpful to you, could you please attach the "strange error messages" to get a better understanding of your problem?

Cheers,
Zoltán
-- Zoltán Ujhelyi
https://www.inf.mit.bme.hu/en/members/ujhelyiz

Fault Tolerant Systems Research Group
Budapest University of Technology and Economics
> --
> You received this message because you are subscribed to the Google Groups "EMF-IncQuery Users" group.
> To post to this group, send email to incquer...@googlegroups.com.
> To unsubscribe from this group, send email to incquery-user...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msg/incquery-users/-/x5bbJ_sOVRoJ.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Re: [incquery-users] How to serialise a generated PatternModel Jan Reimann 10/26/12 1:12 AM
Hi Zoltán,
thanks for your answer

 
Basically, there are some issues you should be aware of when using EMF-IncQuery this way:
 * Be careful when instantiating Variables - as local variables (the ones contained in the PatternBody objects) are created automatically using a derived feature - so there is no need to create that manually for the defined variable references.
So how can I do this instead then?
 
 * We have some issues in test environments when our patternlanguage.emf.ui project is loaded in the Run configuration. Consider unloading them if not needed.

I don't have dependencies to ui plugins since I'm running a standalone JUnit test.
 
I did not have time to set up your environment yet, so it is quite possible that I have missed something. If my ideas were not helpful to you, could you please attach the "strange error messages" to get a better understanding of your problem?

It would be very nice if some of you guys could have a look at my setting. I assume reason for failing is my way of creating the pattern model programmatically since a reference cannot be resolved as can be seen in the following stacktrace I get when executing the test case:

0    [main] ERROR xt.linking.lazy.LazyLinkingResource  - resolution of uriFragment 'xtextLink_::0.2.0::0::/2' failed.
org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBoundsException: index=0, size=0
    at org.eclipse.emf.common.util.BasicEList.get(BasicEList.java:352)
    at org.eclipse.xtext.linking.lazy.LazyURIEncoder.resolveShortFragment(LazyURIEncoder.java:101)
    at org.eclipse.xtext.linking.lazy.LazyURIEncoder.decode(LazyURIEncoder.java:89)
    at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:166)
    at org.eclipse.xtext.xbase.resource.XbaseResource.access$0(XbaseResource.java:1)
    at org.eclipse.xtext.xbase.resource.XbaseResource$2.exec(XbaseResource.java:239)
    at org.eclipse.xtext.xbase.resource.XbaseResource$2.exec(XbaseResource.java:1)
    at org.eclipse.xtext.util.OnChangeEvictingCache.execWithoutCacheClear(OnChangeEvictingCache.java:124)
    at org.eclipse.xtext.xbase.resource.XbaseResource.getEObject(XbaseResource.java:237)
    at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:219)
    at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:203)
    at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:263)
    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy(BasicEObjectImpl.java:1483)
    at org.eclipse.viatra2.patternlanguage.eMFPatternLanguage.impl.PackageImportImpl.getEPackage(PackageImportImpl.java:76)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.sequence_PackageImport(AbstractEMFPatternLanguageSemanticSequencer.java:1221)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.createSequence(AbstractEMFPatternLanguageSemanticSequencer.java:119)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:299)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:325)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:239)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:394)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:439)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.sequence_EMFPatternModel(AbstractEMFPatternLanguageSemanticSequencer.java:1197)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.createSequence(AbstractEMFPatternLanguageSemanticSequencer.java:125)
    at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:85)
    at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:108)
    at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:130)
    at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:316)
    at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1423)
    at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:992)
    at org.emftext.refactoring.matching.incquery.CopyOfIncQueryTest.generatePatternTest(CopyOfIncQueryTest.java:145)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
16   [main] ERROR xt.linking.lazy.LazyLinkingResource  - resolution of uriFragment 'xtextLink_::0.2.0::0::/2' failed.
org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBoundsException: index=0, size=0
    at org.eclipse.emf.common.util.BasicEList.get(BasicEList.java:352)
    at org.eclipse.xtext.linking.lazy.LazyURIEncoder.resolveShortFragment(LazyURIEncoder.java:101)
    at org.eclipse.xtext.linking.lazy.LazyURIEncoder.decode(LazyURIEncoder.java:89)
    at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:166)
    at org.eclipse.xtext.xbase.resource.XbaseResource.access$0(XbaseResource.java:1)
    at org.eclipse.xtext.xbase.resource.XbaseResource$2.exec(XbaseResource.java:239)
    at org.eclipse.xtext.xbase.resource.XbaseResource$2.exec(XbaseResource.java:1)
    at org.eclipse.xtext.util.OnChangeEvictingCache.execWithoutCacheClear(OnChangeEvictingCache.java:124)
    at org.eclipse.xtext.xbase.resource.XbaseResource.getEObject(XbaseResource.java:237)
    at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:219)
    at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:207)
    at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:263)
    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy(BasicEObjectImpl.java:1483)
    at org.eclipse.viatra2.patternlanguage.eMFPatternLanguage.impl.PackageImportImpl.getEPackage(PackageImportImpl.java:76)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.sequence_PackageImport(AbstractEMFPatternLanguageSemanticSequencer.java:1221)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.createSequence(AbstractEMFPatternLanguageSemanticSequencer.java:119)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:299)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:325)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:239)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:394)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:439)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.sequence_EMFPatternModel(AbstractEMFPatternLanguageSemanticSequencer.java:1197)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.createSequence(AbstractEMFPatternLanguageSemanticSequencer.java:125)
    at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:85)
    at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:108)
    at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:130)
    at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:316)
    at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1423)
    at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:992)
    at org.emftext.refactoring.matching.incquery.CopyOfIncQueryTest.generatePatternTest(CopyOfIncQueryTest.java:145)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
80904 [main] ERROR xt.linking.lazy.LazyLinkingResource  - resolution of uriFragment 'xtextLink_::0.1.0.3.0.1::1::/2' failed.
org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBoundsException: index=0, size=0
    at org.eclipse.emf.common.util.BasicEList.get(BasicEList.java:352)
    at org.eclipse.xtext.linking.lazy.LazyURIEncoder.resolveShortFragment(LazyURIEncoder.java:101)
    at org.eclipse.xtext.linking.lazy.LazyURIEncoder.decode(LazyURIEncoder.java:89)
    at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:166)
    at org.eclipse.xtext.xbase.resource.XbaseResource.access$0(XbaseResource.java:1)
    at org.eclipse.xtext.xbase.resource.XbaseResource$2.exec(XbaseResource.java:239)
    at org.eclipse.xtext.xbase.resource.XbaseResource$2.exec(XbaseResource.java:1)
    at org.eclipse.xtext.util.OnChangeEvictingCache.execWithoutCacheClear(OnChangeEvictingCache.java:124)
    at org.eclipse.xtext.xbase.resource.XbaseResource.getEObject(XbaseResource.java:237)
    at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:219)
    at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:203)
    at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:263)
    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy(BasicEObjectImpl.java:1483)
    at org.eclipse.viatra2.patternlanguage.eMFPatternLanguage.impl.ClassTypeImpl.getClassname(ClassTypeImpl.java:77)
    at org.eclipse.viatra2.patternlanguage.eMFPatternLanguage.impl.ClassTypeImpl.eGet(ClassTypeImpl.java:121)
    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1021)
    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1013)
    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1008)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer$SerializableObject.<init>(BacktrackingSemanticSequencer.java:146)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:412)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.sequence_Type(AbstractEMFPatternLanguageSemanticSequencer.java:1240)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.createSequence(AbstractEMFPatternLanguageSemanticSequencer.java:97)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:299)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:325)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:222)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:401)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:439)
    at org.eclipse.viatra2.patternlanguage.core.serializer.AbstractPatternLanguageSemanticSequencer.sequence_Parameter(AbstractPatternLanguageSemanticSequencer.java:1329)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.createSequence(AbstractEMFPatternLanguageSemanticSequencer.java:291)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:299)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:325)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:239)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:394)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:439)
    at org.eclipse.viatra2.patternlanguage.core.serializer.AbstractPatternLanguageSemanticSequencer.sequence_Pattern(AbstractPatternLanguageSemanticSequencer.java:1431)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.createSequence(AbstractEMFPatternLanguageSemanticSequencer.java:251)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:299)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:325)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:239)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:394)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:439)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.sequence_EMFPatternModel(AbstractEMFPatternLanguageSemanticSequencer.java:1197)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.createSequence(AbstractEMFPatternLanguageSemanticSequencer.java:125)
    at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:85)
    at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:108)
    at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:130)
    at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:316)
    at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1423)
    at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:992)
    at org.emftext.refactoring.matching.incquery.CopyOfIncQueryTest.generatePatternTest(CopyOfIncQueryTest.java:145)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
80919 [main] ERROR xt.linking.lazy.LazyLinkingResource  - resolution of uriFragment 'xtextLink_::0.1.0.3.0.1::1::/2' failed.
org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBoundsException: index=0, size=0
    at org.eclipse.emf.common.util.BasicEList.get(BasicEList.java:352)
    at org.eclipse.xtext.linking.lazy.LazyURIEncoder.resolveShortFragment(LazyURIEncoder.java:101)
    at org.eclipse.xtext.linking.lazy.LazyURIEncoder.decode(LazyURIEncoder.java:89)
    at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:166)
    at org.eclipse.xtext.xbase.resource.XbaseResource.access$0(XbaseResource.java:1)
    at org.eclipse.xtext.xbase.resource.XbaseResource$2.exec(XbaseResource.java:239)
    at org.eclipse.xtext.xbase.resource.XbaseResource$2.exec(XbaseResource.java:1)
    at org.eclipse.xtext.util.OnChangeEvictingCache.execWithoutCacheClear(OnChangeEvictingCache.java:124)
    at org.eclipse.xtext.xbase.resource.XbaseResource.getEObject(XbaseResource.java:237)
    at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:219)
    at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:207)
    at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:263)
    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy(BasicEObjectImpl.java:1483)
    at org.eclipse.viatra2.patternlanguage.eMFPatternLanguage.impl.ClassTypeImpl.getClassname(ClassTypeImpl.java:77)
    at org.eclipse.viatra2.patternlanguage.eMFPatternLanguage.impl.ClassTypeImpl.eGet(ClassTypeImpl.java:121)
    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1021)
    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1013)
    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1008)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer$SerializableObject.<init>(BacktrackingSemanticSequencer.java:146)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:412)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.sequence_Type(AbstractEMFPatternLanguageSemanticSequencer.java:1240)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.createSequence(AbstractEMFPatternLanguageSemanticSequencer.java:97)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:299)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:325)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:222)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:401)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:439)
    at org.eclipse.viatra2.patternlanguage.core.serializer.AbstractPatternLanguageSemanticSequencer.sequence_Parameter(AbstractPatternLanguageSemanticSequencer.java:1329)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.createSequence(AbstractEMFPatternLanguageSemanticSequencer.java:291)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:299)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:325)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:239)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:394)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:439)
    at org.eclipse.viatra2.patternlanguage.core.serializer.AbstractPatternLanguageSemanticSequencer.sequence_Pattern(AbstractPatternLanguageSemanticSequencer.java:1431)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.createSequence(AbstractEMFPatternLanguageSemanticSequencer.java:251)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:299)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:325)
    at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:239)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:394)
    at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:439)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.sequence_EMFPatternModel(AbstractEMFPatternLanguageSemanticSequencer.java:1197)
    at org.eclipse.viatra2.patternlanguage.serializer.AbstractEMFPatternLanguageSemanticSequencer.createSequence(AbstractEMFPatternLanguageSemanticSequencer.java:125)
    at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:85)
    at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:108)
    at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:130)
    at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:316)
    at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1423)
    at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:992)
    at org.emftext.refactoring.matching.incquery.CopyOfIncQueryTest.generatePatternTest(CopyOfIncQueryTest.java:145)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
 
 
Re: [incquery-users] How to serialise a generated PatternModel Zoltán Ujhelyi 10/26/12 1:37 AM
Hi Jan,


On 2012.10.26., at 10:12, EMF-IncQuery Users on behalf of Jan Reimann <incquery-users+noreply-APn2wQc8Z1_pklUqTCInDLlXAvtzSIyfVP8SVM8QA@googlegroups.com> wrote:

> Hi Zoltán,
> thanks for your answer
>
>
>> Basically, there are some issues you should be aware of when using
>> EMF-IncQuery this way:
>> * Be careful when instantiating Variables - as local variables (the ones
>> contained in the PatternBody objects) are created automatically using a
>> derived feature - so there is no need to create that manually for the
>> defined variable references.
>>
> So how can I do this instead then?
Basically, I would create all VariableReferences _without_ creating corresponding local variables, and when all references are created, I would call body.getVariables(). But according to the exception trace at the end of your email, this is not the issue you are experiencing (possibly yet).

Or even better, it would make sense to use the patterns in their textual syntax as we do in our own tests. For the framework, see the org.eclipse.viatra2.emf.incquery.testing.core project (https://github.com/ujhelyiz/EMF-IncQuery/blob/master/tests/org.eclipse.viatra2.emf.incquery.testing.core), that is used in the school test project (stored in a different https://github.com/ujhelyiz/EMF-IncQuery-Examples/tree/master/school/school.tests).

>
>> * We have some issues in test environments when our
>> patternlanguage.emf.ui project is loaded in the Run configuration. Consider
>> unloading them if not needed.
>>
>> I don't have dependencies to ui plugins since I'm running a standalone
> JUnit test.
But the run configuration may still contain the ui plug-in, even if it is not loaded. However, as of now, standalone execution (without OSGi) is not supported, and we know explicitely of some known issues (that is why the IncQuery runtime will explicitly tell you it will not function - it basically checks whether the Eclipse platform is started).
According to the stack trace, the framework tries to read a PackageImport declaration but does not find it/cannot resolve it. When I looked in your code, I did not see any PackageImport element created - you might need to reference the ecore EPackage directly.

I hope, this was more helpful then the previous mail.

Cheers,
Zoltán

Re: [incquery-users] How to serialise a generated PatternModel Jan Reimann 10/30/12 5:22 AM
Hi Zoltán,
thanks for your answer.

Basically, I would create all VariableReferences _without_ creating corresponding local variables, and when all references are created, I would call body.getVariables(). But according to the exception trace at the end of your email, this is not the issue you are experiencing (possibly yet).

Or even better, it would make sense to use the patterns in their textual syntax as we do in our own tests. For the framework, see the org.eclipse.viatra2.emf.incquery.testing.core project (https://github.com/ujhelyiz/EMF-IncQuery/blob/master/tests/org.eclipse.viatra2.emf.incquery.testing.core), that is used in the school test project (stored in a different https://github.com/ujhelyiz/EMF-IncQuery-Examples/tree/master/school/school.tests).


According to the stack trace, the framework tries to read a PackageImport declaration but does not find it/cannot resolve it. When I looked in your code, I did not see any PackageImport element created - you might need to reference the ecore EPackage directly.

What I do is to load the base.eiq containing all my helper patterns discussed in my other threads before (such as all the containment, canContain or eAllStructuralFeatures patterns). This file is loaded which is intended to be extended afterwards by a new generated pattern which refers to some of the previously loaded patterns. The point is that the PatternModel created by loading the base.eiq contains the one and only package import to "http://www.eclipse.org/emf/2002/Ecore" but only is a proxy which cannot be resolved. My test class initialises the registry first as can be seen here:

    private static void initLanguages(){
        // Ecore
        EPackage.Registry.INSTANCE.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());

        // XMI
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
        // Pattern language
        EPackage.Registry.INSTANCE.put(XbasePackage.eNS_URI, XbasePackage.eINSTANCE);
        EPackage.Registry.INSTANCE.put(PatternLanguagePackage.eNS_URI, PatternLanguagePackage.eINSTANCE);

        EPackage.Registry.INSTANCE.put(EMFPatternLanguagePackage.eNS_URI, EMFPatternLanguagePackage.eINSTANCE);
        Injector injector = Guice.createInjector(new EMFPatternLanguageRuntimeModule());
        IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("eiq", resourceFactory);
    }

But it doesn't solve the problem. As I'm no Xtext expert I couldn't find the place where the text of the imported package is parsed/transformed into the PackageImport model element. There must be a place where this is done and where the EPackage.Registry is asked for the passed ns Uri string. Maybe this place must be adjusted?

best regards,
Jan

Re: [incquery-users] How to serialise a generated PatternModel Zoltán Ujhelyi 11/6/12 10:18 AM
Hi Jan,

sorry for the late answer.

I don't know the exact answer for your question, but if you have an Xtext UI bundle (in our case the org.eclipse.viatra2.patternlanguage.emf.ui), it registers an EMF extension parser for the generated parser available through a Guice-injected method.

As the runtime features provide no support for these injected methods, this registration is not done automatically.

I believe, you need to register an extension parser for this method through the XtextResourceFactory class, available through the injector created with the EMFPatternLanguageStandardSetup, and asking for an IResourceFactory.

I am sorry that I do not have any code for this, I am only speculating now based on my experiences. If this does not work out for you, then I will try to create something to parse eiq files programmatically - but I will not have the to do it this week.

Cheers,
Zoltán
-- Zoltán Ujhelyi
https://www.inf.mit.bme.hu/en/members/ujhelyiz

Fault Tolerant Systems Research Group
Budapest University of Technology and Economics

> --
> You received this message because you are subscribed to the Google Groups "EMF-IncQuery Users" group.
> To post to this group, send email to incquer...@googlegroups.com.
> To unsubscribe from this group, send email to incquery-user...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msg/incquery-users/-/RxyabSu6Q7sJ.
Re: [incquery-users] How to serialise a generated PatternModel Jan Reimann 11/7/12 12:13 AM
Hi Zoltán,
Yes, I did that what you wrote. You can see it in my first post:

private static void initLanguages(){

        // XMI
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
        // Pattern language

        EPackage.Registry.INSTANCE.put(EMFPatternLanguagePackage.eNS_URI, EMFPatternLanguagePackage.eINSTANCE);
        Injector injector = Guice.createInjector(new EMFPatternLanguageRuntimeModule());
        IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("eiq", resourceFactory);
}

It would be very nice if you can have a look at it. Don't get stressed, I don't need it this week.

best regards,
Jan

Am Dienstag, 6. November 2012 19:18:43 UTC+1 schrieb Zoltán Ujhelyi:
Re: [incquery-users] How to serialise a generated PatternModel Jan Reimann 11/7/12 4:08 AM
I found something interesting. A file globalEiqModel.xmi is created but it's invisible first. It contains your patterns in a XMI serialised resource. Why and where is this file created?
Re: [incquery-users] How to serialise a generated PatternModel Zoltán Ujhelyi 11/7/12 4:32 AM
Hi,

that is created by the code generator infrastructure as the generated pattern matchers use them.

This is problematic for several reasons, and we have some plans to either remove or restructure them (but none of them are in a final form yet). Alltogether, if it fixes your issue for now, you may use it (the system maintains a current version of it for now), but I do not recommend it, as we will almost certainly break your code in a not-to-far future.

Zoltán
-- Zoltán Ujhelyi
https://www.inf.mit.bme.hu/en/members/ujhelyiz

Fault Tolerant Systems Research Group
Budapest University of Technology and Economics

> --
> You received this message because you are subscribed to the Google Groups "EMF-IncQuery Users" group.
> To post to this group, send email to incquer...@googlegroups.com.
> To unsubscribe from this group, send email to incquery-user...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msg/incquery-users/-/cgREYX6ZgosJ.
Re: [incquery-users] How to serialise a generated PatternModel Jan Reimann 11/7/12 4:36 AM
Hi Zoltán,
oh I don't want to use it. I'm just curious about how the XMI is created programmatically. Can you give me a pointer?

best regards,
Jan

Am Mittwoch, 7. November 2012 13:32:14 UTC+1 schrieb Zoltán Ujhelyi:
Re: [incquery-users] How to serialise a generated PatternModel Zoltán Ujhelyi 11/7/12 4:53 AM
Hi,

The xmi is created in the code generator that already relies on Xtext features to parse the original textual representation, and it only uses the EMF model version. From that point, it is simple EMF-based operations.

If you want to have a look at the code, you could check the XmiModelBuilder class from the tooling.generator project (Github source url: https://github.com/ujhelyiz/EMF-IncQuery/blob/master/plugins/org.eclipse.viatra2.emf.incquery.tooling.generator/src/org/eclipse/viatra2/emf/incquery/tooling/generator/builder/xmi/XmiModelBuilder.xtend)

best regards,
Zoltán
-- Zoltán Ujhelyi
https://www.inf.mit.bme.hu/en/members/ujhelyiz

Fault Tolerant Systems Research Group
Budapest University of Technology and Economics

On 2012.11.07., at 13:36, EMF-IncQuery Users on behalf of Jan Reimann <incquery-users+noreply-APn2wQc8Z1_pklUqTCInDLlXAvtzSIyfVP8SVM8QA@googlegroups.com> wrote:

> Hi Zoltán,
> oh I don't want to use it. I'm just curious about how the XMI is created
> programmatically. Can you give me a pointer?
>
> best regards,
> Jan
>
> Am Mittwoch, 7. November 2012 13:32:14 UTC+1 schrieb Zoltán Ujhelyi:
>>
>> Hi,
>>
>> that is created by the code generator infrastructure as the generated
>> pattern matchers use them.
>>
>> This is problematic for several reasons, and we have some plans to either
>> remove or restructure them (but none of them are in a final form yet).
>> Alltogether, if it fixes your issue for now, you may use it (the system
>> maintains a current version of it for now), but I do not recommend it, as
>> we will almost certainly break your code in a not-to-far future.
>>
>> Zoltán
>> -- Zoltán Ujhelyi
>> https://www.inf.mit.bme.hu/en/members/ujhelyiz
>>
>> Fault Tolerant Systems Research Group
>> Budapest University of Technology and Economics
>>
>> On 2012.11.07., at 13:08, EMF-IncQuery Users on behalf of Jan Reimann <
>> incquery-users+noreply-APn2wQc8Z1_pklUqTCInDLlXAvtzSIyfVP8SVM8QA@googlegroups.com<javascript:>>
>> wrote:
>>
>>> I found something interesting. A file globalEiqModel.xmi is created but
>>> it's invisible first. It contains your patterns in a XMI serialised
>>> resource. Why and where is this file created?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>> Groups "EMF-IncQuery Users" group.
>>> To post to this group, send email to incquer...@googlegroups.com<javascript:>.
>>
>>> To unsubscribe from this group, send email to
>> incquery-user...@googlegroups.com <javascript:>.
>>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/incquery-users/-/cgREYX6ZgosJ.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups "EMF-IncQuery Users" group.
> To post to this group, send email to incquer...@googlegroups.com.
> To unsubscribe from this group, send email to incquery-user...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msg/incquery-users/-/1dZEMrf738EJ.
Re: [incquery-users] How to serialise a generated PatternModel Ábel Hegedüs 11/7/12 7:01 AM
Hi Jan,

after seeing the thread getting longer and longer I decided to give it a try as well.

I believe that the main problem with your code is that you load a pattern model from one file and then put the pattern model into a different resource. I think that Xtext fails to properly manage such copying,
I hava managed to create a small test case which (1) loads an existing pattern model, (2) creates a new pattern in code and adds it to the model, (3) then saves the modified model into the same file.
The code for this is embedded below (in Xtend), as you can see it's quite simple but I tested it and it works on my machine. The test.eiq is loaded using a file URI, since JUnit Plug-in Tests make it hard to work with workspace resources and you cannot save into plugin resources. I have tried it without test.eiq even existing (I have commented the part for creating a new pattern model) and also by putting the base.eiq queries you sent before into it and just attaching the new pattern.
I know that this may not be a holy grail, but it may help you move forward.

######################## PatternBuilderTest.xtend #######################

package somepackage

import org.eclipse.viatra2.patternlanguage.eMFPatternLanguage.PatternModel
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.PatternLanguageFactory
import org.eclipse.viatra2.patternlanguage.eMFPatternLanguage.EMFPatternLanguageFactory
import org.eclipse.emf.ecore.EcorePackage
import org.junit.Test
import org.junit.runner.RunWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.viatra2.emf.incquery.testing.core.injector.EMFPatternLanguageInjectorProvider
import org.eclipse.emf.common.util.URI
import org.eclipse.viatra2.emf.incquery.runtime.util.XmiModelUtil

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(EMFPatternLanguageInjectorProvider))
class PatternBuilderTest {
  
  @Test
  def simpleTest(){
    val resourceset = XmiModelUtil::prepareXtextResource
    val pr = resourceset.createResource(URI::createFileURI("D:/test.eiq"))   
        
    val factory = PatternLanguageFactory::eINSTANCE
    val emffactory = EMFPatternLanguageFactory::eINSTANCE
    
    pr.load(null)
    val pm = pr.contents.get(0) as PatternModel
    //val pm = emffactory.createPatternModel()
    //val ip = emffactory.createPackageImport()
    //ip.EPackage = EcorePackage::eINSTANCE
    //pm.importPackages.add(ip)
    
    val pattern = factory.createPattern()
    pattern.setName("ExtractXWithRefClass")
    val patternBody = factory.createPatternBody()
    pattern.getBodies().add(patternBody)
    
    val c = emffactory.createEClassifierConstraint()
    val ct = emffactory.createClassType()
    ct.setClassname(EcorePackage::eINSTANCE.EClass)
    c.setType(ct)
    val reference = factory.createVariableReference()
    reference.setVar("T")
    c.setVar(reference)
    patternBody.getConstraints().add(c)
    patternBody.getVariables()
    
    pm.getPatterns().add(pattern)
    //val pr = pm.eResource.resourceSet.createResource(URI::createFileURI("D:/test.eiq"));
    //pr.contents.add(pm);
    pr.save(null)
    //pm.eResource.save(null);
  }
 
}

#######################################################