in remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java [153:211]
private static ElementDescription findElement(final FileObject file, final int pos) {
final ElementDescription[] handle = new ElementDescription[1];
if ("text/x-java".equals(FileUtil.getMIMEType(file, "text/x-java"))) {
final JavaSource js = JavaSource.forFileObject(file);
ScanDialog.runWhenScanFinished(new Runnable() {
@Override public void run() {
try {
js.runUserActionTask(new Task<CompilationController>() {
@Override public void run(CompilationController parameter) throws Exception {
parameter.toPhase(JavaSource.Phase.RESOLVED);
TreePath tp = parameter.getTreeUtilities().pathFor(pos);
Element el = parameter.getTrees().getElement(tp);
if (el != null && JavaUtils.SUPPORTED_KINDS.contains(el.getKind())) {
handle[0] = new ElementDescription(parameter, el);
}
}
}, true);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}, "Find Remote Usages");
return handle[0];
} else {
RemoteSourceDescription rsd = org.netbeans.modules.jackpot30.remoting.api.Utilities.remoteSource(file);
if (rsd != null) {
try {
URI sourceURI = new URI(rsd.idx.remote.toExternalForm() + "/ui/target?path=" + WebUtilities.escapeForQuery(rsd.idx.remoteSegment) + "&relative=" + WebUtilities.escapeForQuery(rsd.relative) + "&position=" + pos);
Map<Object, Object> targetData = Pojson.load(HashMap.class, sourceURI.toURL().openStream());
String signature = (String) targetData.get("signature");
if (signature != null) {
List<String> baseMethodsSpec = (List<String>) targetData.get("superMethods");
baseMethodsSpec = baseMethodsSpec != null ? baseMethodsSpec : Collections.<String>emptyList();
List<ElementHandle<?>> baseMethods = new ArrayList<ElementHandle<?>>(baseMethodsSpec.size());
for (String spec : baseMethodsSpec) {
baseMethods.add(signature2Handle(spec));
}
return new ElementDescription(signature2Handle(signature),
baseMethods);
}
} catch (URISyntaxException ex) {
Exceptions.printStackTrace(ex);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
return null;
}
}