Skip to content

Instantly share code, notes, and snippets.

@abelhegedus
Created November 13, 2012 18:03
Show Gist options
  • Save abelhegedus/4067344 to your computer and use it in GitHub Desktop.
Save abelhegedus/4067344 to your computer and use it in GitHub Desktop.
Test case to reproduce ITC issue
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="descent" nsURI="http://descent/1.0" nsPrefix="descent">
<eClassifiers xsi:type="ecore:EClass" name="TestClass"/>
<eSubpackages name="jitd" nsURI="http://jitd.descent/1.0" nsPrefix="jitd">
<eClassifiers xsi:type="ecore:EClass" name="Game">
<eStructuralFeatures xsi:type="ecore:EReference" name="dungeon" lowerBound="1"
eType="#//jitd/dungeon/Dungeon" containment="true" eOpposite="#//jitd/dungeon/Dungeon/game"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="gameDecks" lowerBound="1"
eType="#//jitd/GameDecks" containment="true" eOpposite="#//jitd/GameDecks/game"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="GameDecks">
<eStructuralFeatures xsi:type="ecore:EReference" name="game" lowerBound="1"
eType="#//jitd/Game" eOpposite="#//jitd/Game/gameDecks"/>
</eClassifiers>
<eSubpackages name="dungeon" nsURI="http://dungeon.jitd.descent/1.0" nsPrefix="dungeon">
<eClassifiers xsi:type="ecore:EClass" name="Dungeon">
<eStructuralFeatures xsi:type="ecore:EReference" name="game" lowerBound="1"
eType="#//jitd/Game" eOpposite="#//jitd/Game/dungeon"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="rooms" lowerBound="1"
upperBound="-1" eType="#//jitd/dungeon/Room" containment="true" eOpposite="#//jitd/dungeon/Room/dungeon"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="connections" upperBound="-1"
eType="#//jitd/dungeon/RoomConnection" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="entitiesOnBoard" upperBound="-1"
eType="#//jitd/dungeon/OnBoardEntity" containment="true" eOpposite="#//jitd/dungeon/OnBoardEntity/dungeon"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Room">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="dungeon" lowerBound="1"
eType="#//jitd/dungeon/Dungeon" eOpposite="#//jitd/dungeon/Dungeon/rooms"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="directedConnections"
lowerBound="1" upperBound="-1" eType="#//jitd/dungeon/OrientationToConnectionPointMap"
containment="true" eOpposite="#//jitd/dungeon/OrientationToConnectionPointMap/room"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="coordinateToTileMap"
upperBound="-1" eType="#//jitd/dungeon/CoordinateToTileMap" containment="true"
eOpposite="#//jitd/dungeon/CoordinateToTileMap/room"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="RoomCoordinate">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="x" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"
defaultValueLiteral="-1"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="y" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"
defaultValueLiteral="-1"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Tile">
<eStructuralFeatures xsi:type="ecore:EReference" name="entitiesOnTile" upperBound="-1"
eType="#//jitd/dungeon/OnBoardEntity" eOpposite="#//jitd/dungeon/OnBoardEntity/location"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="tileMap" lowerBound="1"
eType="#//jitd/dungeon/CoordinateToTileMap" eOpposite="#//jitd/dungeon/CoordinateToTileMap/tile"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="RoomConnectionPoint">
<eStructuralFeatures xsi:type="ecore:EReference" name="connection" lowerBound="1"
eType="#//jitd/dungeon/RoomConnection" eOpposite="#//jitd/dungeon/RoomConnection/connectedPoints"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="connectedTiles" lowerBound="2"
upperBound="2" eType="#//jitd/dungeon/RoomCoordinate" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="connectionPointMap"
lowerBound="1" eType="#//jitd/dungeon/OrientationToConnectionPointMap"
eOpposite="#//jitd/dungeon/OrientationToConnectionPointMap/connection"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="RoomConnection">
<eStructuralFeatures xsi:type="ecore:EReference" name="connectedPoints" lowerBound="2"
upperBound="2" eType="#//jitd/dungeon/RoomConnectionPoint" eOpposite="#//jitd/dungeon/RoomConnectionPoint/connection"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="Orientation">
<eLiterals name="NORTH"/>
<eLiterals name="NORTHEAST" value="1"/>
<eLiterals name="EAST" value="2"/>
<eLiterals name="SOUTHEAST" value="3"/>
<eLiterals name="SOUTH" value="4"/>
<eLiterals name="SOUTHWEST" value="5"/>
<eLiterals name="WEST" value="6"/>
<eLiterals name="NORTHWEST" value="7"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="CoordinateToTileMap">
<eStructuralFeatures xsi:type="ecore:EReference" name="tile" lowerBound="1"
eType="#//jitd/dungeon/Tile" containment="true" eOpposite="#//jitd/dungeon/Tile/tileMap"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="coordinate" lowerBound="1"
eType="#//jitd/dungeon/RoomCoordinate" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="room" lowerBound="1"
eType="#//jitd/dungeon/Room" eOpposite="#//jitd/dungeon/Room/coordinateToTileMap"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="OrientationToConnectionPointMap">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="key" eType="#//jitd/dungeon/Orientation"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="connection" lowerBound="1"
eType="#//jitd/dungeon/RoomConnectionPoint" containment="true" eOpposite="#//jitd/dungeon/RoomConnectionPoint/connectionPointMap"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="room" lowerBound="1"
eType="#//jitd/dungeon/Room" eOpposite="#//jitd/dungeon/Room/directedConnections"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="OnBoardEntity" abstract="true">
<eStructuralFeatures xsi:type="ecore:EReference" name="location" lowerBound="1"
eType="#//jitd/dungeon/Tile" eOpposite="#//jitd/dungeon/Tile/entitiesOnTile"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="dungeon" lowerBound="1"
eType="#//jitd/dungeon/Dungeon" eOpposite="#//jitd/dungeon/Dungeon/entitiesOnBoard"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Monster" eSuperTypes="#//jitd/dungeon/OnBoardEntity">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="orientation" eType="#//jitd/dungeon/Orientation"
defaultValueLiteral=""/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="master" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="woundsLost" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"
defaultValueLiteral="0"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Glyph" eSuperTypes="#//jitd/dungeon/OnBoardEntity">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="activated" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"
defaultValueLiteral="false"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Rock" eSuperTypes="#//jitd/dungeon/OnBoardEntity"/>
<eClassifiers xsi:type="ecore:EClass" name="Pit" eSuperTypes="#//jitd/dungeon/OnBoardEntity"/>
<eClassifiers xsi:type="ecore:EClass" name="EventMarker" eSuperTypes="#//jitd/dungeon/OnBoardEntity"/>
<eClassifiers xsi:type="ecore:EClass" name="Water" eSuperTypes="#//jitd/dungeon/OnBoardEntity"/>
<eClassifiers xsi:type="ecore:EClass" name="Hero" eSuperTypes="#//jitd/dungeon/OnBoardEntity">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="currentWounds" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="currentFatigue" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="TreasureChest" eSuperTypes="#//jitd/dungeon/OnBoardEntity">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="treasureType" eType="#//jitd/dungeon/TreasureType"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="TreasureType">
<eLiterals name="BRONZE" literal="BRONZE"/>
<eLiterals name="SILVER" value="1" literal="SILVER"/>
<eLiterals name="GOLD" value="2" literal="GOLD"/>
</eClassifiers>
</eSubpackages>
</eSubpackages>
</ecore:EPackage>
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
import org.eclipse.viatra2.emf.incquery.triggerengine.util.PatternToMatchMultimap
import org.eclipse.viatra2.emf.incquery.runtime.extensibility.MatcherFactoryRegistry
import org.eclipse.viatra2.emf.incquery.base.api.IQueryResultUpdateListener
import org.eclipse.viatra2.emf.incquery.runtime.api.IPatternMatch
import org.eclipse.viatra2.emf.incquery.runtime.api.IncQueryMatcher
import org.eclipse.viatra2.emf.incquery.runtime.api.IMatcherFactory
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
import javax.inject.Inject
import org.apache.log4j.Logger
import java.util.logging.Logging
import org.eclipse.viatra2.emf.incquery.runtime.api.IncQueryEngine
import org.eclipse.emf.ecore.EPackage
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.viatra2.emf.incquery.base.api.NavigationHelper
import org.eclipse.viatra2.emf.incquery.base.api.IncQueryBaseFactory
import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.EcoreFactory
import java.util.Collection
@RunWith(typeof(XtextRunner))
@InjectWith(typeof(EMFPatternLanguageInjectorProvider))
class PatternBuilderTest {
@Inject Logger logger
@Test
def callbackTest(){
val resourceset = XmiModelUtil::prepareXtextResource
val pr = resourceset.createResource(URI::createFileURI("D:/temp/test/test.eiq"))
pr.load(null)
val pm = pr.contents.get(0) as PatternModel
val rs = new ResourceSetImpl
val mr = rs.createResource(URI::createFileURI("D:/temp/test/descent_2.ecore"))
mr.load(null)
val matchers = newArrayList()
val callback = new TestCallback
val CALLBACK = true
pm.patterns.forEach[
val factory = MatcherFactoryRegistry::getOrCreateMatcherFactory(it) as IMatcherFactory<IncQueryMatcher<IPatternMatch>>
val matcher = factory.getMatcher(rs)
matcher.addCallbackAfterUpdates(callback)
matchers.add(matcher);
]
val start = System::nanoTime
val end = System::nanoTime - start
logger.warn("[Callback] Total time on resource load: " + end + ", Count: " + callback.count)
val navHelper = IncQueryBaseFactory::instance.createNavigationHelper(rs, false, logger);
navHelper.registerEClasses(newHashSet(EcorePackage::eINSTANCE.EClass))
val eclasses = navHelper.getAllInstances(EcorePackage::eINSTANCE.EClass)
val start2 = System::nanoTime
eclasses.forEach[
val ec = it as EClass
if(ec.EPackage != EcorePackage::eINSTANCE){
ec.EPackage.EClassifiers.remove(it)
}
]
val end2 = System::nanoTime - start2
logger.warn("[Callback] Total time on model modification: " + end2 + ", Count: " + callback.count)
}
}
class TestCallback implements Runnable{
int count = 0
override run() {
count = count + 1
}
def getCount(){
return count;
}
}
import "http://www.eclipse.org/emf/2002/Ecore"
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);
neg find isEcore(Source);
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)
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 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);
}
TC init[141]: T(ECI@6f8f7fe2 (name: Dungeon) foobar;ECI@3e48983b (name: RoomConnection) foobar;)
TC init[141]: T(ECI@6f8f7fe2 (name: Dungeon) foobar;ECI@5b56becd (name: Room) foobar;)
TC init[141]: T(ECI@b3a0261 (name: OrientationToConnectionPointMap) foobar;ECI@2998a407 (name: RoomConnectionPoint) foobar;)
TC init[141]: T(ECI@1997ce1a (name: CoordinateToTileMap) foobar;ECI@701e8c16 (name: Tile) foobar;)
TC init[141]: T(ECI@5b56becd (name: Room) foobar;ECI@1997ce1a (name: CoordinateToTileMap) foobar;)
TC init[141]: T(ECI@33d650f6 (name: Game) foobar;ECI@7968f44a (name: GameDecks) foobar;)
TC init[141]: T(ECI@6f8f7fe2 (name: Dungeon) foobar;ECI@330d8014 (name: OnBoardEntity) (instanceClassName: null) (abstract: true, interface: false);)
TC init[141]: T(ECI@5b56becd (name: Room) foobar;ECI@b3a0261 (name: OrientationToConnectionPointMap) foobar;)
TC init[141]: T(ECI@33d650f6 (name: Game) foobar;ECI@6f8f7fe2 (name: Dungeon) foobar;)
TC init[141]: T(ECI@1997ce1a (name: CoordinateToTileMap) foobar;ECI@69b4b9d2 (name: RoomCoordinate) foobar;)
TC init[141]: T(ECI@2998a407 (name: RoomConnectionPoint) foobar;ECI@69b4b9d2 (name: RoomCoordinate) foobar;)
TC IN[141]: REVOKE !!! T(ECI@1997ce1a (name: CoordinateToTileMap) foobar;ECI@701e8c16 (name: Tile) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@1997ce1a (name: CoordinateToTileMap) foobar;ECI@701e8c16 (name: Tile) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@5b56becd (name: Room) foobar;ECI@701e8c16 (name: Tile) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@6f8f7fe2 (name: Dungeon) foobar;ECI@701e8c16 (name: Tile) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@33d650f6 (name: Game) foobar;ECI@701e8c16 (name: Tile) foobar;)
TC IN[141]: REVOKE !!! T(ECI@b3a0261 (name: OrientationToConnectionPointMap) foobar;ECI@2998a407 (name: RoomConnectionPoint) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@b3a0261 (name: OrientationToConnectionPointMap) foobar;ECI@2998a407 (name: RoomConnectionPoint) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@b3a0261 (name: OrientationToConnectionPointMap) foobar;ECI@69b4b9d2 (name: RoomCoordinate) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@5b56becd (name: Room) foobar;ECI@69b4b9d2 (name: RoomCoordinate) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@5b56becd (name: Room) foobar;ECI@2998a407 (name: RoomConnectionPoint) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@6f8f7fe2 (name: Dungeon) foobar;ECI@69b4b9d2 (name: RoomCoordinate) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@6f8f7fe2 (name: Dungeon) foobar;ECI@2998a407 (name: RoomConnectionPoint) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@33d650f6 (name: Game) foobar;ECI@69b4b9d2 (name: RoomCoordinate) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@33d650f6 (name: Game) foobar;ECI@2998a407 (name: RoomConnectionPoint) foobar;)
TC IN[141]: REVOKE !!! T(ECI@5b56becd (name: Room) foobar;ECI@b3a0261 (name: OrientationToConnectionPointMap) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@5b56becd (name: Room) foobar;ECI@b3a0261 (name: OrientationToConnectionPointMap) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@6f8f7fe2 (name: Dungeon) foobar;ECI@b3a0261 (name: OrientationToConnectionPointMap) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@33d650f6 (name: Game) foobar;ECI@b3a0261 (name: OrientationToConnectionPointMap) foobar;)
TC IN[141]: REVOKE !!! T(ECI@2998a407 (name: RoomConnectionPoint) foobar;ECI@69b4b9d2 (name: RoomCoordinate) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@2998a407 (name: RoomConnectionPoint) foobar;ECI@69b4b9d2 (name: RoomCoordinate) foobar;)
TC IN[141]: REVOKE !!! T(ECI@1997ce1a (name: CoordinateToTileMap) foobar;ECI@69b4b9d2 (name: RoomCoordinate) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@1997ce1a (name: CoordinateToTileMap) foobar;ECI@69b4b9d2 (name: RoomCoordinate) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@5b56becd (name: Room) foobar;ECI@69b4b9d2 (name: RoomCoordinate) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@6f8f7fe2 (name: Dungeon) foobar;ECI@69b4b9d2 (name: RoomCoordinate) foobar;)
TC OUT[141]: REVOKE !!! T(ECI@33d650f6 (name: Game) foobar;ECI@69b4b9d2 (name: RoomCoordinate) foobar;)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment