public String target()

in remoting/server/web/web.ui/src/org/netbeans/modules/jackpot30/backend/ui/UI.java [616:696]


    public String target(@QueryParam("path") String segment, @QueryParam("relative") String relative, @QueryParam("position") final long position) throws URISyntaxException, IOException, InterruptedException {
        final CompilationInfo info = ResolveService.parse(segment, relative);
        ResolvedLocation location = resolveTarget(info, position, true);
        Map<String, Object> result = new HashMap<String, Object>();

        if (location.declaration) {
            if (location.signature != null) {
                List<Map<String, String>> menu = new ArrayList<Map<String, String>>();

                menu.add(menuMap("Usages in current project", "/index/ui/usages?path=" + escapeForQuery(segment) + "&signatures=" + escapeForQuery(location.signature)));
                menu.add(menuMap("Usages in all known projects", "/index/ui/usages?signatures=" + escapeForQuery(location.signature)));

                switch (location.kind) {
                    case METHOD:
                        menu.add(menuMap("Overriders in the current project", "/index/ui/implements?path=" + escapeForQuery(segment) + "&method=" + escapeForQuery(location.signature)));
                        menu.add(menuMap("Overriders in all known projects", "/index/ui/implements?method=" + escapeForQuery(location.signature)));
                        break;
                    case CLASS: case INTERFACE: case ENUM: case ANNOTATION_TYPE:
                        menu.add(menuMap("Subtypes in the current project", "/index/ui/implements?path=" + escapeForQuery(segment) + "&type=" + escapeForQuery(location.signature)));
                        menu.add(menuMap("Subtypes in all known projects", "/index/ui/implements?type=" + escapeForQuery(location.signature)));
                        break;
                }
                result.put("menu", menu);
                result.put("signature", location.signature);
            }
        } else {
            if (location.position != (-2)) {
                result.put("position", location.position);
            } else if (location.signature != null) {
                String targetSignature = location.signature;
                String source = ResolveService.resolveSource(segment, relative, targetSignature);

                if (source != null) {
                    result.put("path", segment);
                    result.put("source", source);
                } else {
                    String singleSource = null;
                    String singleSourceSegment = null;
                    boolean multipleSources = false;
                    List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();

                    for (Entry<? extends CategoryStorage, ? extends Iterable<? extends String>> e : ResolveService.findSourcesContaining(targetSignature).entrySet()) {
                        Map<String, Object> categoryData = new HashMap<String, Object>();

                        categoryData.put("rootDisplayName", e.getKey().getDisplayName());
                        categoryData.put("rootPath", e.getKey().getId());
                        categoryData.put("files", e.getValue());

                        if (!multipleSources) {
                            Iterator<? extends String> fIt = e.getValue().iterator();

                            if (fIt.hasNext()) {
                                singleSource = fIt.next();
                                singleSourceSegment = e.getKey().getId();
                            }

                            if (fIt.hasNext())
                                multipleSources = true;
                        }

                        results.add(categoryData);
                    }

                    if (singleSource != null && !multipleSources) {
                        //TODO: will automatically jump to the single known target - correct?
                        result.put("path", singleSourceSegment);
                        result.put("source", singleSource);
                    } else if (!results.isEmpty()) {
                        result.put("targets", results);
                    }
                }
            }
        }

        if (location.signature != null) {
            result.put("signature", location.signature);
            result.put("superMethods", location.superMethodsSignatures);
        }

        return Pojson.save(result);
    }