Skip to content

Commit 5a2a4dd

Browse files
author
jossonsmith
committed
Fixed a bug that open *.java file in a non-java project will fail.
1 parent a10d2c8 commit 5a2a4dd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

sources/net.sf.j2s.ui/src/net/sf/j2s/ui/actions/OpenJSEditorAction.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package net.sf.j2s.ui.actions;
22

3+
import org.eclipse.core.resources.IResource;
34
import org.eclipse.jdt.core.ICompilationUnit;
5+
import org.eclipse.jdt.core.IJavaModel;
46
import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
57
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
68
import org.eclipse.jdt.ui.actions.ExtractMethodAction;
@@ -72,6 +74,14 @@ public void setActiveEditor(IAction action, IEditorPart targetEditor) {
7274
ICompilationUnit unit = SelectionConverter.getInputAsCompilationUnit(editor);
7375
boolean enabled = false;
7476
if (unit != null) {
77+
IJavaModel javaModel = unit.getJavaModel();
78+
if (javaModel == null) {
79+
return;
80+
}
81+
IResource resource = javaModel.getResource();
82+
if (resource == null){
83+
return;
84+
}
7585
enabled = UnitJavaScriptUtil.isUnitJSExisted(unit);
7686
}
7787
if (!enabled) {

0 commit comments

Comments
 (0)