Lines 54-69
Link Here
|
54 |
import javax.swing.text.Document; |
54 |
import javax.swing.text.Document; |
55 |
import javax.swing.text.JTextComponent; |
55 |
import javax.swing.text.JTextComponent; |
56 |
import org.netbeans.api.editor.EditorRegistry; |
56 |
import org.netbeans.api.editor.EditorRegistry; |
|
|
57 |
import org.netbeans.modules.cnd.utils.cache.CndFileUtils; |
57 |
import org.netbeans.modules.dlight.api.storage.DataTableMetadata.Column; |
58 |
import org.netbeans.modules.dlight.api.storage.DataTableMetadata.Column; |
58 |
import org.netbeans.modules.dlight.core.stack.api.FunctionCallWithMetric; |
59 |
import org.netbeans.modules.dlight.core.stack.api.FunctionCallWithMetric; |
59 |
import org.netbeans.modules.dlight.core.stack.api.support.FunctionMetricFormatter; |
60 |
import org.netbeans.modules.dlight.core.stack.api.support.FunctionMetricFormatter; |
60 |
import org.netbeans.modules.dlight.core.stack.dataprovider.SourceFileInfoDataProvider; |
61 |
import org.netbeans.modules.dlight.core.stack.dataprovider.SourceFileInfoDataProvider; |
61 |
import org.netbeans.modules.dlight.core.stack.spi.AnnotatedSourceSupport; |
62 |
import org.netbeans.modules.dlight.core.stack.spi.AnnotatedSourceSupport; |
62 |
import org.netbeans.modules.dlight.spi.SourceFileInfoProvider.SourceFileInfo; |
63 |
import org.netbeans.modules.dlight.spi.SourceFileInfoProvider.SourceFileInfo; |
63 |
import org.netbeans.modules.dlight.spi.SourceSupportProvider.FileObjectsToSourceMap; |
|
|
64 |
import org.netbeans.modules.dlight.util.DLightExecutorService; |
64 |
import org.netbeans.modules.dlight.util.DLightExecutorService; |
65 |
import org.openide.filesystems.FileObject; |
65 |
import org.openide.filesystems.FileObject; |
66 |
import org.openide.filesystems.FileUtil; |
|
|
67 |
import org.openide.loaders.DataObject; |
66 |
import org.openide.loaders.DataObject; |
68 |
import org.openide.util.Lookup; |
67 |
import org.openide.util.Lookup; |
69 |
|
68 |
|
Lines 92-97
Link Here
|
92 |
} |
91 |
} |
93 |
return instance; |
92 |
return instance; |
94 |
} |
93 |
} |
|
|
94 |
|
95 |
private String getCacheKey(final FileObject fileObject) { |
96 |
if (fileObject == null) { |
97 |
return null; |
98 |
} |
99 |
|
100 |
CharSequence url = CndFileUtils.fileObjectToUrl(fileObject); |
101 |
return url == null ? null : url.toString(); |
102 |
} |
103 |
|
104 |
private String getCacheKey(final CharSequence filePath) { |
105 |
FileObject fo = CndFileUtils.toFileObject(filePath); |
106 |
String result = getCacheKey(fo); |
107 |
if (result != null) { |
108 |
return result; |
109 |
} |
110 |
return filePath.toString(); |
111 |
} |
95 |
|
112 |
|
96 |
private synchronized void preProcessAnnotations(SourceFileInfoDataProvider sourceFileInfoProvider, List<Column> metrics, List<FunctionCallWithMetric> list, boolean lineAnnotations) { |
113 |
private synchronized void preProcessAnnotations(SourceFileInfoDataProvider sourceFileInfoProvider, List<Column> metrics, List<FunctionCallWithMetric> list, boolean lineAnnotations) { |
97 |
if (list == null || list.size() == 0) { |
114 |
if (list == null || list.size() == 0) { |
Lines 102-117
Link Here
|
102 |
if (sourceFileInfo != null) { |
119 |
if (sourceFileInfo != null) { |
103 |
if (sourceFileInfo.isSourceKnown()) { |
120 |
if (sourceFileInfo.isSourceKnown()) { |
104 |
String filePath = sourceFileInfo.getFileName(); |
121 |
String filePath = sourceFileInfo.getFileName(); |
105 |
if (new File(filePath).exists()) { |
122 |
String key = getCacheKey(filePath); |
106 |
filePath = FileUtil.normalizePath(filePath); |
123 |
FileAnnotationInfo fileAnnotationInfo = activeAnnotations.get(key); |
107 |
} |
|
|
108 |
FileAnnotationInfo fileAnnotationInfo = activeAnnotations.get(filePath); |
109 |
if (fileAnnotationInfo == null) { |
124 |
if (fileAnnotationInfo == null) { |
110 |
fileAnnotationInfo = new FileAnnotationInfo(); |
125 |
fileAnnotationInfo = new FileAnnotationInfo(); |
111 |
fileAnnotationInfo.setFilePath(filePath); |
126 |
fileAnnotationInfo.setFilePath(filePath); |
112 |
fileAnnotationInfo.setColumnNames(new String[metrics.size()]); |
127 |
fileAnnotationInfo.setColumnNames(new String[metrics.size()]); |
113 |
fileAnnotationInfo.setMaxColumnWidth(new int[metrics.size()]); |
128 |
fileAnnotationInfo.setMaxColumnWidth(new int[metrics.size()]); |
114 |
activeAnnotations.put(filePath, fileAnnotationInfo); |
129 |
activeAnnotations.put(key, fileAnnotationInfo); |
115 |
} |
130 |
} |
116 |
LineAnnotationInfo lineAnnotationInfo = new LineAnnotationInfo(fileAnnotationInfo); |
131 |
LineAnnotationInfo lineAnnotationInfo = new LineAnnotationInfo(fileAnnotationInfo); |
117 |
lineAnnotationInfo.setLine(sourceFileInfo.getLine()); |
132 |
lineAnnotationInfo.setLine(sourceFileInfo.getLine()); |
Lines 154-160
Link Here
|
154 |
} |
169 |
} |
155 |
|
170 |
|
156 |
public synchronized FileAnnotationInfo getFileAnnotationInfo(String filePath) { |
171 |
public synchronized FileAnnotationInfo getFileAnnotationInfo(String filePath) { |
157 |
return activeAnnotations.get(filePath); |
172 |
return activeAnnotations.get(getCacheKey(filePath)); |
158 |
} |
173 |
} |
159 |
|
174 |
|
160 |
public synchronized void updateSource(SourceFileInfoDataProvider sourceFileInfoProvider, List<Column> metrics, List<FunctionCallWithMetric> list, List<FunctionCallWithMetric> functionCalls) { |
175 |
public synchronized void updateSource(SourceFileInfoDataProvider sourceFileInfoProvider, List<Column> metrics, List<FunctionCallWithMetric> list, List<FunctionCallWithMetric> functionCalls) { |
Lines 187-215
Link Here
|
187 |
} |
202 |
} |
188 |
} |
203 |
} |
189 |
|
204 |
|
190 |
private String fileFromEditorPane(JTextComponent jEditorPane) { |
205 |
private FileObject getFileObjectFromEditorPane(JTextComponent jEditorPane) { |
191 |
String ret = null; |
206 |
if (jEditorPane != null) { |
|
|
207 |
Document doc = jEditorPane.getDocument(); |
208 |
if (doc != null) { |
209 |
Object source = doc.getProperty(Document.StreamDescriptionProperty); |
192 |
|
210 |
|
193 |
if (jEditorPane != null) { |
211 |
if (source instanceof DataObject) { |
194 |
Object source = jEditorPane.getDocument().getProperty(Document.StreamDescriptionProperty); |
212 |
FileObject fo = ((DataObject) source).getPrimaryFile(); |
195 |
if (source instanceof DataObject) { |
213 |
return fo; |
196 |
FileObject fo = ((DataObject) source).getPrimaryFile(); |
|
|
197 |
ret = FileObjectsToSourceMap.getInstance().get(fo); |
198 |
if (ret == null) { |
199 |
ret = (String)fo.getAttribute("URI"); // NOI18N |
200 |
} |
201 |
if (ret == null && FileUtil.toFile(fo) != null) { |
202 |
ret = FileUtil.toFile(fo).getPath(); |
203 |
} |
204 |
if (ret != null) { |
205 |
ret = FileUtil.normalizePath(ret); |
206 |
} |
214 |
} |
207 |
} |
215 |
} |
208 |
} |
216 |
} |
209 |
|
217 |
return null; |
210 |
return ret; |
|
|
211 |
} |
218 |
} |
212 |
|
219 |
|
213 |
private synchronized void annotateCurrentFocusedFiles() { |
220 |
private synchronized void annotateCurrentFocusedFiles() { |
214 |
// FIXUP: could there be more than one file in view? |
221 |
// FIXUP: could there be more than one file in view? |
215 |
if (activeAnnotations.size() == 0) { |
222 |
if (activeAnnotations.size() == 0) { |
Lines 220-228
Link Here
|
220 |
jEditorPane = EditorRegistry.lastFocusedComponent(); |
227 |
jEditorPane = EditorRegistry.lastFocusedComponent(); |
221 |
} |
228 |
} |
222 |
if (jEditorPane != null) { |
229 |
if (jEditorPane != null) { |
223 |
String fileURI = fileFromEditorPane(jEditorPane); |
230 |
FileObject fileObject = getFileObjectFromEditorPane(jEditorPane); |
224 |
if (fileURI != null) { |
231 |
String key = getCacheKey(fileObject); |
225 |
final FileAnnotationInfo fileAnnotationInfo = activeAnnotations.get(fileURI); |
232 |
if (key != null) { |
|
|
233 |
FileAnnotationInfo fileAnnotationInfo = activeAnnotations.get(key); |
234 |
|
226 |
if (fileAnnotationInfo != null) { |
235 |
if (fileAnnotationInfo != null) { |
227 |
// if (!fileAnnotationInfo.isAnnotated()) { |
236 |
// if (!fileAnnotationInfo.isAnnotated()) { |
228 |
fileAnnotationInfo.setEditorPane((JEditorPane) jEditorPane); |
237 |
fileAnnotationInfo.setEditorPane((JEditorPane) jEditorPane); |