Lines 41-46
Link Here
|
41 |
|
41 |
|
42 |
package org.netbeans.api.java.source; |
42 |
package org.netbeans.api.java.source; |
43 |
|
43 |
|
|
|
44 |
import org.netbeans.spi.java.loaders.ImportProcessor; |
44 |
import java.io.File; |
45 |
import java.io.File; |
45 |
import java.io.IOException; |
46 |
import java.io.IOException; |
46 |
import java.net.MalformedURLException; |
47 |
import java.net.MalformedURLException; |
Lines 80-85
Link Here
|
80 |
import javax.swing.SwingUtilities; |
81 |
import javax.swing.SwingUtilities; |
81 |
|
82 |
|
82 |
import org.netbeans.api.annotations.common.NonNull; |
83 |
import org.netbeans.api.annotations.common.NonNull; |
|
|
84 |
import org.netbeans.api.editor.mimelookup.MimeLookup; |
85 |
import org.netbeans.api.editor.mimelookup.MimePath; |
83 |
import org.netbeans.api.java.classpath.ClassPath; |
86 |
import org.netbeans.api.java.classpath.ClassPath; |
84 |
import org.netbeans.api.java.lexer.JavaTokenId; |
87 |
import org.netbeans.api.java.lexer.JavaTokenId; |
85 |
import org.netbeans.api.java.classpath.GlobalPathRegistry; |
88 |
import org.netbeans.api.java.classpath.GlobalPathRegistry; |
Lines 112-117
Link Here
|
112 |
import org.openide.filesystems.FileUtil; |
115 |
import org.openide.filesystems.FileUtil; |
113 |
import org.openide.filesystems.URLMapper; |
116 |
import org.openide.filesystems.URLMapper; |
114 |
import org.openide.util.Exceptions; |
117 |
import org.openide.util.Exceptions; |
|
|
118 |
import org.openide.util.Lookup; |
115 |
import org.openide.util.Parameters; |
119 |
import org.openide.util.Parameters; |
116 |
import org.openide.util.Utilities; |
120 |
import org.openide.util.Utilities; |
117 |
|
121 |
|
Lines 271-297
Link Here
|
271 |
return fqn; |
275 |
return fqn; |
272 |
|
276 |
|
273 |
//not imported/visible so far by any means: |
277 |
//not imported/visible so far by any means: |
274 |
if (info instanceof WorkingCopy) { |
278 |
String topLevelLanguageMIMEType = info.getFileObject().getMIMEType(); |
275 |
CompilationUnitTree nue = (CompilationUnitTree) ((WorkingCopy)info).getChangeSet().get(cut); |
279 |
if ("text/x-java".equals(topLevelLanguageMIMEType)){ |
276 |
cut = nue != null ? nue : cut; |
280 |
if (info instanceof WorkingCopy) { |
277 |
((WorkingCopy)info).rewrite(info.getCompilationUnit(), addImports(cut, Collections.singletonList(fqn), ((WorkingCopy)info).getTreeMaker())); |
281 |
CompilationUnitTree nue = (CompilationUnitTree) ((WorkingCopy)info).getChangeSet().get(cut); |
278 |
} else { |
282 |
cut = nue != null ? nue : cut; |
279 |
SwingUtilities.invokeLater(new Runnable() { |
283 |
((WorkingCopy)info).rewrite(info.getCompilationUnit(), addImports(cut, Collections.singletonList(fqn), ((WorkingCopy)info).getTreeMaker())); |
280 |
public void run() { |
284 |
} else { |
281 |
try { |
285 |
SwingUtilities.invokeLater(new Runnable() { |
282 |
ModificationResult.runModificationTask(Collections.singletonList(info.getSnapshot().getSource()), new UserTask() { |
286 |
public void run() { |
283 |
@Override |
287 |
try { |
284 |
public void run(ResultIterator resultIterator) throws Exception { |
288 |
ModificationResult.runModificationTask(Collections.singletonList(info.getSnapshot().getSource()), new UserTask() { |
285 |
WorkingCopy copy = WorkingCopy.get(resultIterator.getParserResult()); |
289 |
@Override |
286 |
copy.toPhase(Phase.ELEMENTS_RESOLVED); |
290 |
public void run(ResultIterator resultIterator) throws Exception { |
287 |
copy.rewrite(copy.getCompilationUnit(), addImports(copy.getCompilationUnit(), Collections.singletonList(fqn), copy.getTreeMaker())); |
291 |
WorkingCopy copy = WorkingCopy.get(resultIterator.getParserResult()); |
288 |
} |
292 |
copy.toPhase(Phase.ELEMENTS_RESOLVED); |
289 |
}).commit(); |
293 |
copy.rewrite(copy.getCompilationUnit(), addImports(copy.getCompilationUnit(), Collections.singletonList(fqn), copy.getTreeMaker())); |
290 |
} catch (Exception e) { |
294 |
} |
291 |
Exceptions.printStackTrace(e); |
295 |
}).commit(); |
|
|
296 |
} catch (Exception e) { |
297 |
Exceptions.printStackTrace(e); |
298 |
} |
292 |
} |
299 |
} |
293 |
} |
300 |
}); |
294 |
}); |
301 |
} |
|
|
302 |
} else { // embedded java, look up the handler for the top level language |
303 |
Lookup lookup = MimeLookup.getLookup(MimePath.get(topLevelLanguageMIMEType)); |
304 |
Lookup.Result result = lookup.lookup(new Lookup.Template(ImportProcessor.class)); |
305 |
Collection<ImportProcessor> instances = result.allInstances(); |
306 |
|
307 |
for (ImportProcessor importsProcesor : instances) { |
308 |
importsProcesor.addImport(info.getDocument(), fqn); |
309 |
} |
310 |
|
295 |
} |
311 |
} |
296 |
TypeElement te = info.getElements().getTypeElement(fqn); |
312 |
TypeElement te = info.getElements().getTypeElement(fqn); |
297 |
if (te != null) { |
313 |
if (te != null) { |