Skip to content

Commit e1e8811

Browse files
PStmmroberlehner
authored andcommitted
Introducing error markers with QuickFix support for attributes
When an attribute is deleted from the type library, a new error marker will be created. This error marker now includes QuickFix support. The following Quickfixes are supported: Change atp Create atp Suggestion of best fitting atp
1 parent 58acd96 commit e1e8811

File tree

23 files changed

+580
-41
lines changed

23 files changed

+580
-41
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Johannes Kepler University Linz
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Paul Stemmer - initial API and implementation and/or initial documentation
12+
*******************************************************************************/
13+
package org.eclipse.fordiac.ide.application.marker.resolution;
14+
15+
import java.text.MessageFormat;
16+
import java.util.stream.Stream;
17+
18+
import org.eclipse.core.resources.IMarker;
19+
import org.eclipse.core.runtime.CoreException;
20+
import org.eclipse.core.runtime.IProgressMonitor;
21+
import org.eclipse.fordiac.ide.model.commands.change.ChangeAttributeDeclarationCommand;
22+
import org.eclipse.fordiac.ide.model.errormarker.FordiacErrorMarker;
23+
import org.eclipse.fordiac.ide.model.helpers.PackageNameHelper;
24+
import org.eclipse.fordiac.ide.model.libraryElement.Attribute;
25+
import org.eclipse.fordiac.ide.model.typelibrary.AttributeTypeEntry;
26+
import org.eclipse.fordiac.ide.model.typelibrary.TypeLibrary;
27+
import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager;
28+
import org.eclipse.fordiac.ide.ui.FordiacMessages;
29+
import org.eclipse.gef.commands.Command;
30+
import org.eclipse.swt.graphics.Image;
31+
32+
public class BestFitAttributeMarkerResolution extends AbstractCommandMarkerResolution<Attribute> {
33+
34+
private final AttributeTypeEntry selectedAttribute;
35+
36+
protected BestFitAttributeMarkerResolution(final IMarker marker, final AttributeTypeEntry selectedAttribute) {
37+
super(marker, Attribute.class);
38+
this.selectedAttribute = selectedAttribute;
39+
}
40+
41+
@Override
42+
protected boolean prepare(final IMarker[] markers, final IProgressMonitor monitor) throws CoreException {
43+
return true;
44+
}
45+
46+
@Override
47+
protected Command createCommand(final Attribute element, final IProgressMonitor monitor) throws CoreException {
48+
return ChangeAttributeDeclarationCommand.forName(element, selectedAttribute.getFullTypeName());
49+
50+
}
51+
52+
public static Stream<BestFitAttributeMarkerResolution> createResolutions(final IMarker marker) {
53+
String attrName = null;
54+
if (FordiacErrorMarker.getTarget(marker) instanceof final Attribute attr) {
55+
attrName = PackageNameHelper.extractPlainTypeName(attr.getName());
56+
}
57+
if (null == attrName) {
58+
return Stream.empty();
59+
}
60+
final String name = attrName;
61+
final TypeLibrary typeLibrary = TypeLibraryManager.INSTANCE.getTypeLibrary(marker.getResource().getProject());
62+
return typeLibrary.getAttributeTypes().stream().filter(type -> type.getTypeName().equals(name))
63+
.map(typeEntry -> new BestFitAttributeMarkerResolution(marker, typeEntry));
64+
}
65+
66+
@Override
67+
public String getDescription() {
68+
return MessageFormat.format(FordiacMessages.Repair_Dialog_BestFitAttrType, selectedAttribute.getFullTypeName());
69+
}
70+
71+
@Override
72+
public Image getImage() {
73+
return null;
74+
}
75+
76+
@Override
77+
public String getLabel() {
78+
return MessageFormat.format(FordiacMessages.Repair_Dialog_BestFitAttrType, selectedAttribute.getFullTypeName());
79+
}
80+
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Johannes Kepler University Linz
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Paul Stemmer - initial API and implementation and/or initial documentation
12+
*******************************************************************************/
13+
package org.eclipse.fordiac.ide.application.marker.resolution;
14+
15+
import org.eclipse.core.resources.IMarker;
16+
import org.eclipse.core.runtime.CoreException;
17+
import org.eclipse.core.runtime.IProgressMonitor;
18+
import org.eclipse.fordiac.ide.model.commands.change.ChangeAttributeDeclarationCommand;
19+
import org.eclipse.fordiac.ide.model.libraryElement.Attribute;
20+
import org.eclipse.fordiac.ide.model.typelibrary.AttributeTypeEntry;
21+
import org.eclipse.fordiac.ide.model.ui.editors.DataTypeTreeSelectionDialog;
22+
import org.eclipse.fordiac.ide.model.ui.nat.AttributeSelectionTreeContentProvider;
23+
import org.eclipse.fordiac.ide.model.ui.nat.TypeNode;
24+
import org.eclipse.fordiac.ide.ui.FordiacMessages;
25+
import org.eclipse.gef.commands.Command;
26+
import org.eclipse.jface.window.Window;
27+
import org.eclipse.swt.graphics.Image;
28+
import org.eclipse.ui.PlatformUI;
29+
30+
public class ChangeAttributeMarkerResolution extends AbstractCommandMarkerResolution<Attribute> {
31+
32+
private AttributeTypeEntry attribute;
33+
34+
protected ChangeAttributeMarkerResolution(final IMarker marker) {
35+
super(marker, Attribute.class);
36+
}
37+
38+
@Override
39+
protected boolean prepare(final IMarker[] markers, final IProgressMonitor monitor) throws CoreException {
40+
final DataTypeTreeSelectionDialog dialog = new DataTypeTreeSelectionDialog(
41+
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
42+
AttributeSelectionTreeContentProvider.INSTANCE);
43+
dialog.setInput(getTypeLibrary());
44+
if ((dialog.open() == Window.OK && dialog.getFirstResult() instanceof final TypeNode node
45+
&& !node.isDirectory())) {
46+
attribute = (AttributeTypeEntry) node.getTypeEntry();
47+
return true;
48+
}
49+
return false;
50+
}
51+
52+
@Override
53+
protected Command createCommand(final Attribute element, final IProgressMonitor monitor) throws CoreException {
54+
return ChangeAttributeDeclarationCommand.forName(element, attribute.getFullTypeName());
55+
}
56+
57+
@Override
58+
public String getDescription() {
59+
return FordiacMessages.Repair_Dialog_ChangeAttribute;
60+
}
61+
62+
@Override
63+
public Image getImage() {
64+
return null;
65+
}
66+
67+
@Override
68+
public String getLabel() {
69+
return FordiacMessages.Repair_Dialog_ChangeAttribute;
70+
}
71+
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Johannes Kepler University Linz
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Paul Stemmer - initial API and implementation and/or initial documentation
12+
*******************************************************************************/
13+
package org.eclipse.fordiac.ide.application.marker.resolution;
14+
15+
import java.io.File;
16+
17+
import org.eclipse.core.resources.IFile;
18+
import org.eclipse.core.resources.IMarker;
19+
import org.eclipse.core.resources.IProject;
20+
import org.eclipse.core.runtime.CoreException;
21+
import org.eclipse.core.runtime.IPath;
22+
import org.eclipse.core.runtime.IProgressMonitor;
23+
import org.eclipse.core.runtime.NullProgressMonitor;
24+
import org.eclipse.core.runtime.Path;
25+
import org.eclipse.core.runtime.Platform;
26+
import org.eclipse.fordiac.ide.model.commands.change.ChangeAttributeDeclarationCommand;
27+
import org.eclipse.fordiac.ide.model.helpers.PackageNameHelper;
28+
import org.eclipse.fordiac.ide.model.libraryElement.Attribute;
29+
import org.eclipse.fordiac.ide.model.typelibrary.AttributeTypeEntry;
30+
import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryTags;
31+
import org.eclipse.fordiac.ide.typemanagement.util.TypeFromTemplateCreator;
32+
import org.eclipse.fordiac.ide.typemanagement.wizards.NewTypeWizard;
33+
import org.eclipse.fordiac.ide.ui.FordiacMessages;
34+
import org.eclipse.gef.commands.Command;
35+
import org.eclipse.swt.graphics.Image;
36+
37+
public class CreateAttributMarkerResolution extends AbstractCommandMarkerResolution<Attribute> {
38+
private static final String TEMPLATE_PATH = Platform.getInstallLocation().getURL().getFile() + File.separatorChar
39+
+ "template" + File.separatorChar + "AttributeDeclaration.atp"; //$NON-NLS-1$ //$NON-NLS-2$
40+
41+
private AttributeTypeEntry newEntry;
42+
43+
protected CreateAttributMarkerResolution(final IMarker marker) {
44+
super(marker, Attribute.class);
45+
}
46+
47+
@Override
48+
protected boolean prepare(final IMarker[] markers, final IProgressMonitor monitor) throws CoreException {
49+
final File template = new File(TEMPLATE_PATH);
50+
51+
final String typeName = getMarker().getAttributes().get("location").toString(); //$NON-NLS-1$
52+
final IFile targetFile = getTargetFile(typeName, markers[0].getResource().getProject());
53+
final TypeFromTemplateCreator creator = new TypeFromTemplateCreator(targetFile, template,
54+
PackageNameHelper.extractPackageName(typeName));
55+
creator.createTypeFromTemplate(new NullProgressMonitor());
56+
NewTypeWizard.openTypeEditor(targetFile);
57+
58+
newEntry = (AttributeTypeEntry) creator.getTypeEntry();
59+
return null != newEntry;
60+
}
61+
62+
private static IFile getTargetFile(final String typeName, final IProject project) {
63+
return project.getFile(Path.fromOSString(TypeLibraryTags.TYPE_LIB_FOLDER_NAME)
64+
.append(typeName.replace(PackageNameHelper.PACKAGE_NAME_DELIMITER, String.valueOf(IPath.SEPARATOR)))
65+
.addFileExtension(TypeLibraryTags.ATTRIBUTE_TYPE_FILE_ENDING.toLowerCase()));
66+
}
67+
68+
@Override
69+
protected Command createCommand(final Attribute element, final IProgressMonitor monitor) throws CoreException {
70+
return switch (element) {
71+
case final Attribute attr -> ChangeAttributeDeclarationCommand.forName(attr, newEntry.getFullTypeName());
72+
};
73+
}
74+
75+
@Override
76+
public String getDescription() {
77+
return FordiacMessages.Repair_Dialog_New_Attribute;
78+
}
79+
80+
@Override
81+
public Image getImage() {
82+
return null;
83+
}
84+
85+
@Override
86+
public String getLabel() {
87+
return FordiacMessages.Repair_Dialog_New_Attribute;
88+
}
89+
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Johannes Kepler University Linz
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Paul Stemmer - initial API and implementation and/or initial documentation
12+
*******************************************************************************/
13+
package org.eclipse.fordiac.ide.application.marker.resolution;
14+
15+
import java.io.File;
16+
17+
import org.eclipse.core.resources.IFile;
18+
import org.eclipse.core.resources.IMarker;
19+
import org.eclipse.core.resources.IProject;
20+
import org.eclipse.core.runtime.CoreException;
21+
import org.eclipse.core.runtime.IPath;
22+
import org.eclipse.core.runtime.IProgressMonitor;
23+
import org.eclipse.core.runtime.NullProgressMonitor;
24+
import org.eclipse.core.runtime.Path;
25+
import org.eclipse.core.runtime.Platform;
26+
import org.eclipse.fordiac.ide.model.commands.change.ChangeAttributeDeclarationCommand;
27+
import org.eclipse.fordiac.ide.model.errormarker.FordiacErrorMarker;
28+
import org.eclipse.fordiac.ide.model.helpers.PackageNameHelper;
29+
import org.eclipse.fordiac.ide.model.libraryElement.Attribute;
30+
import org.eclipse.fordiac.ide.model.typelibrary.AttributeTypeEntry;
31+
import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryTags;
32+
import org.eclipse.fordiac.ide.typemanagement.util.TypeFromTemplateCreator;
33+
import org.eclipse.fordiac.ide.typemanagement.wizards.NewTypeWizard;
34+
import org.eclipse.fordiac.ide.ui.FordiacMessages;
35+
import org.eclipse.gef.commands.Command;
36+
import org.eclipse.swt.graphics.Image;
37+
38+
public class CreateAttributeMarkerResolution extends AbstractCommandMarkerResolution<Attribute> {
39+
private static final String TEMPLATE_PATH = Platform.getInstallLocation().getURL().getFile() + File.separatorChar
40+
+ "template" + File.separatorChar + "AttributeDeclaration.atp"; //$NON-NLS-1$ //$NON-NLS-2$
41+
42+
private AttributeTypeEntry newEntry;
43+
44+
protected CreateAttributeMarkerResolution(final IMarker marker) {
45+
super(marker, Attribute.class);
46+
}
47+
48+
@Override
49+
protected boolean prepare(final IMarker[] markers, final IProgressMonitor monitor) throws CoreException {
50+
final File template = new File(TEMPLATE_PATH);
51+
final String typeName = FordiacErrorMarker.getData(markers[0])[0];
52+
final IFile targetFile = getTargetFile(typeName, markers[0].getResource().getProject());
53+
final TypeFromTemplateCreator creator = new TypeFromTemplateCreator(targetFile, template,
54+
PackageNameHelper.extractPackageName(typeName));
55+
creator.createTypeFromTemplate(new NullProgressMonitor());
56+
NewTypeWizard.openTypeEditor(targetFile);
57+
58+
newEntry = (AttributeTypeEntry) creator.getTypeEntry();
59+
return null != newEntry;
60+
}
61+
62+
private static IFile getTargetFile(final String typeName, final IProject project) {
63+
return project.getFile(Path.fromOSString(TypeLibraryTags.TYPE_LIB_FOLDER_NAME)
64+
.append(typeName.replace(PackageNameHelper.PACKAGE_NAME_DELIMITER, String.valueOf(IPath.SEPARATOR)))
65+
.addFileExtension(TypeLibraryTags.ATTRIBUTE_TYPE_FILE_ENDING.toLowerCase()));
66+
}
67+
68+
@Override
69+
protected Command createCommand(final Attribute element, final IProgressMonitor monitor) throws CoreException {
70+
return ChangeAttributeDeclarationCommand.forName(element, newEntry.getFullTypeName());
71+
}
72+
73+
@Override
74+
public String getDescription() {
75+
return FordiacMessages.Repair_Dialog_New_Attribute;
76+
}
77+
78+
@Override
79+
public Image getImage() {
80+
return null;
81+
}
82+
83+
@Override
84+
public String getLabel() {
85+
return FordiacMessages.Repair_Dialog_New_Attribute;
86+
}
87+
88+
}

plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/marker/resolution/FordiacMarkerResolutionGenerator.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* - initial API and implementation and/or initial documentation
1414
* Martin Erich Jobst
1515
* - add resolutions for configurable FBs
16+
* Paul Stemmer
17+
* - add resolutions for Attributes
1618
*******************************************************************************/
1719
package org.eclipse.fordiac.ide.application.marker.resolution;
1820

@@ -29,6 +31,9 @@ public class FordiacMarkerResolutionGenerator implements IMarkerResolutionGenera
2931
@Override
3032
public IMarkerResolution[] getResolutions(final IMarker marker) {
3133
return switch (FordiacErrorMarker.getCode(marker)) {
34+
case LibraryElementValidator.ATTRIBUTE__VALIDATE_ATTRIBUTE_DECLARATION -> Stream.concat(
35+
Stream.of(new CreateAttributeMarkerResolution(marker), new ChangeAttributeMarkerResolution(marker)),
36+
BestFitAttributeMarkerResolution.createResolutions(marker)).toArray(IMarkerResolution[]::new);
3237
case LibraryElementValidator.ITYPED_ELEMENT__VALIDATE_TYPE,
3338
LibraryElementValidator.CONFIGURABLE_FB__VALIDATE_DATA_TYPE ->
3439
Stream.concat(
@@ -47,6 +52,7 @@ public boolean hasResolutions(final IMarker marker) {
4752
return LibraryElementValidator.DIAGNOSTIC_SOURCE.equals(FordiacErrorMarker.getSource(marker))
4853
&& (LibraryElementValidator.ITYPED_ELEMENT__VALIDATE_TYPE == code
4954
|| LibraryElementValidator.TYPED_CONFIGUREABLE_OBJECT__VALIDATE_TYPE == code
50-
|| LibraryElementValidator.CONFIGURABLE_FB__VALIDATE_DATA_TYPE == code);
55+
|| LibraryElementValidator.CONFIGURABLE_FB__VALIDATE_DATA_TYPE == code
56+
|| LibraryElementValidator.ATTRIBUTE__VALIDATE_ATTRIBUTE_DECLARATION == code);
5157
}
5258
}

plugins/org.eclipse.fordiac.ide.model.ui/src/org/eclipse/fordiac/ide/model/ui/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public final class Messages extends NLS {
2424
public static String DataTypeDropdown_Type_Selection;
2525
public static String DataTypeDropdown_Select_Type;
2626
public static String DataTypeDropdown_Elementary_Types;
27+
public static String AttributeTypeDropdown_Attribute_Types;
2728
public static String DataTypeDropdown_STRUCT_Types;
2829
public static String OpenEditorAction_text;
2930
public static String OpenEditorAction_viewertext;

plugins/org.eclipse.fordiac.ide.model.ui/src/org/eclipse/fordiac/ide/model/ui/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ AutoReloadError_PathNotFound=Automatic reload of editor not possible due to data
1616
DataTypeDropdown_Type_Selection=Type Selection
1717
DataTypeDropdown_Select_Type=Select a Type:
1818
DataTypeDropdown_Elementary_Types=Elementary Types
19+
AttributeTypeDropdown_Attribute_Types=Attribute Types
1920
DataTypeDropdown_STRUCT_Types=Structured Types
2021
DataTypeDropdown_Adapter_Types=Adapter Types
2122
DataTypeDropdown_FB_Types=FB Types

0 commit comments

Comments
 (0)