use of org.yakindu.base.types.Declaration in project statecharts by Yakindu.
the class RenameElementHandler method findElementForFakeInStatechart.
private NamedElement findElementForFakeInStatechart(NamedElement fakeElement) {
Resource resource = fakeElement.eResource();
// only do something if element is really from fake resource
if (resource instanceof LazyLinkingResource) {
Statechart sct = getStatechartFromFakeResource((LazyLinkingResource) resource);
EList<Scope> scopes = sct.getScopes();
for (Scope scope : scopes) {
// check all declarations
EList<Declaration> declarations = scope.getDeclarations();
for (Declaration decl : declarations) {
if (decl.eClass().getName().equals(fakeElement.eClass().getName()) && decl.getName().equals(fakeElement.getName())) {
return decl;
}
}
// check scope itself it is a named one
if (scope instanceof NamedElement) {
NamedElement namedScope = (NamedElement) scope;
if (namedScope.eClass().getName().equals(fakeElement.eClass().getName()) && namedScope.getName().equals(fakeElement.getName())) {
return namedScope;
}
}
}
}
return fakeElement;
}
use of org.yakindu.base.types.Declaration in project statecharts by Yakindu.
the class ModelSequencertDeclarationsTest method testMapScope.
@SuppressWarnings("unused")
@Test
public void testMapScope() {
InterfaceScope scope = _createInterfaceScope(null, null);
EventDefinition e1 = _createEventDefinition("e1", scope);
EventDefinition e2 = _createEventDefinition("e2", scope);
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
Scope _scope = structureMapping.mapScope(scope);
assertTrue(_scope instanceof InterfaceScope);
assertEquals(3, _scope.getDeclarations().size());
for (int i = 0; i < _scope.getDeclarations().size(); i++) {
Declaration s_decl = scope.getDeclarations().get(i);
Declaration r_decl = _scope.getDeclarations().get(i);
assertNotSame(s_decl, r_decl);
assertEquals(s_decl.getName(), r_decl.getName());
assertEquals(s_decl.getClass(), r_decl.getClass());
}
}
use of org.yakindu.base.types.Declaration in project statecharts by Yakindu.
the class SCTResourceTest method testStatechartParsing.
@Test
public void testStatechartParsing() {
Statechart statechart = createStatechart("internal: event Event1");
assertEquals(0, statechart.getScopes().size());
res.getContents().add(statechart);
assertEquals(1, statechart.getScopes().size());
Scope scope = statechart.getScopes().get(0);
assertTrue(scope instanceof InternalScope);
EList<Declaration> declarations = ((InternalScope) scope).getDeclarations();
Declaration declaration = declarations.get(0);
assertTrue(declaration instanceof EventDefinition);
assertEquals("" + res.getSyntaxDiagnostics(), 0, res.getSyntaxDiagnostics().size());
}
use of org.yakindu.base.types.Declaration in project statecharts by Yakindu.
the class ImportDeclarationImpl method setDeclaration.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setDeclaration(Declaration newDeclaration) {
Declaration oldDeclaration = declaration;
declaration = newDeclaration;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, SGraphPackage.IMPORT_DECLARATION__DECLARATION, oldDeclaration, declaration));
}
use of org.yakindu.base.types.Declaration in project statecharts by Yakindu.
the class STextJavaValidator method checkUnusedVariablesInInternalScope.
@Check(CheckType.FAST)
public void checkUnusedVariablesInInternalScope(InternalScope internalScope) {
EList<Declaration> internalScopeDeclarations = internalScope.getDeclarations();
EObject rootContainer = EcoreUtil.getRootContainer(internalScope);
Resource rootRes = getResource(rootContainer);
Statechart statechart = (Statechart) EcoreUtil.getObjectByType(rootRes.getContents(), SGraphPackage.Literals.STATECHART);
if (statechart == null)
return;
List<ElementReferenceExpression> allUsedElementReferences = EcoreUtil2.getAllContentsOfType(statechart, ElementReferenceExpression.class);
if (statechart.getSpecification() != null) {
for (Declaration internalDeclaration : internalScopeDeclarations) {
boolean internalDeclarationUsed = false;
for (ElementReferenceExpression elementReference : allUsedElementReferences) {
if (elementReference.getReference().eContainer() instanceof InternalScope) {
if (elementReference.getReference() instanceof VariableDefinition) {
if (((VariableDefinition) elementReference.getReference()).getName().equals(internalDeclaration.getName()) && internalDeclaration instanceof VariableDefinition) {
internalDeclarationUsed = true;
break;
}
} else if (elementReference.getReference() instanceof EventDefinition) {
if (((EventDefinition) elementReference.getReference()).getName().equals(internalDeclaration.getName()) && internalDeclaration instanceof EventDefinition) {
internalDeclarationUsed = true;
break;
}
} else if (elementReference.getReference() instanceof OperationDefinition) {
if (((OperationDefinition) elementReference.getReference()).getName().equals(internalDeclaration.getName()) && internalDeclaration instanceof OperationDefinition) {
internalDeclarationUsed = true;
break;
}
}
}
}
if (!internalDeclarationUsed) {
if (internalDeclaration instanceof VariableDefinition || internalDeclaration instanceof EventDefinition || internalDeclaration instanceof OperationDefinition)
warning(INTERNAL_DECLARATION_UNUSED, internalDeclaration, null, -1);
}
}
}
}
Aggregations