Skip to content

Commit

Permalink
Merge branch 'eclipse-jdt:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenartur authored Jan 26, 2024
2 parents e9959bb + 1e0e94b commit f5527a1
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pipeline {
archiveArtifacts artifacts: '*.log,*/target/work/data/.metadata/*.log,*/tests/target/work/data/.metadata/*.log,apiAnalyzer-workspace/.metadata/*.log', allowEmptyArchive: true
junit '**/target/surefire-reports/*.xml'
discoverGitReferenceBuild referenceJob: 'eclipse.jdt.debug-github/master'
recordIssues publishAllIssues: true, tools: [java(), mavenConsole(), javaDoc()]
recordIssues publishAllIssues: true, tools: [eclipse(pattern: '**/target/compilelogs/*.xml'), mavenConsole(), javaDoc()]
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions org.eclipse.jdt.debug.tests/java8/GH275.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import com.debug.test.Subject;
import com.debug.test.Observation;

public class GH275 {
public static void main(String[] args) {
Subject subject = new Subject("Name 1");
Observation.start(() -> subject, sub -> System.out.println(sub)).observe();
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ synchronized void assert18Project() {
try {
if (!loaded18) {
jp = createProject(ONE_EIGHT_PROJECT_NAME, JavaProjectHelper.TEST_1_8_SRC_DIR.toString(), JavaProjectHelper.JAVA_SE_1_8_EE_NAME, false);
IPath lib = new Path(JavaTestPlugin.getDefault().getFileInPlugin(new Path("testjars").append("gh275").append("debug-lib.jar")).getAbsolutePath());
JavaProjectHelper.addLibrary(jp, lib);

cfgs.add(createLaunchConfiguration(jp, "EvalTest18"));
cfgs.add(createLaunchConfiguration(jp, "FunctionalCaptureTest18"));
cfgs.add(createLaunchConfiguration(jp, "EvalTestIntf18"));
Expand Down Expand Up @@ -503,6 +506,7 @@ synchronized void assert18Project() {
cfgs.add(createLaunchConfiguration(jp, "Bug578145LambdaInAnonymous"));
cfgs.add(createLaunchConfiguration(jp, "Bug578145LambdaOnChainCalls"));
cfgs.add(createLaunchConfiguration(jp, "LambdaBreakpoints1"));
cfgs.add(createLaunchConfiguration(jp, "GH275"));
loaded18 = true;
waitForBuild();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,55 @@ public void testContextEvaluations() throws Exception {
}
}

public void testEvaluate_GH275_StaticBinaryMethod_EvaluateSnippetWithImportedTypes() throws Exception {
IJavaThread javaThread = null;
try {
IJavaLineBreakpoint bp = createLineBreakpoint(getType("com.debug.test.Observation"), 25);
javaThread = launchToLineBreakpoint("GH275", bp);
assertNotNull("The program did not suspend", javaThread);

String snippet = "new Observation((Object) subject, (Consumer) action)";
IValue value = doEval(javaThread, snippet);

assertNotNull("value is null", value);
} finally {
removeAllBreakpoints();
terminateAndRemove(javaThread);
}
}

public void testEvaluate_GH275_InstanceBinaryMethod_EvaluateConstructWithImportedTypes() throws Exception {
IJavaThread javaThread = null;
try {
IJavaLineBreakpoint bp = createLineBreakpoint(getType("com.debug.test.Observation"), 19);
javaThread = launchToLineBreakpoint("GH275", bp);
assertNotNull("The program did not suspend", javaThread);

String snippet = "new Observation((Object) subject, (Consumer) action)";
IValue value = doEval(javaThread, snippet);

assertNotNull("value is null", value);
} finally {
removeAllBreakpoints();
terminateAndRemove(javaThread);
}
}

public void testEvaluate_GH275_InstanceBinaryMethod_EvaluateSnippetWithImportedTypes() throws Exception {
IJavaThread javaThread = null;
try {
IJavaLineBreakpoint bp = createLineBreakpoint(getType("com.debug.test.Observation"), 19);
javaThread = launchToLineBreakpoint("GH275", bp);
assertNotNull("The program did not suspend", javaThread);

String snippet = "((Subject)this.subject).getName()";
IValue value = doEval(javaThread, snippet);

assertNotNull("value is null", value);
assertEquals("Return value doesn't match", "Name 1", value.getValueString());
} finally {
removeAllBreakpoints();
terminateAndRemove(javaThread);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testWatchPoint() throws Exception {
//create Breakpoint to test
createWatchpoint("a.b.c.Movee", "anInt", true, true);
//refactor
Refactoring ref = setupRefactor("Movee","anInt","src","a.b.c","Movee.java");
Refactoring ref = setupRefactor("Movee", "src", "a.b.c", "Movee.java");
performRefactor(ref);
//test breakpoints
IBreakpoint[] breakPoints = getBreakpointManager().getBreakpoints();
Expand All @@ -52,7 +52,7 @@ public void testWatchPoint() throws Exception {

/////////////////////////////////////////

private Refactoring setupRefactor(String parentClassName, String className, String root, String targetPackageName, String cuName) throws Exception {
private Refactoring setupRefactor(String parentClassName, String root, String targetPackageName, String cuName) throws Exception {

IJavaProject javaProject = get14Project();
IType parentClas= getCompilationUnit(javaProject, root, targetPackageName, cuName).getType(parentClassName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public void testSimpleArrayValueText() throws Exception {
try {
String sig = Signature.createTypeSignature("org.test.MyClass", false);
TestIJavaType type = new TestIJavaType("barfoo", sig);
TestIJavaArrayValue value = new TestIJavaArrayValue(type, "org.test.MyArrayClass[]", null, "org.test.MyClass", "My Array", 3);
TestIJavaArrayValue value = new TestIJavaArrayValue(type, "org.test.MyArrayClass[]", null, "org.test.MyClass", "My Array");
value.setValues(new IJavaValue[] {
new TestIJavaValue(type, "I", null, "org.test.MyArrayClass", "Array Value 1")
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ public class TestIJavaArrayValue extends TestIJavaObjectValue implements IJavaAr
int size = 0;
IJavaValue[] values;

/**
* Constructor
*/
public TestIJavaArrayValue(IJavaType type, String sig, String gsig, String rtname, String vstring, int size) {
TestIJavaArrayValue(IJavaType type, String sig, String gsig, String rtname, String vstring) {
super(type, sig, gsig, rtname, vstring);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,10 @@ public Image getImage(Object item) {

try {
if (item instanceof JDIReferenceListVariable) {
return getReferencesImage(item);
return getReferencesImage();
}
if (item instanceof JDIReferenceListEntryVariable){
return getReferenceImage(item);
return getReferenceImage();
}
if (item instanceof IJavaVariable) {
return getVariableImage((IAdaptable) item);
Expand Down Expand Up @@ -938,7 +938,7 @@ protected Image getVariableImage(IAdaptable element) {
*
* @return image associated with reference variables
*/
protected Image getReferencesImage(Object element){
private Image getReferencesImage() {
return JavaDebugImages.get(JavaDebugImages.IMG_ELCL_ALL_REFERENCES);
}

Expand All @@ -948,7 +948,7 @@ protected Image getReferencesImage(Object element){
*
* @return image associated with reference variables
*/
protected Image getReferenceImage(Object element){
private Image getReferenceImage() {
return JavaDebugImages.get(JavaDebugImages.IMG_OBJS_REFERENCE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ public IProgressMonitor getProgressMonitor() {
@Override
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
if (runnable instanceof ISchedulingRuleProvider) {
run(fork, cancelable, runnable, ((ISchedulingRuleProvider)runnable).getSchedulingRule());
run(runnable, ((ISchedulingRuleProvider) runnable).getSchedulingRule());
} else {
run(fork, cancelable, runnable, ResourcesPlugin.getWorkspace().getRoot());
run(runnable, ResourcesPlugin.getWorkspace().getRoot());
}
}

/**
* Runs a new {@link WorkspaceModifyDelegatingOperation}
*/
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable, ISchedulingRule schedulingRule) throws InvocationTargetException, InterruptedException {
private void run(IRunnableWithProgress runnable, ISchedulingRule schedulingRule) throws InvocationTargetException, InterruptedException {
WorkspaceModifyDelegatingOperation operation= new WorkspaceModifyDelegatingOperation(runnable, schedulingRule);
operation.run(getProgressMonitor());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PropertyPage;

public class JavaBreakpointAdvancedPage extends PropertyPage {
public abstract class JavaBreakpointAdvancedPage extends PropertyPage {

ThreadFilterEditor fThreadFilterEditor;
InstanceFilterEditor fInstanceFilterEditor;
Expand Down Expand Up @@ -82,9 +82,7 @@ public void createInstanceFilterEditor(Composite parent) {
/**
* Allow subclasses to create type-specific editors.
*/
protected void createTypeSpecificEditors(Composite parent) {
// Do nothing.
}
abstract void createTypeSpecificEditors(Composite parent);

protected void createThreadFilterEditor(Composite parent) {
fThreadFilterEditor = new ThreadFilterEditor(parent, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
*******************************************************************************/
package org.eclipse.jdt.internal.debug.eval.ast.engine;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.debug.core.IJavaReferenceType;
Expand Down Expand Up @@ -50,6 +53,8 @@ public class BinaryBasedSourceGenerator {

private String fCompilationUnitName;

private Set<String> fImports;

/**
* Level of source code to generate (major, minor). For example 1 and 4
* indicates 1.4.
Expand All @@ -63,6 +68,7 @@ public BinaryBasedSourceGenerator(String[] localTypesNames,
fLocalVariableTypeNames = localTypesNames;
fLocalVariableNames = localVariables;
fIsInStaticMethod = isInStaticMethod;
fImports = new HashSet<>();
int index = sourceLevel.indexOf('.');
String num;
if (index != -1) {
Expand Down Expand Up @@ -101,9 +107,16 @@ public void buildSourceStatic(IJavaReferenceType type) {
fSource = buildTypeDeclaration(refType, buildRunMethod(refType), null,
false);
String packageName = getPackageName(refType.name());
int packageEndPos = 0;
if (packageName != null) {
fSource.insert(0, "package " + packageName + ";\n"); //$NON-NLS-1$ //$NON-NLS-2$
fCodeSnippetPosition += 10 + packageName.length();
packageEndPos = 10 + packageName.length();
fCodeSnippetPosition += packageEndPos;
}
if (!fImports.isEmpty()) {
String importBlock = fImports.stream().collect(Collectors.joining(";\nimport ", "import ", ";")).concat("\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
fSource.insert(packageEndPos, importBlock);
fCodeSnippetPosition += importBlock.length();
}
fCompilationUnitName = getSimpleName(refType.name());
}
Expand All @@ -128,7 +141,9 @@ private StringBuilder buildRunMethod(ReferenceType type) {
source.append(getUniqueMethodName(RUN_METHOD_NAME, type));
source.append('(');
for (int i = 0, length = fLocalVariableNames.length; i < length; i++) {
source.append(getDotName(fLocalVariableTypeNames[i]));
String varType = getDotName(fLocalVariableTypeNames[i]);
addToImports(varType);
source.append(varType);
source.append(' ');
source.append(fLocalVariableNames[i]);
if (i + 1 < length)
Expand All @@ -147,6 +162,12 @@ private StringBuilder buildRunMethod(ReferenceType type) {
return source;
}

private void addToImports(String type) {
if (!type.equals(getSimpleName(type))) {
fImports.add(Signature.getTypeErasure(type));
}
}

private StringBuilder buildTypeDeclaration(ReferenceType referenceType,
StringBuilder buffer, String nestedTypeName) {

Expand All @@ -164,9 +185,16 @@ private StringBuilder buildTypeDeclaration(ReferenceType referenceType,

if (thisField == null) {
String packageName = getPackageName(referenceType.name());
int packageEndPos = 0;
if (packageName != null) {
source.insert(0, "package " + packageName + ";\n"); //$NON-NLS-1$ //$NON-NLS-2$
fCodeSnippetPosition += 10 + packageName.length();
packageEndPos = 10 + packageName.length();
fCodeSnippetPosition += packageEndPos;
}
if (!fImports.isEmpty()) {
String importBlock = fImports.stream().collect(Collectors.joining(";\nimport ", "import ", ";")).concat("\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
source.insert(packageEndPos, importBlock);
fCodeSnippetPosition += importBlock.length();
}
if (isAnonymousTypeName(referenceType.name())) {
fCompilationUnitName = ANONYMOUS_CLASS_NAME;
Expand Down Expand Up @@ -338,6 +366,8 @@ && isSourceLevelGreaterOrEqual(1, 5)) {
if (!method.isConstructor() && !method.isStaticInitializer()
&& !method.isBridge()) {
source.append(buildMethodDeclaration(method));
} else if (method.isConstructor()) {
source.append(buildMethodDeclaration(method, getSimpleName(referenceType.name())));
}
}

Expand Down Expand Up @@ -387,13 +417,19 @@ private StringBuilder buildFieldDeclaration(Field field) {
source.append("protected "); //$NON-NLS-1$
}

source.append(getDotName(field.typeName())).append(' ')
String dotName = getDotName(field.typeName());
addToImports(dotName);
source.append(dotName).append(' ')
.append(field.name()).append(';').append('\n');

return source;
}

private StringBuilder buildMethodDeclaration(Method method) {
return buildMethodDeclaration(method, null);
}

private StringBuilder buildMethodDeclaration(Method method, String methodName) {
StringBuilder source = new StringBuilder();

if (method.isFinal()) {
Expand Down Expand Up @@ -444,11 +480,10 @@ private StringBuilder buildMethodDeclaration(Method method) {
source.append("> "); //$NON-NLS-1$
}

source.append(
Signature.toString(
Signature.getReturnType(genericSignature)).replace(
'/', '.')).append(' ').append(method.name())
.append('(');
if (!method.isConstructor()) {
source.append(Signature.toString(Signature.getReturnType(genericSignature)).replace('/', '.')).append(' ');
}
source.append((methodName == null) ? method.name() : methodName).append('(');

String[] parameterTypes = Signature
.getParameterTypes(genericSignature);
Expand Down Expand Up @@ -481,8 +516,10 @@ private StringBuilder buildMethodDeclaration(Method method) {
}
source.append(')');
} else {
source.append(getDotName(method.returnTypeName())).append(' ')
.append(method.name()).append('(');
if (!method.isConstructor()) {
source.append(getDotName(method.returnTypeName())).append(' ');
}
source.append((methodName == null) ? method.name() : methodName).append('(');

List<String> arguments = method.argumentTypeNames();
int i = 0;
Expand Down
27 changes: 9 additions & 18 deletions org.eclipse.jdt.debug/jdi/org/eclipse/jdi/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,26 @@ public class Bootstrap {
public Bootstrap() {
}

@SuppressWarnings("deprecation")
public static synchronized com.sun.jdi.VirtualMachineManager virtualMachineManager() {
if (fVirtualMachineManager != null) {
return fVirtualMachineManager;
}

IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
String className = null;
if (extensionRegistry != null) { // is null if the platform was not started
className = extensionRegistry.getExtensionPoint(JDIDebugPlugin.getUniqueIdentifier(), "jdiclient").getLabel(); //$NON-NLS-1$
}
Class<?> clazz = null;
try {
IExtensionRegistry extensionRegistry = Platform
.getExtensionRegistry();
String className = null;
if (extensionRegistry != null) { // is null if the platform was not
// started
className = extensionRegistry
.getExtensionPoint(
JDIDebugPlugin.getUniqueIdentifier(),
"jdiclient").getLabel(); //$NON-NLS-1$
}
Class<?> clazz = null;
if (className != null) {
clazz = Class.forName(className);
}
if (clazz != null) {
fVirtualMachineManager = (com.sun.jdi.VirtualMachineManager) clazz
.newInstance();
fVirtualMachineManager = (com.sun.jdi.VirtualMachineManager) clazz.getDeclaredConstructor().newInstance();
}
} catch (ClassNotFoundException e) {
} catch (NoClassDefFoundError e) {
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
} catch (Exception e) {
throw new RuntimeException("Could not instantiate " + className, e); //$NON-NLS-1$
}

if (fVirtualMachineManager == null) {
Expand Down
Loading

0 comments on commit f5527a1

Please sign in to comment.