Skip to content

Commit

Permalink
Added data type attributes as children in DataTypeInstance Search
Browse files Browse the repository at this point in the history
  • Loading branch information
oberlehner committed Feb 4, 2025
1 parent 39ad8dc commit 466d2e3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.fordiac.ide.model.commands.change.ChangeAttributeDeclarationCommand;
import org.eclipse.fordiac.ide.model.commands.change.ChangeAttributeTypeCommand;
import org.eclipse.fordiac.ide.model.commands.change.ChangeDataTypeCommand;
import org.eclipse.fordiac.ide.model.commands.change.ChangeStructCommand;
import org.eclipse.fordiac.ide.model.commands.change.ConfigureFBCommand;
Expand Down Expand Up @@ -192,6 +193,10 @@ private static void handleDataTypeEntryUpdate(final LibraryElement editedElement
final DataTypeInstanceSearch search = new DataTypeInstanceSearch(editedElement, dtEntry);
final AnyDerivedType dataType = dtEntry.getType();
search.performSearch().stream().map(item -> {
if (item instanceof final Attribute attr) {
return ChangeAttributeTypeCommand.forDataType(attr, dataType);
}

if (item instanceof final VarDeclaration varDecl) {
return ChangeDataTypeCommand.forDataType(varDecl, dataType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@

import org.eclipse.emf.ecore.EObject;
import org.eclipse.fordiac.ide.model.data.StructuredType;
import org.eclipse.fordiac.ide.model.libraryElement.Application;
import org.eclipse.fordiac.ide.model.libraryElement.Attribute;
import org.eclipse.fordiac.ide.model.libraryElement.AttributeDeclaration;
import org.eclipse.fordiac.ide.model.libraryElement.AutomationSystem;
import org.eclipse.fordiac.ide.model.libraryElement.ConfigurableFB;
import org.eclipse.fordiac.ide.model.libraryElement.ConfigurableObject;
import org.eclipse.fordiac.ide.model.libraryElement.ErrorMarkerDataType;
import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement;
import org.eclipse.fordiac.ide.model.libraryElement.FBType;
import org.eclipse.fordiac.ide.model.libraryElement.IInterfaceElement;
import org.eclipse.fordiac.ide.model.libraryElement.LibraryElement;
import org.eclipse.fordiac.ide.model.libraryElement.UntypedSubApp;
import org.eclipse.fordiac.ide.model.libraryElement.VarDeclaration;
Expand Down Expand Up @@ -55,7 +60,8 @@ private static IEC61499SearchFilter createSearchFilter(final TypeEntry dtEntry)
return searchCandidate -> (searchCandidate instanceof final VarDeclaration varDecl
&& dtEntry == varDecl.getType().getTypeEntry())
|| (searchCandidate instanceof final ConfigurableFB configFb
&& isConfiguredWithDataType(configFb, dtEntry));
&& isConfiguredWithDataType(configFb, dtEntry))
|| (searchCandidate instanceof final Attribute attr && attr.getType().getTypeEntry() == dtEntry);
}

private static boolean isConfiguredWithDataType(final ConfigurableFB confFB, final TypeEntry dtEntry) {
Expand All @@ -72,7 +78,9 @@ private static final class DataTypeInstanceSearchChildrenProvider implements ISe
@Override
public boolean hasChildren(final EObject obj) {
return (obj instanceof FBType) || (obj instanceof AutomationSystem) || (obj instanceof UntypedSubApp)
|| (obj instanceof final StructuredType) || (obj instanceof final AttributeDeclaration);
|| (obj instanceof final StructuredType) || (obj instanceof final AttributeDeclaration)
|| (obj instanceof final Application) || (obj instanceof Attribute)
|| (obj instanceof FBNetworkElement) || (obj instanceof IInterfaceElement);
}

@Override
Expand All @@ -81,9 +89,17 @@ public Stream<? extends EObject> getChildren(final EObject obj) {
return SearchChildrenProviderHelper.getFBTypeChildren(fbType);
}
if (obj instanceof final AutomationSystem system) {
return system.getApplication().stream()
.flatMap(app -> app.getFBNetwork().getNetworkElements().stream());
return Stream.concat(system.getAttributes().stream(), system.getApplication().stream());
}

if (obj instanceof final Application application) {
Stream<? extends EObject> stream = application.getFBNetwork().getNetworkElements().stream();
stream = Stream.concat(stream, application.getFBNetwork().getAdapterConnections().stream());
stream = Stream.concat(stream, application.getFBNetwork().getDataConnections().stream());
stream = Stream.concat(stream, application.getFBNetwork().getEventConnections().stream());
return Stream.concat(stream, application.getAttributes().stream());
}

if (obj instanceof final UntypedSubApp untypedSubapp) {
return SearchChildrenProviderHelper.getUntypedSubappChildren(untypedSubapp);
}
Expand All @@ -93,6 +109,24 @@ public Stream<? extends EObject> getChildren(final EObject obj) {
if (obj instanceof final AttributeDeclaration attrdecl) {
return SearchChildrenProviderHelper.getAttributeDeclChildren(attrdecl);
}

if (obj instanceof final FBNetworkElement elem) {
return Stream.concat(elem.getAttributes().stream(),
SearchChildrenProviderHelper.getInterfaceListChildren(elem.getInterface()));
}

if (obj instanceof final IInterfaceElement interfaceElement) {
return interfaceElement.getAttributes().stream();
}

if (obj instanceof final Attribute atrr) {
return Stream.of(atrr.getType());
}

if (obj instanceof final ConfigurableObject object) {
return object.getAttributes().stream();
}

return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,18 @@ public static Stream<? extends EObject> getFBTypeChildren(final FBType fbType) {
if (fbType instanceof final SubAppType subappType) {
// we may have untyped subapps inside
retval = Stream.concat(retval, subappType.getFBNetwork().getNetworkElements().stream());
retval = Stream.concat(retval, subappType.getFBNetwork().getAdapterConnections().stream());
retval = Stream.concat(retval, subappType.getFBNetwork().getDataConnections().stream());
retval = Stream.concat(retval, subappType.getFBNetwork().getEventConnections().stream());
}

return retval;
}

public static Stream<? extends EObject> getUntypedSubappChildren(final UntypedSubApp untypedSubapp) {
Stream<? extends EObject> retval = getInterfaceListChildren(untypedSubapp.getInterface());
retval = Stream.concat(retval, untypedSubapp.getSubAppNetwork().getNetworkElements().stream());
retval = Stream.concat(retval, untypedSubapp.getAttributes().stream());
return retval;
}

Expand Down

0 comments on commit 466d2e3

Please sign in to comment.