Skip to content

Commit

Permalink
Filtering unqualified Stacktraces #115
Browse files Browse the repository at this point in the history
Using method signature to filter unqualified stacktraces generated in
java stacktrace console. + Includes code review changes

Fixes #115
  • Loading branch information
SougandhS committed Nov 1, 2024
1 parent f595ab8 commit b8fc106
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package a;
import java.net.URL;
/**
* Test class
*/
public class Sample {
public static void main(String[] args) {
System.out.println("Main Method");
test();
}
public static void test() {
System.out.println("Testing..");
}
public void testMethod() {
System.out.println("Random");
}
public static void tes3(int x) {
System.out.println("Expected_Single_Parameter");
}
public void tes2() {

}
public static void tesComplex(String[] x, java.net.URL[] sx) {
System.out.println("Expected_One_normal_&_One_fully_qualified");
}
public void testBlank() {
System.out.println("Expected_No_Signature");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,14 @@ public IStatus runInUIThread(IProgressMonitor monitor) {
if (exactMatchesFiltered.size() == 1) {
processSearchResult(exactMatchesFiltered.get(0), typeName, lineNumber);
return Status.OK_STATUS;
} else if (exactMatchesFiltered.size() > 1) {
for(Object res : exactMatchesFiltered) {
if (res instanceof IType type) {
if (type.getFullyQualifiedName().startsWith("bin.")) { //$NON-NLS-1$
exactMatchesFiltered.remove(res);
}
}
}
return openClipboard(exactMatchesFiltered, line, typeName);
}
List<Object> filteredResults = filterBinResults(exactMatchesFiltered);
if (filteredResults.size() == 1) {
processSearchResult(filteredResults.get(0), typeName, lineNumber);
return Status.OK_STATUS;
}
return openClipboard(filteredResults, line, typeName);

}
return openClipboard(matches, line, typeName);
} else {
Expand All @@ -241,6 +239,40 @@ public IStatus runInUIThread(IProgressMonitor monitor) {
job.schedule();
}

/**
* Further filters the extracted results
*
* @param exactMatchesFiltered
* extracted matches method name
* @return returns <code>List</code>
*/
private List<Object> filterBinResults(List<Object> exactMatchesFiltered) {
List<Object> itemsToBeDeleted = new ArrayList<>();
List<Object> fileredResults = new ArrayList<>();
for (Object res : exactMatchesFiltered) {
if (res instanceof IType type) {
if (type.getFullyQualifiedName().startsWith("bin.")) { //$NON-NLS-1$
String currentTarget = type.getFullyQualifiedName().substring(4);
long counts = exactMatchesFiltered.stream().filter(obj -> obj instanceof IType).map(obj -> (IType) obj).filter(ob -> {
String current = ob.getFullyQualifiedName();
if (current.startsWith("bin.")) { //$NON-NLS-1$
current = current.substring(4);
}
return current.equals(currentTarget);
}).count();
if (counts > 1) {
itemsToBeDeleted.add(res);
}
}
}
}
for (Object obj : exactMatchesFiltered) {
if (!itemsToBeDeleted.contains(obj)) {
fileredResults.add(obj);
}
}
return fileredResults;
}
/**
* Filter classes based on matching method name
*
Expand Down Expand Up @@ -656,4 +688,4 @@ private static String removeModuleInfo(String typeName) {
}
return typeName;
}
}
}

0 comments on commit b8fc106

Please sign in to comment.