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 32d9ef8 commit 0f2ebc7
Show file tree
Hide file tree
Showing 9 changed files with 356 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,87 @@ public void testLinkNavigationTrueForInnerClassMultilevel() throws Exception {
}
}

public void testLinkNavigationTrueForInnerClassParameters() throws Exception {
String projectName = "StackTest";
IJavaProject project = createProject(projectName, "testfiles/AmbiguityTest/", JavaProjectHelper.JAVA_SE_1_8_EE_NAME, false);
waitForBuild();
waitForJobs();
consoleDocumentWithText("MyScheduledExecutor(Worker).doWork(MyScheduledExecutor$Wor) line: 20");
IHyperlink[] hyperlinks = fConsole.getHyperlinks();
assertEquals("Wrong hyperlinks, listing all links: " + allLinks(), 2, hyperlinks.length);
String expectedText = "System.out.println(\"Expected_Result\");";
try {
for (IHyperlink hyperlink : hyperlinks) {
closeAllEditors();
hyperlink.linkActivated();
IEditorPart editor = waitForEditorOpen();
String[] selectedText = new String[1];
sync(() -> selectedText[0] = getSelectedText(editor));
selectedText[0] = selectedText[0].trim();
assertEquals("Wrong text selected after hyperlink navigation", expectedText, selectedText[0]);

}
} finally {
closeAllEditors();
boolean force = true;
project.getProject().delete(force, new NullProgressMonitor());
}
}

public void testLinkNavigationTrueForInnerClassMultiParameters() throws Exception {
String projectName = "StackTest";
IJavaProject project = createProject(projectName, "testfiles/AmbiguityTest/", JavaProjectHelper.JAVA_SE_1_8_EE_NAME, false);
waitForBuild();
waitForJobs();
consoleDocumentWithText("MyScheduledExecutor(Worker).doWorkParams(MyScheduledExecutor$Wor,MyScheduledExecutor$Ran) line: 23");
IHyperlink[] hyperlinks = fConsole.getHyperlinks();
assertEquals("Wrong hyperlinks, listing all links: " + allLinks(), 2, hyperlinks.length);
String expectedText = "System.out.println(\"Expected_Result\");";
try {
for (IHyperlink hyperlink : hyperlinks) {
closeAllEditors();
hyperlink.linkActivated();
IEditorPart editor = waitForEditorOpen();
String[] selectedText = new String[1];
sync(() -> selectedText[0] = getSelectedText(editor));
selectedText[0] = selectedText[0].trim();
assertEquals("Wrong text selected after hyperlink navigation", expectedText, selectedText[0]);

}
} finally {
closeAllEditors();
boolean force = true;
project.getProject().delete(force, new NullProgressMonitor());
}
}

public void testLinkNavigationTrueForLinksWithNoProperMethodSignature() throws Exception {
String projectName = "StackTest";
IJavaProject project = createProject(projectName, "testfiles/AmbiguityTest/", JavaProjectHelper.JAVA_SE_1_8_EE_NAME, false);
waitForBuild();
waitForJobs();
consoleDocumentWithText("Sample.testBlank(Sample.java:40)");
IHyperlink[] hyperlinks = fConsole.getHyperlinks();
assertEquals("Wrong hyperlinks, listing all links: " + allLinks(), 1, hyperlinks.length);
String expectedText = "System.out.println(\"Expected_No_Signature\");";
try {
for (IHyperlink hyperlink : hyperlinks) {
closeAllEditors();
hyperlink.linkActivated();
IEditorPart editor = waitForEditorOpen();
String[] selectedText = new String[1];
sync(() -> selectedText[0] = getSelectedText(editor));
selectedText[0] = selectedText[0].trim();
assertEquals("Wrong text selected after hyperlink navigation", expectedText, selectedText[0]);

}
} finally {
closeAllEditors();
boolean force = true;
project.getProject().delete(force, new NullProgressMonitor());
}
}

private void waitForJobs() throws Exception {
TestUtil.waitForJobs(getName(), 250, 10_000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public static void main(String[] ar) {

}
class innerL1 {
void check() {
void check2() {
System.out.println("EXPECTED_INNERCLASS");
}
class innerL2 {
void check2() {
void check4() {
System.out.println("EXPECTED_INNER-INNER_CLASS");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* 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
*******************************************************************************/
public class MyScheduledExecutor {
public void executeTask() {
Wor worker = new Wor();
}
class Worker {
public void doWork2(Wor w) {

}
public void doWorkParams(Wor w,Ran r) {
System.out.println("Expected_Result");
}
}
class Wor {

}
class Ran {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* 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
*******************************************************************************/
public class MyScheduledExecutor {
public void executeTask() {
Wor worker = new Wor();
}
class Worker {
public void doWork(Wor w) {
System.out.println("Expected_Result");
}
}
class Wor {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ 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
@@ -0,0 +1,32 @@
/*******************************************************************************
* 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
*******************************************************************************/
/**
* Test class
*/
class InnerClassTest {
public static void main(String[] ar) {

}
class innerL1 {
void check1() {
System.out.println("EXPECTED_INNERCLASS");
}
class innerL2 {
void check23() {
System.out.println("EXPECTED_INNER-INNER_CLASS");
}
}
}
}

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
@@ -0,0 +1,32 @@
/*******************************************************************************
* 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
*******************************************************************************/
/**
* Test class
*/
class InnerClassTest {
public static void main(String[] ar) {

}
class innerL1 {
void check() {
System.out.println("EXPECTED_INNERCLASS");
}
class innerL2 {
void check2() {
System.out.println("EXPECTED_INNER-INNER_CLASS");
}
}
}
}

Loading

0 comments on commit 0f2ebc7

Please sign in to comment.