Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function FB type reference search #969

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ TypeQuery=Type Query
Warning=Warning
WorkspaceScope=Workspace
SearchForTypeReferences=Search for references of type {0}
STSearchErrorDialog_Title=Inaccurate Search
STSearchErrorDialog_Body=The search may be inaccurate as there are errors in the resolved ST code.
3 changes: 2 additions & 1 deletion plugins/org.eclipse.fordiac.ide.model.search/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
<test forcePluginActivation="false" property="org.eclipse.core.resources.extension" value="sub" />
<test forcePluginActivation="false" property="org.eclipse.core.resources.extension" value="dtd" />
<test forcePluginActivation="false" property="org.eclipse.core.resources.extension" value="dtp" />
</or>
<test forcePluginActivation="false" property="org.eclipse.core.resources.extension" value="fct" />
</or>
</adapt>
</iterate>
</with>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@SuppressWarnings("squid:S3008") // tell sonar the java naming convention does not make sense for this class
public final class Messages extends NLS {

private static final String BUNDLE_NAME = "org.eclipse.fordiac.ide.model.search.messages"; //$NON-NLS-1$
private static final String BUNDLE_NAME = "plugin"; //$NON-NLS-1$
public static String InstanceName;
public static String SearchHeaderName;
public static String ProjectScope;
Expand All @@ -43,6 +43,8 @@ public final class Messages extends NLS {
public static String Element;
public static String Location;
public static String SearchForTypeReferences;
public static String STSearchErrorDialog_Title;
public static String STSearchErrorDialog_Body;

static {
// initialize resource bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,110 +15,20 @@
import org.eclipse.core.resources.IProject;

// The inputs from the search page grouped in one place
public class ModelQuerySpec {
public record ModelQuerySpec(
String searchString,
boolean checkInstanceName,
boolean checkPinName,
boolean checkType,
boolean checkComments,
boolean checkCaseSensitive,
boolean checkExactMatching,
SearchScope scope,
IProject project
) {

public enum SearchScope {
WORKSPACE, PROJECT
}

private String searchString;
private boolean checkInstanceName;
private boolean checkPinName;
private boolean checkType;
private boolean checkComments;
private boolean checkCaseSensitive;
private boolean checkExactMatching;
private SearchScope scope;
private IProject project;

public ModelQuerySpec() {
}

public ModelQuerySpec(final String searchString, final boolean isCheckedInstanceName,
final boolean isCheckedPinName, final boolean isCheckedType, final boolean isCheckedComment,
final boolean isCaseSensitive, final boolean isExactNameMatching, final SearchScope scope,
final IProject project) {
this.searchString = searchString;
this.checkInstanceName = isCheckedInstanceName;
this.checkPinName = isCheckedPinName;
this.checkType = isCheckedType;
this.checkComments = isCheckedComment;
this.checkCaseSensitive = isCaseSensitive;
this.checkExactMatching = isExactNameMatching;
this.project = project;
this.scope = scope;
}

public String getSearchString() {
return searchString;
}

public boolean isCheckedInstanceName() {
return checkInstanceName;
}

public boolean isCheckedPinName() {
return checkPinName;
}

public boolean isCheckedType() {
return checkType;
}

public boolean isCheckedComment() {
return checkComments;
}

public boolean isCheckCaseSensitive() {
return checkCaseSensitive;
}

public boolean isCheckExactMatching() {
return checkExactMatching;
}

public SearchScope getScope() {
return scope;
}

public IProject getProject() {
return project;
}

public void setCheckCaseSensitive(final boolean checkCaseSensitive) {
this.checkCaseSensitive = checkCaseSensitive;
}

public void setSearchString(final String searchString) {
this.searchString = searchString;
}

public void setCheckedInstanceName(final boolean isCheckedInstanceName) {
this.checkInstanceName = isCheckedInstanceName;
}

public void setCheckedPinName(final boolean isCheckedPinName) {
this.checkPinName = isCheckedPinName;
}

public void setCheckedType(final boolean isCheckedType) {
this.checkType = isCheckedType;
}

public void setCheckedComment(final boolean isCheckedComment) {
this.checkComments = isCheckedComment;
}

public void setCheckExactMatching(final boolean checkExactMatching) {
this.checkExactMatching = checkExactMatching;
}

@Override
public String toString() {
return "ModelQuerySpec [searchString=" + searchString + ", checkInstanceName=" + checkInstanceName
+ ", checkPinName=" + checkPinName + ", checkType=" + checkType + ", checkComments=" + checkComments
+ ", checkCaseSensitive=" + checkCaseSensitive + ", checkExactMatching=" + checkExactMatching + "]";
}


WORKSPACE, PROJECT
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,18 @@ public boolean performAction() {
// string exists
final boolean optionSelected = isCheckedInstanceName || isCheckedPinName || isCheckedType || isCheckedComment;
if (!"".equals(searchString) && optionSelected) { //$NON-NLS-1$

final ModelQuerySpec modelQuerySpec = new ModelQuerySpec(searchString, isCheckedInstanceName,
isCheckedPinName, isCheckedType, isCheckedComment, isCaseSensitive, isExactNameMatching, getScope(),
// @formatter:off
final ModelQuerySpec modelQuerySpec = new ModelQuerySpec(
searchString,
isCheckedInstanceName,
isCheckedPinName,
isCheckedType,
isCheckedComment,
isCaseSensitive,
isExactNameMatching,
getScope(),
curProject);

// @formatter:on
final ModelSearchQuery searchJob = new ModelSearchQuery(modelQuerySpec);
NewSearchUI.runQueryInBackground(searchJob, NewSearchUI.getSearchResultView());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class ModelSearchPattern { // extends SearchPattern
private final String preScannSTStringPattern;

public ModelSearchPattern(final ModelQuerySpec modelQuerySpec) {
searchPattern = Pattern.compile(convertSearchStringToPattern(modelQuerySpec.getSearchString()));
searchPattern = Pattern.compile(convertSearchStringToPattern(modelQuerySpec.searchString()));

preScannSTStringPattern = generatePreScanSTStringPattern(modelQuerySpec.getSearchString());
preScannSTStringPattern = generatePreScanSTStringPattern(modelQuerySpec.searchString());
preScannSTPattern = (containsRegex(preScannSTStringPattern))
? Pattern.compile(preScannSTStringPattern, Pattern.CASE_INSENSITIVE)
: null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.fordiac.ide.model.data.ArrayType;
import org.eclipse.fordiac.ide.model.data.DataType;
import org.eclipse.fordiac.ide.model.data.StructuredType;
import org.eclipse.fordiac.ide.model.eval.EvaluatorPrepareException;
import org.eclipse.fordiac.ide.model.eval.variable.VariableOperations;
import org.eclipse.fordiac.ide.model.libraryElement.Algorithm;
import org.eclipse.fordiac.ide.model.libraryElement.Application;
Expand All @@ -43,6 +44,7 @@
import org.eclipse.fordiac.ide.model.libraryElement.FBNetwork;
import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement;
import org.eclipse.fordiac.ide.model.libraryElement.FBType;
import org.eclipse.fordiac.ide.model.libraryElement.FunctionFBType;
import org.eclipse.fordiac.ide.model.libraryElement.IInterfaceElement;
import org.eclipse.fordiac.ide.model.libraryElement.INamedElement;
import org.eclipse.fordiac.ide.model.libraryElement.InterfaceList;
Expand All @@ -56,16 +58,19 @@
import org.eclipse.fordiac.ide.model.libraryElement.VarDeclaration;
import org.eclipse.fordiac.ide.model.search.ModelQuerySpec.SearchScope;
import org.eclipse.fordiac.ide.ui.FordiacLogHelper;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search2.internal.ui.SearchView;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;

public class ModelSearchQuery implements ISearchQuery {

private final ModelQuerySpec modelQuerySpec;
private final ModelSearchPattern pattern;
private ModelSearchResult searchResult;
private boolean isIncompleteResult = false; // errors in resolved st code

public ModelSearchQuery(final ModelQuerySpec modelQuerySpec) {
this.modelQuerySpec = modelQuerySpec;
Expand All @@ -85,12 +90,19 @@ public IStatus run(final IProgressMonitor monitor) throws OperationCanceledExcep
Display.getDefault()
.asyncExec(() -> ((SearchView) NewSearchUI.getSearchResultView()).showSearchResult(getSearchResult()));

if (isIncompleteResult) {
Display.getDefault()
.asyncExec(() -> MessageDialog.openWarning(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
Messages.STSearchErrorDialog_Title, Messages.STSearchErrorDialog_Body));
}

return Status.OK_STATUS;
}

private List<ISearchContext> getSearchContexts() {
if (modelQuerySpec.getScope() == SearchScope.PROJECT && modelQuerySpec.getProject() != null) {
return Arrays.asList(new LiveSearchContext(modelQuerySpec.getProject()));
if (modelQuerySpec.scope() == SearchScope.PROJECT && modelQuerySpec.project() != null) {
return Arrays.asList(new LiveSearchContext(modelQuerySpec.project()));
}
// workspace scope
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
Expand Down Expand Up @@ -169,7 +181,7 @@ private void searchFBNetwork(final FBNetwork network, final List<FBNetworkElemen
searchFBNetwork(subApp.getSubAppNetwork(), path, monitor);
}
if (fbnetworkElement.getInterface() != null) {
if (modelQuerySpec.isCheckedPinName()) {
if (modelQuerySpec.checkPinName()) {
final List<IInterfaceElement> matchingPins = fbnetworkElement.getInterface()
.getAllInterfaceElements().stream()
.filter(pin -> pin.getName() != null && compareStrings(pin.getName())).toList();
Expand All @@ -180,7 +192,7 @@ private void searchFBNetwork(final FBNetwork network, final List<FBNetworkElemen
searchResult.addResults(matchingPins);
}
}
if (modelQuerySpec.isCheckedType()) {
if (modelQuerySpec.checkType()) {
searchInterface(fbnetworkElement.getInterface(), monitor);
}
}
Expand Down Expand Up @@ -278,21 +290,24 @@ private void searchInterface(final InterfaceList interfaceList, final IProgressM

private boolean matchEObject(final INamedElement modelElement, final IProgressMonitor monitor) {
SearchCanceledException.throwIfCanceled(monitor);
if (modelQuerySpec.isCheckedInstanceName()) {
if (modelQuerySpec.checkInstanceName()) {
final String name = modelElement.getName();
final boolean matchInstanceName = name != null && compareStrings(name);
if (matchInstanceName) {
return true;
}
}
if (modelQuerySpec.isCheckedComment()) {
if (modelQuerySpec.checkComments()) {
final String comment = modelElement.getComment();
final boolean matchComment = comment != null && compareStrings(comment);
if (matchComment) {
return true;
}
}
if (modelQuerySpec.isCheckedType()) {
if (modelQuerySpec.checkType()) {
if (modelElement instanceof FunctionFBType) {
return matchInST(modelElement);
}
if (modelElement instanceof final TypedConfigureableObject config) {
return compareStrings(config.getTypeName())
|| (config.getTypeEntry() != null && compareStrings(config.getTypeEntry().getFullTypeName()));
Expand All @@ -316,10 +331,14 @@ private boolean matchEObject(final INamedElement modelElement, final IProgressMo
private boolean matchInST(final INamedElement modelElement) {
final String text = getImplText(modelElement);
if (text == null || pattern.preScanST(text)) {
for (final String fqn : VariableOperations.getAllDependencies(modelElement)) {
if (compareStrings(fqn)) {
return true;
try {
for (final String fqn : VariableOperations.getAllDependencies(modelElement)) {
if (compareStrings(fqn)) {
return true;
}
}
} catch (final EvaluatorPrepareException e) {
isIncompleteResult = true;
}
}
return false;
Expand All @@ -345,18 +364,18 @@ private boolean compareStrings(final String toTest) {
if (pattern.matchSearchString(toTest)) {
return true;
}
if (modelQuerySpec.isCheckExactMatching()) {
return toTest.equals(modelQuerySpec.getSearchString());
if (modelQuerySpec.checkExactMatching()) {
return toTest.equals(modelQuerySpec.searchString());
}
if (modelQuerySpec.isCheckCaseSensitive()) {
return toTest.contains(modelQuerySpec.getSearchString());
if (modelQuerySpec.checkCaseSensitive()) {
return toTest.contains(modelQuerySpec.searchString());
}
return toTest.toLowerCase().contains(modelQuerySpec.getSearchString().toLowerCase());
return toTest.toLowerCase().contains(modelQuerySpec.searchString().toLowerCase());
}

@Override
public String getLabel() {
return modelQuerySpec.getSearchString();
return modelQuerySpec.searchString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,18 @@ public Object execute(final ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
final TypeEntry typeEntry = getTypeEntryFromSelection(selection);
if (typeEntry != null) {
final ModelQuerySpec searchSpec = new ModelQuerySpec(typeEntry.getFullTypeName(), false, false, true, false,
false, true, SearchScope.PROJECT, typeEntry.getFile().getProject());
// @formatter:off
final ModelQuerySpec searchSpec = new ModelQuerySpec(
typeEntry.getFullTypeName(),
false,
false,
true,
false,
false,
true,
SearchScope.PROJECT,
typeEntry.getFile().getProject());
// @formatter:on
final ModelSearchQuery query = createModelSearchQuery(typeEntry, searchSpec);
NewSearchUI.runQueryInBackground(query, NewSearchUI.getSearchResultView());
}
Expand Down
Loading