• R/O
  • SSH
  • HTTPS

propedit: コミット


コミットメタ情報

リビジョン163 (tree)
日時2009-05-11 00:57:14
作者chomakichi

ログメッセージ

(メッセージはありません)

変更サマリ

差分

--- trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/jdt/proposal/PropertiesCompletionProposalComputer.java (nonexistent)
+++ trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/jdt/proposal/PropertiesCompletionProposalComputer.java (revision 163)
@@ -0,0 +1,150 @@
1+package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.jdt.proposal;
2+
3+import java.io.IOException;
4+import java.util.ArrayList;
5+import java.util.Collections;
6+import java.util.Iterator;
7+import java.util.List;
8+import java.util.Properties;
9+
10+import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.PropertiesEditorPlugin;
11+
12+import org.eclipse.core.resources.IContainer;
13+import org.eclipse.core.resources.IFile;
14+import org.eclipse.core.resources.IProject;
15+import org.eclipse.core.resources.IResource;
16+import org.eclipse.core.runtime.CoreException;
17+import org.eclipse.core.runtime.ILog;
18+import org.eclipse.core.runtime.IPath;
19+import org.eclipse.core.runtime.IProgressMonitor;
20+import org.eclipse.core.runtime.IStatus;
21+import org.eclipse.core.runtime.Status;
22+import org.eclipse.jdt.core.IJavaProject;
23+import org.eclipse.jdt.core.JavaModelException;
24+import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
25+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer;
26+import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext;
27+import org.eclipse.jface.text.contentassist.CompletionProposal;
28+
29+public class PropertiesCompletionProposalComputer implements
30+ IJavaCompletionProposalComputer {
31+
32+ public List computeCompletionProposals(ContentAssistInvocationContext context,
33+ IProgressMonitor monitor) {
34+ if (!(context instanceof JavaContentAssistInvocationContext)) {
35+ return Collections.EMPTY_LIST;
36+ }
37+
38+ JavaContentAssistInvocationContext jContext = (JavaContentAssistInvocationContext)context;
39+ IJavaProject jProject = jContext.getProject();
40+ IProject project = jProject.getProject();
41+
42+ IPath outputPath = null;
43+ try {
44+ outputPath = jProject.getOutputLocation();
45+ } catch (JavaModelException e) {
46+ IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e);
47+ ILog log = PropertiesEditorPlugin.getDefault().getLog();
48+ log.log(status);
49+ }
50+
51+ IFile[] pFiles = findFileExt(project, outputPath, "properties");
52+
53+ List keyList = new ArrayList();
54+ for (int i = 0; i < pFiles.length; i++) {
55+ Properties prop = new Properties();
56+ try {
57+ prop.load(pFiles[i].getContents());
58+ } catch (IOException e) {
59+ IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e);
60+ ILog log = PropertiesEditorPlugin.getDefault().getLog();
61+ log.log(status);
62+ } catch (CoreException e) {
63+ IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e);
64+ ILog log = PropertiesEditorPlugin.getDefault().getLog();
65+ log.log(status);
66+ }
67+
68+ keyList.addAll(prop.keySet());
69+ }
70+
71+ String source = context.getDocument().get();
72+ int offset = context.getInvocationOffset();
73+ int idx = source.charAt(offset) == '\"' ? source.lastIndexOf("\"", offset - 1) : source.lastIndexOf("\"", offset);
74+ StringBuffer buf = new StringBuffer();
75+ for (int i = idx + 1; i < offset; i++) {
76+ char c = source.charAt(i);
77+ buf.append(c);
78+ }
79+
80+ String match = buf.toString();
81+
82+ List list = new ArrayList();
83+
84+ Iterator ite = keyList.iterator();
85+ while (ite.hasNext()) {
86+ String key = (String)ite.next();
87+ if (key.startsWith(match)) {
88+ list.add(new CompletionProposal(key, offset - match.length(),
89+ match.length(), key.length()));
90+ }
91+ }
92+
93+ return list;
94+ }
95+
96+ public List computeContextInformation(ContentAssistInvocationContext arg0,
97+ IProgressMonitor arg1) {
98+ // TODO Auto-generated method stub
99+ return null;
100+ }
101+
102+ public String getErrorMessage() {
103+ // TODO Auto-generated method stub
104+ return null;
105+ }
106+
107+ public void sessionEnded() {
108+ // TODO Auto-generated method stub
109+
110+ }
111+
112+ public void sessionStarted() {
113+ // TODO Auto-generated method stub
114+
115+ }
116+
117+ public IFile[] findFileExt(IContainer container, IPath excludePath, String extension) {
118+ IResource[] list = null;
119+ try {
120+ list = container.members();
121+ } catch (CoreException e) {
122+ IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e);
123+ ILog log = PropertiesEditorPlugin.getDefault().getLog();
124+ log.log(status);
125+ return new IFile[0];
126+ }
127+ if (list == null) {
128+ return new IFile[0];
129+ }
130+ List fileList = new ArrayList();
131+ for (int i = 0; i < list.length; i++) {
132+ if (list[i] instanceof IFile) {
133+ if (extension.equals(list[i].getFileExtension())) {
134+ fileList.add((IFile)list[i]);
135+ }
136+ } else if (list[i] instanceof IContainer) {
137+ if (excludePath.matchingFirstSegments(list[i].getFullPath()) == excludePath.segmentCount()) {
138+ continue;
139+ }
140+ IFile[] files = findFileExt((IContainer)list[i], excludePath, extension);
141+ for (int j = 0; j < files.length; j++) {
142+ fileList.add(files[j]);
143+ }
144+ }
145+ }
146+
147+ return (IFile[])fileList.toArray(new IFile[0]);
148+ }
149+
150+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/listener/DuplicationKeyCheckListener.java (revision 162)
+++ trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/listener/DuplicationKeyCheckListener.java (revision 163)
@@ -4,18 +4,19 @@
44
55 import org.eclipse.core.runtime.CoreException;
66 import org.eclipse.core.runtime.IProgressMonitor;
7+import org.eclipse.jface.text.IDocument;
78 import org.eclipse.ui.IFileEditorInput;
89
910 public class DuplicationKeyCheckListener implements IPropertiesDocumentListener {
1011
1112 /**
12- * @see jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.listener.IPropertiesDocumentListener#afterConvertAtLoadingDocument(java.lang.String, java.lang.Object)
13+ * @see jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.listener.IPropertiesDocumentListener#afterConvertAtLoadingDocument(org.eclipse.jface.text.IDocument, java.lang.Object)
1314 */
14- public void afterConvertAtLoadingDocument(String content, Object element) {
15+ public void afterConvertAtLoadingDocument(IDocument document, Object element) {
1516 if (element instanceof IFileEditorInput) {
1617 CheckAndMarkDuplicateKey camd = new CheckAndMarkDuplicateKey();
1718 try {
18- camd.checkAndMarkDuplicateKeyInString(content, (IFileEditorInput)element);
19+ camd.checkAndMarkDuplicateKeyInString(document.get(), (IFileEditorInput)element);
1920 } catch(CoreException e) {
2021 e.printStackTrace();
2122 }
@@ -23,27 +24,27 @@
2324 }
2425
2526 /**
26- * @see jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.listener.IPropertiesDocumentListener#afterUnicodeConvertAtSavingDocument(org.eclipse.core.runtime.IProgressMonitor, java.lang.String, java.lang.Object)
27+ * @see jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.listener.IPropertiesDocumentListener#afterUnicodeConvertAtSavingDocument(org.eclipse.core.runtime.IProgressMonitor, java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
2728 */
2829 public void afterUnicodeConvertAtSavingDocument(IProgressMonitor monitor,
29- String content, Object element) {
30+ Object element, IDocument document, boolean overwrite) {
3031 }
3132
3233 /**
33- * @see jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.listener.IPropertiesDocumentListener#beforeConvertAtLoadingDocument(java.lang.String, java.lang.Object)
34+ * @see jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.listener.IPropertiesDocumentListener#beforeConvertAtLoadingDocument(org.eclipse.jface.text.IDocument, java.lang.Object)
3435 */
35- public void beforeConvertAtLoadingDocument(String content, Object element) {
36+ public void beforeConvertAtLoadingDocument(IDocument document, Object element) {
3637 }
3738
3839 /**
39- * @see jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.listener.IPropertiesDocumentListener#beforeUnicodeConvertAtSavingDocument(org.eclipse.core.runtime.IProgressMonitor, java.lang.String, java.lang.Object)
40+ * @see jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.listener.IPropertiesDocumentListener#beforeUnicodeConvertAtSavingDocument(org.eclipse.core.runtime.IProgressMonitor, java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
4041 */
4142 public void beforeUnicodeConvertAtSavingDocument(IProgressMonitor monitor,
42- String content, Object element) {
43+ Object element, IDocument document, boolean overwrite) {
4344 if (element instanceof IFileEditorInput) {
4445 CheckAndMarkDuplicateKey camd = new CheckAndMarkDuplicateKey();
4546 try {
46- camd.checkAndMarkDuplicateKeyInString(content, (IFileEditorInput)element);
47+ camd.checkAndMarkDuplicateKeyInString(document.get(), (IFileEditorInput)element);
4748 } catch(CoreException e) {
4849 e.printStackTrace();
4950 }
--- trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/listener/IPropertiesDocumentListener.java (revision 162)
+++ trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/listener/IPropertiesDocumentListener.java (revision 163)
@@ -1,15 +1,16 @@
11 package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.listener;
22
33 import org.eclipse.core.runtime.IProgressMonitor;
4+import org.eclipse.jface.text.IDocument;
45
56 public interface IPropertiesDocumentListener {
67
7- public void beforeUnicodeConvertAtSavingDocument(IProgressMonitor monitor, String content, Object element);
8+ public void beforeUnicodeConvertAtSavingDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite);
89
9- public void afterUnicodeConvertAtSavingDocument(IProgressMonitor monitor, String content, Object element);
10+ public void afterUnicodeConvertAtSavingDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite);
1011
11- public void beforeConvertAtLoadingDocument(String content, Object element);
12+ public void beforeConvertAtLoadingDocument(IDocument document, Object element);
1213
13- public void afterConvertAtLoadingDocument(String content, Object element);
14+ public void afterConvertAtLoadingDocument(IDocument document, Object element);
1415
1516 }
--- trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/editors/PropertiesDocumentProvider.java (revision 162)
+++ trunk/PropertiesEditor/src/jp/gr/java_conf/ussiy/app/propedit/eclipse/plugin/editors/PropertiesDocumentProvider.java (revision 163)
@@ -26,6 +26,7 @@
2626 import org.eclipse.core.runtime.Platform;
2727 import org.eclipse.core.runtime.Status;
2828 import org.eclipse.jface.dialogs.ErrorDialog;
29+import org.eclipse.jface.text.Document;
2930 import org.eclipse.jface.text.IDocument;
3031 import org.eclipse.jface.text.IDocumentPartitioner;
3132 import org.eclipse.jface.text.rules.FastPartitioner;
@@ -80,7 +81,7 @@
8081 for (int i = 0; i < listeners.size(); i++) {
8182 IPropertiesDocumentListener listener = (IPropertiesDocumentListener)listeners.get(i);
8283 try {
83- listener.beforeConvertAtLoadingDocument(document.get(), element);
84+ listener.beforeConvertAtLoadingDocument(document, element);
8485 } catch(Exception e) {
8586 e.printStackTrace();
8687 }
@@ -100,7 +101,7 @@
100101 for (int i = 0; i < listeners.size(); i++) {
101102 IPropertiesDocumentListener listener = (IPropertiesDocumentListener)listeners.get(i);
102103 try {
103- listener.afterConvertAtLoadingDocument(document.get(), element);
104+ listener.afterConvertAtLoadingDocument(document, element);
104105 } catch(Exception e) {
105106 e.printStackTrace();
106107 }
@@ -131,9 +132,11 @@
131132 for (int i = 0; i < listeners.size(); i++) {
132133 IPropertiesDocumentListener listener = (IPropertiesDocumentListener)listeners.get(i);
133134 try {
134- listener.beforeUnicodeConvertAtSavingDocument(monitor, document.get(), input);
135+ listener.beforeUnicodeConvertAtSavingDocument(monitor, element, document, overwrite);
135136 } catch(Exception e) {
136- e.printStackTrace();
137+ IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e);
138+ ILog log = PropertiesEditorPlugin.getDefault().getLog();
139+ log.log(status);
137140 }
138141 }
139142
@@ -168,13 +171,16 @@
168171 ErrorDialog.openError(null, Messages.getString("eclipse.propertieseditor.convert.error"), Messages.getString("eclipse.propertieseditor.property.get.settings.error"), status); //$NON-NLS-1$ //$NON-NLS-2$
169172 }
170173 }
174+ document = new Document(uniEscStr);
171175
172176 for (int i = 0; i < listeners.size(); i++) {
173177 IPropertiesDocumentListener listener = (IPropertiesDocumentListener)listeners.get(i);
174178 try {
175- listener.afterUnicodeConvertAtSavingDocument(monitor, uniEscStr, input);
179+ listener.afterUnicodeConvertAtSavingDocument(monitor, element, document, overwrite);
176180 } catch(Exception e) {
177- e.printStackTrace();
181+ IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e);
182+ ILog log = PropertiesEditorPlugin.getDefault().getLog();
183+ log.log(status);
178184 }
179185 }
180186
--- trunk/PropertiesEditor/plugin.xml (revision 162)
+++ trunk/PropertiesEditor/plugin.xml (revision 163)
@@ -197,5 +197,24 @@
197197 schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
198198 sequence="Ctrl+I"/>
199199 </extension>
200+ <extension
201+ id="jp.gr.java_conf.ussiy.app.propedit.propertiesCompletionProposalComputer"
202+ point="org.eclipse.jdt.ui.javaCompletionProposalComputer">
203+ <javaCompletionProposalComputer
204+ activate="true"
205+ caategoryId="org.eclipse.jdt.ui.defaultProposalCategory"
206+ class="jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.jdt.proposal.PropertiesCompletionProposalComputer">
207+ <partition type="__java_string"/>
208+ </javaCompletionProposalComputer>
209+ </extension>
210+ <extension
211+ point="org.eclipse.core.contenttype.contentTypes">
212+ <content-type
213+ id="jp.gr.java_conf.ussiy.app.propedit.properties.conent.type"
214+ name="Properties File"
215+ base-type="org.eclipse.core.runtime.text"
216+ file-extensions="properties"
217+ default-charset=""/>
218+ </extension>
200219
201220 </plugin>
旧リポジトリブラウザで表示