Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc9dfa90

Browse files
author
jossonsmith
committed
Implement@j2s* auto completion for Eclipse 3.2
Implement contextmenu's "Edit converted *.js" for Eclipse 3.2
1 parent6ae03ea commitc9dfa90

File tree

5 files changed

+546
-43
lines changed

5 files changed

+546
-43
lines changed

‎META-INF/MANIFEST.MF‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,27 @@ Bundle-Activator: net.sf.j2s.ui.Java2ScriptUIPlugin
77
Bundle-Vendor:j2s.sourceforge.net
88
Bundle-Localization:plugin
99
Export-Package:net.sf.j2s.ui.resources
10-
Require-Bundle:org.eclipse.ui,
11-
org.eclipse.core.runtime,
12-
org.eclipse.ui.ide,
13-
org.eclipse.ui.views,
14-
org.eclipse.jface.text,
15-
org.eclipse.ui.workbench.texteditor,
16-
org.eclipse.ui.editors,
17-
org.eclipse.core.resources,
18-
org.eclipse.jdt.core,
19-
org.eclipse.core.filebuffers,
20-
org.eclipse.jdt.ui,
21-
org.eclipse.debug.core,
22-
org.eclipse.debug.ui,
23-
org.eclipse.jdt.debug.ui,
24-
org.eclipse.jdt.debug,
25-
org.eclipse.jdt.launching,
26-
org.eclipse.core.variables,
27-
org.eclipse.ltk.core.refactoring,
28-
org.eclipse.ltk.ui.refactoring,
29-
org.eclipse.ui.console,
30-
net.sf.j2s.core
10+
Require-Bundle:org.eclipse.ui,
11+
org.eclipse.core.runtime,
12+
org.eclipse.ui.ide,
13+
org.eclipse.ui.views,
14+
org.eclipse.jface.text,
15+
org.eclipse.ui.workbench.texteditor,
16+
org.eclipse.ui.editors,
17+
org.eclipse.core.resources,
18+
org.eclipse.jdt.core,
19+
org.eclipse.core.filebuffers,
20+
org.eclipse.jdt.ui,
21+
org.eclipse.debug.core,
22+
org.eclipse.debug.ui,
23+
org.eclipse.jdt.debug.ui,
24+
org.eclipse.jdt.debug,
25+
org.eclipse.jdt.launching,
26+
org.eclipse.core.variables,
27+
org.eclipse.ltk.core.refactoring,
28+
org.eclipse.ltk.ui.refactoring,
29+
org.eclipse.ui.console,
30+
net.sf.j2s.core,
31+
org.eclipse.core.filesystem
3132
Eclipse-AutoStart:true
3233
Main-Class:net.sf.j2s.ui.jdtenhancer.JDTCoreEnhancer

‎plugin.xml‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137
</extension>
138138
<extension
139139
point="org.eclipse.ui.popupMenus">
140-
<!--
141140
<objectContribution
142141
id="net.sf.j2s.ui.actions.openjs"
143142
objectClass="org.eclipse.jdt.core.ICompilationUnit">
@@ -148,7 +147,6 @@
148147
label="Edit Con&amp;verted *.js"
149148
menubarPath="additions"/>
150149
</objectContribution>
151-
-->
152150
<objectContribution
153151
adaptable="false"
154152
id="net.sf.j2s.ui.actions.genPropsJS"
@@ -161,7 +159,6 @@
161159
menubarPath="additions"/>
162160
</objectContribution>
163161
</extension>
164-
<!--
165162
<extension
166163
point="org.eclipse.ui.popupMenus">
167164
<viewerContribution
@@ -175,7 +172,6 @@
175172
</action>
176173
</viewerContribution>
177174
</extension>
178-
-->
179175
<!--
180176
<extension
181177
point="org.eclipse.ui.exportWizards">
@@ -187,12 +183,15 @@
187183
<description>Export Java2Script applications as standalone application</description>
188184
</wizard>
189185
</extension>
190-
<extension
191-
point="org.eclipse.jdt.ui.javadocCompletionProcessor">
192-
<javadocCompletionProcessor
193-
class="net.sf.j2s.ui.text.javadoc.JavaDocCompletionEvaluator"
194-
id="net.sf.j2s.javadocCompletionProcessor"/>
195-
</extension>
196186
-->
187+
<extension
188+
point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
189+
id="J2SCompletionProposalComputer">
190+
<javaCompletionProposalComputer
191+
class="net.sf.j2s.ui.text.javadoc.J2SProposalComputer"
192+
categoryId="org.eclipse.jdt.ui.javaNoTypeProposalCategory">
193+
<partitiontype="__java_javadoc"/>
194+
</javaCompletionProposalComputer>
195+
</extension>
197196

198197
</plugin>

‎src/net/sf/j2s/ui/actions/UnitJavaScriptUtil.java‎

Lines changed: 122 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,23 @@
1414
packagenet.sf.j2s.ui.actions;
1515

1616
importjava.io.File;
17+
importjava.io.FileNotFoundException;
18+
importjava.io.IOException;
19+
importjava.io.InputStream;
20+
importjava.util.ArrayList;
1721

1822
importnet.sf.j2s.ui.Java2ScriptUIPlugin;
1923

24+
importorg.eclipse.core.filesystem.EFS;
25+
importorg.eclipse.core.filesystem.IFileStore;
2026
importorg.eclipse.core.resources.IFile;
27+
importorg.eclipse.core.resources.IWorkspace;
28+
importorg.eclipse.core.resources.ResourcesPlugin;
29+
importorg.eclipse.core.runtime.CoreException;
2130
importorg.eclipse.core.runtime.IPath;
2231
importorg.eclipse.core.runtime.Path;
2332
importorg.eclipse.core.runtime.Platform;
33+
importorg.eclipse.core.runtime.content.IContentType;
2434
importorg.eclipse.jdt.core.ICompilationUnit;
2535
importorg.eclipse.jdt.core.IJavaElement;
2636
importorg.eclipse.jdt.core.IJavaModel;
@@ -32,8 +42,12 @@
3242
importorg.eclipse.ui.IEditorDescriptor;
3343
importorg.eclipse.ui.IEditorInput;
3444
importorg.eclipse.ui.IEditorRegistry;
45+
importorg.eclipse.ui.IWorkbench;
46+
importorg.eclipse.ui.IWorkbenchPage;
47+
importorg.eclipse.ui.IWorkbenchWindow;
3548
importorg.eclipse.ui.PartInitException;
3649
importorg.eclipse.ui.editors.text.EditorsUI;
50+
importorg.eclipse.ui.internal.editors.text.EditorsPlugin;
3751
importorg.eclipse.ui.internal.editors.text.JavaFileEditorInput;
3852
importorg.eclipse.ui.part.FileEditorInput;
3953

@@ -58,33 +72,129 @@ protected static String getEditorID() {
5872
}
5973
returneditorID;
6074
}
61-
publicstaticbooleanopenEditor(ICompilationUnitunit) {
75+
publicstaticbooleanopenEditor(ICompilationUnitunit) {
6276
StringrelativePath =getRelativeJSPath(unit);
6377
IJavaModeljavaModel =unit.getJavaModel();
6478
Filefile =newFile(javaModel.getResource()
6579
.getLocation().toOSString(),relativePath);
66-
80+
6781
IFile[]files =javaModel.getWorkspace().getRoot()
6882
.findFilesForLocation(
6983
Path.fromPortableString(relativePath));
7084
IEditorInputeditorInput =null;
7185
if (files !=null &&files.length !=0) {
7286
editorInput =newFileEditorInput(files[0]);
87+
try {
88+
Java2ScriptUIPlugin.getDefault().getWorkbench()
89+
.getActiveWorkbenchWindow().getActivePage()
90+
.openEditor(editorInput,getEditorID());
91+
returntrue;
92+
}catch (PartInitExceptione) {
93+
e.printStackTrace();
94+
}
7395
}else {
74-
//editorInput = new JavaFileEditorInput(file);
75-
// FIXME open editor for *.js
76-
returnfalse;
96+
IFileStorefileStore=EFS.getLocalFileSystem().getStore(newPath(file.getParent()));
97+
fileStore=fileStore.getChild(file.getName());
98+
if (!fileStore.fetchInfo().isDirectory() &&fileStore.fetchInfo().exists()) {
99+
IEditorInputinput=createEditorInput(fileStore);
100+
if (input ==null) {
101+
returnfalse;
102+
}
103+
IWorkbenchWindowfWindow =Java2ScriptUIPlugin.getDefault().getWorkbench()
104+
.getActiveWorkbenchWindow();
105+
StringeditorId=getEditorId(fWindow,fileStore);
106+
IWorkbenchPagepage=fWindow.getActivePage();
107+
try {
108+
page.openEditor(input,editorId);
109+
returntrue;
110+
}catch (PartInitExceptione) {
111+
EditorsPlugin.log(e.getStatus());
112+
}
113+
}
77114
}
115+
returnfalse;
116+
}
117+
/*
118+
* XXX: Requested a helper to get the correct editor descriptor
119+
*see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=110203
120+
*/
121+
privatestaticStringgetEditorId(IWorkbenchWindowfWindow,IFileStorefile) {
122+
IWorkbenchworkbench=fWindow.getWorkbench();
123+
IEditorRegistryeditorRegistry=workbench.getEditorRegistry();
124+
IEditorDescriptordescriptor=editorRegistry.getDefaultEditor(file.getName(),getContentType(file));
125+
126+
// check the OS for in-place editor (OLE on Win32)
127+
if (descriptor ==null &&editorRegistry.isSystemInPlaceEditorAvailable(file.getName()))
128+
descriptor=editorRegistry.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);
129+
130+
//// check the OS for external editor
131+
//if (descriptor == null && editorRegistry.isSystemExternalEditorAvailable(file.getName()))
132+
//descriptor= editorRegistry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
133+
134+
if (descriptor !=null)
135+
returndescriptor.getId();
136+
137+
returnEditorsUI.DEFAULT_TEXT_EDITOR_ID;
138+
}
139+
140+
privatestaticIContentTypegetContentType (IFileStorefileStore) {
141+
if (fileStore ==null)
142+
returnnull;
143+
144+
InputStreamstream=null;
78145
try {
79-
Java2ScriptUIPlugin.getDefault().getWorkbench()
80-
.getActiveWorkbenchWindow().getActivePage()
81-
.openEditor(editorInput,getEditorID());
82-
returntrue;
83-
}catch (PartInitExceptione) {
84-
e.printStackTrace();
146+
stream=fileStore.openInputStream(EFS.NONE,null);
147+
returnPlatform.getContentTypeManager().findContentTypeFor(stream,fileStore.getName());
148+
}catch (IOExceptionx) {
149+
EditorsPlugin.log(x);
150+
returnnull;
151+
}catch (CoreExceptionx) {
152+
// Do not log FileNotFoundException (no access)
153+
if (!(x.getStatus().getException()instanceofFileNotFoundException))
154+
EditorsPlugin.log(x);
155+
156+
returnnull;
157+
}finally {
158+
try {
159+
if (stream !=null)
160+
stream.close();
161+
}catch (IOExceptionx) {
162+
EditorsPlugin.log(x);
163+
}
85164
}
86-
returnfalse;
87165
}
166+
167+
privatestaticIEditorInputcreateEditorInput(IFileStorefileStore) {
168+
IFileworkspaceFile=getWorkspaceFile(fileStore);
169+
if (workspaceFile !=null)
170+
returnnewFileEditorInput(workspaceFile);
171+
returnnewJavaFileEditorInput(fileStore);
172+
}
173+
174+
privatestaticIFilegetWorkspaceFile(IFileStorefileStore) {
175+
IWorkspaceworkspace=ResourcesPlugin.getWorkspace();
176+
IFile[]files=workspace.getRoot().findFilesForLocation(newPath(fileStore.toURI().getPath()));
177+
files=filterNonExistentFiles(files);
178+
if (files ==null ||files.length ==0)
179+
returnnull;
180+
if (files.length ==1)
181+
returnfiles[0];
182+
returnnull;
183+
}
184+
185+
privatestaticIFile[]filterNonExistentFiles(IFile[]files){
186+
if (files ==null)
187+
returnnull;
188+
189+
intlength=files.length;
190+
ArrayListexistentFiles=newArrayList(length);
191+
for (inti=0;i <length;i++) {
192+
if (files[i].exists())
193+
existentFiles.add(files[i]);
194+
}
195+
return (IFile[])existentFiles.toArray(newIFile[existentFiles.size()]);
196+
}
197+
88198
protectedstaticStringgetRelativeJSPath(ICompilationUnitunit) {
89199
if (unit ==null) {
90200
returnnull;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2005, 2006 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* IBM Corporation - initial API and implementation
10+
*******************************************************************************/
11+
packagenet.sf.j2s.ui.text.javadoc;
12+
13+
importjava.util.Arrays;
14+
importjava.util.List;
15+
16+
importorg.eclipse.core.runtime.IProgressMonitor;
17+
18+
importorg.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
19+
importorg.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer;
20+
21+
22+
/**
23+
* A computer wrapper for the hippie processor.
24+
*
25+
* @since 3.2
26+
*/
27+
publicfinalclassJ2SProposalComputerimplementsIJavaCompletionProposalComputer {
28+
/** The wrapped processor. */
29+
privatefinalJ2SProposalProcessorfProcessor=newJ2SProposalProcessor();
30+
31+
/**
32+
* Default ctor to make it instantiatable via the extension mechanism.
33+
*/
34+
publicJ2SProposalComputer() {
35+
}
36+
37+
/*
38+
* @see org.eclipse.jface.text.contentassist.ICompletionProposalComputer#computeCompletionProposals(org.eclipse.jface.text.contentassist.TextContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
39+
*/
40+
publicListcomputeCompletionProposals(ContentAssistInvocationContextcontext,IProgressMonitormonitor) {
41+
returnArrays.asList(fProcessor.computeCompletionProposals(context.getViewer(),context.getInvocationOffset()));
42+
}
43+
44+
/*
45+
* @see org.eclipse.jface.text.contentassist.ICompletionProposalComputer#computeContextInformation(org.eclipse.jface.text.contentassist.TextContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
46+
*/
47+
publicListcomputeContextInformation(ContentAssistInvocationContextcontext,IProgressMonitormonitor) {
48+
returnArrays.asList(fProcessor.computeContextInformation(context.getViewer(),context.getInvocationOffset()));
49+
}
50+
51+
/*
52+
* @see org.eclipse.jface.text.contentassist.ICompletionProposalComputer#getErrorMessage()
53+
*/
54+
publicStringgetErrorMessage() {
55+
returnfProcessor.getErrorMessage();
56+
}
57+
58+
/*
59+
* @see org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer#sessionStarted()
60+
*/
61+
publicvoidsessionStarted() {
62+
}
63+
64+
/*
65+
* @see org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer#sessionEnded()
66+
*/
67+
publicvoidsessionEnded() {
68+
}
69+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp