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

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
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
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 @@ -15,110 +15,21 @@
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,
boolean checkSTReferences,
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,19 @@ 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,
false, // TODO
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 @@ -43,6 +43,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 Down Expand Up @@ -89,8 +90,8 @@ public IStatus run(final IProgressMonitor monitor) throws OperationCanceledExcep
}

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 +170,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 +181,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 +279,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 @@ -315,7 +319,7 @@ 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)) {
if (modelQuerySpec.checkSTReferences() || text == null || pattern.preScanST(text)) {
for (final String fqn : VariableOperations.getAllDependencies(modelElement)) {
if (compareStrings(fqn)) {
return true;
Expand Down Expand Up @@ -345,18 +349,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 @@ -25,6 +25,7 @@
import org.eclipse.fordiac.ide.model.search.ModelSearchResult;
import org.eclipse.fordiac.ide.model.typelibrary.DataTypeEntry;
import org.eclipse.fordiac.ide.model.typelibrary.FBTypeEntry;
import org.eclipse.fordiac.ide.model.typelibrary.FunctionFBTypeEntry;
import org.eclipse.fordiac.ide.model.typelibrary.SubAppTypeEntry;
import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry;
import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager;
Expand All @@ -41,8 +42,19 @@ 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,
typeEntry instanceof FunctionFBTypeEntry,
SearchScope.PROJECT,
typeEntry.getFile().getProject());
// @formatter:on
final ModelSearchQuery query = createModelSearchQuery(typeEntry, searchSpec);
NewSearchUI.runQueryInBackground(query, NewSearchUI.getSearchResultView());
}
Expand Down
Loading