Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d87a1a0

Browse files
author
zhourenjian
committed
Porting Java2Script compiler from Eclipse 3.3 to Eclipse 3.4
1 parent 33c84a4 commit d87a1a0

File tree

8 files changed

+126
-790
lines changed

8 files changed

+126
-790
lines changed

src/net/sf/j2s/ui/launching/J2SApplicationLaunchShortcut.java

Lines changed: 10 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -11,132 +11,31 @@
1111
package net.sf.j2s.ui.launching;
1212

1313

14-
import java.lang.reflect.InvocationTargetException;
15-
import java.util.ArrayList;
16-
import java.util.List;
17-
18-
import org.eclipse.core.resources.IResource;
19-
import org.eclipse.core.runtime.CoreException;
20-
import org.eclipse.core.runtime.IAdaptable;
2114
import org.eclipse.debug.core.DebugPlugin;
22-
import org.eclipse.debug.core.ILaunchConfiguration;
2315
import org.eclipse.debug.core.ILaunchConfigurationType;
24-
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
25-
import org.eclipse.debug.core.Launch;
26-
import org.eclipse.debug.core.model.ISourceLocator;
27-
import org.eclipse.debug.core.model.IStackFrame;
28-
import org.eclipse.debug.internal.ui.DebugUIMessages;
29-
import org.eclipse.debug.ui.DebugUITools;
30-
import org.eclipse.jdt.core.IJavaElement;
31-
import org.eclipse.jdt.core.IMember;
32-
import org.eclipse.jdt.core.IType;
33-
import org.eclipse.jdt.core.search.IJavaSearchScope;
34-
import org.eclipse.jdt.core.search.SearchEngine;
35-
import org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut;
36-
import org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages;
37-
import org.eclipse.jdt.internal.debug.ui.launcher.MainMethodSearchEngine;
38-
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
39-
import org.eclipse.jface.operation.IRunnableContext;
16+
import org.eclipse.debug.core.ILaunchManager;
17+
import org.eclipse.jdt.debug.ui.launchConfigurations.JavaApplicationLaunchShortcut;
4018

4119
/**
4220
* Performs single click launching for local Java applications.
4321
*/
44-
public class J2SApplicationLaunchShortcut extends JavaLaunchShortcut {
45-
46-
/**
47-
* Returns the Java elements corresponding to the given objects.
48-
*
49-
* @param objects selected objects
50-
* @return corresponding Java elements
51-
*/
52-
private IJavaElement[] getJavaElements(Object[] objects) {
53-
List list= new ArrayList(objects.length);
54-
for (int i = 0; i < objects.length; i++) {
55-
Object object = objects[i];
56-
if (object instanceof IAdaptable) {
57-
IJavaElement element = (IJavaElement) ((IAdaptable)object).getAdapter(IJavaElement.class);
58-
if (element != null) {
59-
if (element instanceof IMember) {
60-
// Use the declaring type if available
61-
IJavaElement type= ((IMember)element).getDeclaringType();
62-
if (type != null) {
63-
element= type;
64-
}
65-
}
66-
list.add(element);
67-
}
68-
}
69-
}
70-
return (IJavaElement[]) list.toArray(new IJavaElement[list.size()]);
71-
}
72-
73-
/* (non-Javadoc)
74-
* @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#createConfiguration(org.eclipse.jdt.core.IType)
75-
*/
76-
protected ILaunchConfiguration createConfiguration(IType type) {
77-
ILaunchConfiguration config = null;
78-
ILaunchConfigurationWorkingCopy wc = null;
79-
try {
80-
ILaunchConfigurationType configType = getConfigurationType();
81-
wc = configType.newInstance(null, getLaunchManager().generateUniqueLaunchConfigurationNameFrom(type.getElementName()));
82-
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, type.getFullyQualifiedName());
83-
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, type.getJavaProject().getElementName());
84-
wc.setMappedResources(new IResource[] {type.getJavaProject().getProject()});
85-
config = wc.doSave();
86-
} catch (CoreException exception) {
87-
reportErorr(exception);
88-
}
89-
return config;
90-
}
22+
public class J2SApplicationLaunchShortcut extends JavaApplicationLaunchShortcut {
9123

9224
/* (non-Javadoc)
9325
* @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getConfigurationType()
9426
*/
9527
protected ILaunchConfigurationType getConfigurationType() {
96-
// return getLaunchManager().getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
28+
//return getLaunchManager().getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
9729
return getLaunchManager().getLaunchConfigurationType("net.sf.j2s.ui.launching.j2sApplication");//IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
9830
}
99-
100-
protected IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException {
101-
try {
102-
IJavaElement[] javaElements = getJavaElements(elements);
103-
MainMethodSearchEngine engine = new MainMethodSearchEngine();
104-
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(javaElements, false);
105-
return engine.searchMainMethods(context, scope, true);
106-
} catch (InvocationTargetException e) {
107-
throw (CoreException)e.getTargetException();
108-
}
109-
}
110-
111-
/* (non-Javadoc)
112-
* @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getTypeSelectionTitle()
113-
*/
114-
protected String getTypeSelectionTitle() {
115-
return LauncherMessages.JavaApplicationLaunchShortcut_0;
116-
}
117-
118-
/* (non-Javadoc)
119-
* @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getEditorEmptyMessage()
120-
*/
121-
protected String getEditorEmptyMessage() {
122-
return LauncherMessages.JavaApplicationLaunchShortcut_1;
123-
}
124-
125-
/* (non-Javadoc)
126-
* @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getSelectionEmptyMessage()
127-
*/
128-
protected String getSelectionEmptyMessage() {
129-
return LauncherMessages.JavaApplicationLaunchShortcut_2;
130-
}
13131

13232
/**
133-
* Launches a configuration for the given type
33+
* Returns the singleton launch manager.
34+
*
35+
* @return launch manager
13436
*/
135-
protected void launch(IType type, String mode) {
136-
ILaunchConfiguration config = findLaunchConfiguration(type, getConfigurationType());
137-
if (config != null) {
138-
DebugUITools.launch(config, mode);
139-
}
37+
private ILaunchManager getLaunchManager() {
38+
return DebugPlugin.getDefault().getLaunchManager();
14039
}
141-
40+
14241
}

src/net/sf/j2s/ui/launching/J2SArgumentsTab.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
2222
import org.eclipse.jdt.internal.debug.ui.JavaDebugImages;
2323
import org.eclipse.jdt.internal.debug.ui.actions.ControlAccessibleListener;
24+
import org.eclipse.jdt.internal.debug.ui.launcher.JavaWorkingDirectoryBlock;
2425
import org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages;
26+
import org.eclipse.jdt.internal.debug.ui.launcher.VMArgumentsBlock;
2527
import org.eclipse.jdt.internal.debug.ui.launcher.WorkingDirectoryBlock;
2628
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
2729
import org.eclipse.swt.SWT;
2830
import org.eclipse.swt.events.ModifyEvent;
2931
import org.eclipse.swt.events.ModifyListener;
32+
import org.eclipse.swt.events.SelectionAdapter;
3033
import org.eclipse.swt.events.SelectionEvent;
3134
import org.eclipse.swt.events.SelectionListener;
3235
import org.eclipse.swt.graphics.Font;
@@ -49,7 +52,7 @@
4952
* @since 2.0
5053
*/
5154
public class J2SArgumentsTab extends JavaLaunchTab {
52-
55+
5356
// Program arguments widgets
5457
protected Label fPrgmArgumentsLabel;
5558
protected Text fPrgmArgumentsText;
@@ -70,9 +73,9 @@ public J2SArgumentsTab() {
7073
// protected VMArgumentsBlock createVMArgsBlock() {
7174
// return new VMArgumentsBlock();
7275
// }
73-
//
76+
7477
protected WorkingDirectoryBlock createWorkingDirBlock() {
75-
return new WorkingDirectoryBlock();
78+
return new JavaWorkingDirectoryBlock();
7679
}
7780

7881
/**
@@ -115,7 +118,7 @@ public void modifyText(ModifyEvent evt) {
115118
String buttonLabel = LauncherMessages.JavaArgumentsTab_5;
116119
Button pgrmArgVariableButton = createPushButton(group, buttonLabel, null);
117120
pgrmArgVariableButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
118-
pgrmArgVariableButton.addSelectionListener(new SelectionListener() {
121+
pgrmArgVariableButton.addSelectionListener(new SelectionAdapter() {
119122
public void widgetSelected(SelectionEvent e) {
120123
StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
121124
dialog.open();
@@ -124,9 +127,6 @@ public void widgetSelected(SelectionEvent e) {
124127
fPrgmArgumentsText.insert(variable);
125128
}
126129
}
127-
public void widgetDefaultSelected(SelectionEvent e) {
128-
}
129-
130130
});
131131

132132
//fVMArgumentsBlock.createControl(comp);
@@ -245,6 +245,15 @@ public String getMessage() {
245245
public Image getImage() {
246246
return JavaDebugImages.get(JavaDebugImages.IMG_VIEW_ARGUMENTS_TAB);
247247
}
248+
249+
/**
250+
* @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#getId()
251+
*
252+
* @since 3.3
253+
*/
254+
public String getId() {
255+
return "org.eclipse.jdt.debug.ui.javaArgumentsTab"; //$NON-NLS-1$
256+
}
248257

249258
/* (non-Javadoc)
250259
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#activated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

src/net/sf/j2s/ui/launching/J2SLaunchingUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public static void launchingJ2SUnit(ILaunchConfiguration configuration, String m
142142

143143
buf.append("\t\tClazzLoader.loadClass (\"junit.textui.TestRunner\", function () {\r\n");
144144
buf.append("\t\t\tClazzLoader.loadClass (\"" + mainType + "\", function () {\r\n");
145-
IType mType = JavaModelUtil.findType(javaProject, mainType);
145+
IType mType = (IType) JavaModelUtil.findTypeContainer(javaProject, mainType);
146146
boolean isTestSuite = false;
147147
if (mType != null) {
148148
IMethod suiteMethod = JavaModelUtil.findMethod("suite", new String[0], false, mType);
@@ -174,7 +174,7 @@ public static void launchingJ2SUnit(ILaunchConfiguration configuration, String m
174174

175175
buf.append("ClazzLoader.loadClass (\"junit.textui.TestRunner\", function () {\r\n");
176176
buf.append("\tClazzLoader.loadClass (\"" + mainType + "\", function () {\r\n");
177-
IType mType = JavaModelUtil.findType(javaProject, mainType);
177+
IType mType = (IType) JavaModelUtil.findTypeContainer(javaProject, mainType);
178178
boolean isTestSuite = false;
179179
if (mType != null) {
180180
IMethod suiteMethod = JavaModelUtil.findMethod("suite", new String[0], false, mType);

0 commit comments

Comments
 (0)