Skip to content

Commit

Permalink
Updated association reference syntax to use '->' #53
Browse files Browse the repository at this point in the history
  • Loading branch information
ujhelyiz committed Jul 3, 2015
1 parent 8222cbe commit ee71abe
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.incquerylabs.uml.ralf.scoping.AbstractUMLContextProvider;
import com.incquerylabs.uml.ralf.scoping.IUMLContextProvider;
import com.incquerylabs.uml.ralf.ui.internal.ReducedAlfLanguageActivator;
import com.incquerylabs.uml.ralf.ui.queries.AssociationsOfClassMatcher;
import com.incquerylabs.uml.ralf.ui.queries.AttributesOfClassMatcher;
import com.incquerylabs.uml.ralf.ui.queries.XtClassMatcher;

Expand Down Expand Up @@ -195,6 +196,19 @@ public Iterable<Property> getPropertiesOfClass(Class cl) {
}
return super.getPropertiesOfClass(cl);
}

@Override
public Iterable<Property> getAssociationsOfClass(Class cl) {
AssociationsOfClassMatcher matcher;
try {
matcher = AssociationsOfClassMatcher.on(getEngine(getModel()));
return matcher.getAllValuesOfassociation(cl);
} catch (IncQueryException | ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return super.getPropertiesOfClass(cl);
}

@Override
public Class getThisType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ import "http://www.eclipse.org/uml2/5.0.0/UML"
import "http://Papyrus/xtUMLProfile"
import "http://Papyrus/ExecutableModelingProfile"

pattern xtClass(cl) {
pattern xtClass(cl : Class) {
XtClass.base_Class(_, cl);
}

pattern attributesOfClass(cl : Class, attribute : Property) {
// find xtClass(cl);
Property.type(sourceEnd, cl);
Association.ownedEnd(association, sourceEnd);
Association.ownedEnd(association, attribute);
sourceEnd != attribute;
} or {
// find xtClass(cl);
Class.ownedAttribute(cl, attribute);
}

pattern associationsOfClass(cl : Class, association : Property) {
// find xtClass(cl);
Property.type(sourceEnd, cl);
Association.ownedEnd(assoc, sourceEnd);
Association.ownedEnd(assoc, association);
sourceEnd != association;
}

pattern propertyNames(cl : Class, name) {
find attributesOfClass(cl, property);
Property.name(property, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ PrimaryExpression returns Expression :
BaseExpression
( {FeatureInvocationExpression.context = current} '.' operation = [uml::Operation|Name] parameters = Tuple |
{PropertyAccessExpression.context = current} '.' property = [uml::Property|Name] |
{AssociationAccessExpression.context = current} '->' association = [uml::Property|Name] |
// {ExtentOrExpression.nonNameExpression = current} '->'
// ( {SequenceOperationExpression.primary = current} operation = [uml::Operation|QualifiedName] tuple = Tuple
// // CHANGE: Made SequenceExpansionExpression concrete.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import org.eclipse.uml2.uml.Class
import org.eclipse.uml2.uml.Classifier
import org.eclipse.uml2.uml.PrimitiveType
import org.eclipse.uml2.uml.Type
import com.incquerylabs.uml.ralf.reducedAlfLanguage.AssociationAccessExpression
import com.incquerylabs.uml.ralf.reducedAlfLanguage.SendSignalStatement
import org.eclipse.uml2.uml.Signal

inject extension IUMLContextProvider umlContext
val REAL = IUMLContextProvider.REAL_TYPE
Expand Down Expand Up @@ -313,6 +316,12 @@ from {
result = ex.property.getType()
}

rule AssociationAccessExpression
G |- AssociationAccessExpression ex : Type result
from {
result = ex.association.getType()
}

rule FeatureLeftHandSide
G |- FeatureLeftHandSide lhs : Type result
from {
Expand Down Expand Up @@ -350,4 +359,19 @@ from {
empty |- st.variable : var Type varType
empty |- st.expression : var Type valueType
empty |- varType <: valueType
}

checkrule SendSignalStatement for
SendSignalStatement st
from {
empty |- st.signal : var Type signalType
empty |- st.target : var Type targetType
if (!(signalType instanceof Signal)) {
fail
error "Invalid signal type " + signalType.name
}
if (!(targetType instanceof Class)) {
fail
error "Invalid signal target " + targetType.name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ abstract class AbstractUMLContextProvider implements IUMLContextProvider {
return newArrayList
}

override getAssociationsOfClass(Class cl) {
return newArrayList
}

override getThisType() {
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface IUMLContextProvider {
Type getPrimitiveType(String name);

Iterable<Property> getPropertiesOfClass(Class cl);
Iterable<Property> getAssociationsOfClass(Class cl);

/**
* Returns the type of the this expression. If no container can be calculated, might return null.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ package com.incquerylabs.uml.ralf.scoping

import com.google.inject.Inject
import com.incquerylabs.uml.ralf.ReducedAlfSystem
import com.incquerylabs.uml.ralf.reducedAlfLanguage.AssociationAccessExpression
import com.incquerylabs.uml.ralf.reducedAlfLanguage.Block
import com.incquerylabs.uml.ralf.reducedAlfLanguage.Expression
import com.incquerylabs.uml.ralf.reducedAlfLanguage.PropertyAccessExpression
import com.incquerylabs.uml.ralf.reducedAlfLanguage.Statement
import com.incquerylabs.uml.ralf.reducedAlfLanguage.Statements
import com.incquerylabs.uml.ralf.reducedAlfLanguage.Variable
import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.EReference
import org.eclipse.uml2.uml.Class
import org.eclipse.xtext.scoping.IScope
import org.eclipse.xtext.scoping.Scopes
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider
import org.eclipse.xtext.util.PolymorphicDispatcher

/**
* This class contains custom scoping description.
Expand Down Expand Up @@ -133,10 +133,31 @@ class ReducedAlfLanguageScopeProvider extends AbstractDeclarativeScopeProvider {
return null
}
val type = typeResult.value
if (type instanceof org.eclipse.uml2.uml.Class) {
if (type instanceof Class) {
Scopes.scopeFor(umlContext.getPropertiesOfClass(type))
} else {
null
}
}

def IScope scope_AssociationAccessExpression_association(AssociationAccessExpression ctx, EReference ref) {
if (ctx.context != null && !(ctx.context.eIsProxy)) {
scope_AssociationAccessExpression_association(ctx.context, ref)
} else {
null
}
}

def IScope scope_AssociationAccessExpression_association(Expression ctx, EReference ref) {
val typeResult = system.type(ctx)
if (typeResult.failed) {
return null
}
val type = typeResult.value
if (type instanceof Class) {
Scopes.scopeFor(umlContext.getAssociationsOfClass(type))
} else {
null
}
}
}

0 comments on commit ee71abe

Please sign in to comment.