JFlexXref.java revision 943
30N/A/*
30N/A * CDDL HEADER START
30N/A *
30N/A * The contents of this file are subject to the terms of the
30N/A * Common Development and Distribution License (the "License").
30N/A * You may not use this file except in compliance with the License.
30N/A *
30N/A * See LICENSE.txt included in this distribution for the specific
30N/A * language governing permissions and limitations under the License.
30N/A *
30N/A * When distributing Covered Code, include this CDDL HEADER in each
30N/A * file and include the License file at LICENSE.txt.
30N/A * If applicable, add the following below this CDDL HEADER, with the
30N/A * fields enclosed by brackets "[]" replaced with your own identifying
30N/A * information: Portions Copyright [yyyy] [name of copyright owner]
30N/A *
30N/A * CDDL HEADER END
30N/A */
30N/A
30N/A/*
1054N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
30N/A * Use is subject to license terms.
30N/A */
30N/A
58N/Apackage org.opensolaris.opengrok.analysis;
58N/A
58N/Aimport java.io.IOException;
30N/Aimport java.io.Writer;
1016N/Aimport java.util.Set;
30N/Aimport org.opensolaris.opengrok.configuration.Project;
58N/Aimport org.opensolaris.opengrok.configuration.RuntimeEnvironment;
58N/Aimport org.opensolaris.opengrok.history.Annotation;
58N/A
58N/A/**
58N/A *
667N/A * @author Lubos Kosco
58N/A */
1016N/Apublic class JFlexXref {
320N/A public Writer out;
320N/A public String urlPrefix = RuntimeEnvironment.getInstance().getUrlPrefix();
490N/A public Annotation annotation;
664N/A public Project project;
664N/A protected Definitions defs;
1026N/A
112N/A public void setDefs(Definitions defs) {
570N/A this.defs = defs;
30N/A }
30N/A
30N/A protected void appendProject() throws IOException {
58N/A if (project != null) {
30N/A out.write("&project=");
418N/A out.write(project.getDescription());
58N/A }
456N/A }
30N/A
320N/A protected String getProjectPostfix() {
320N/A return project == null ? "" : ("&project=" + project.getDescription());
30N/A }
30N/A
77N/A /**
77N/A * Write a symbol and generate links as appropriate.
77N/A *
77N/A * @param symbol the symbol to write
30N/A * @param keywords a set of keywords recognized by this analyzer (no links
30N/A * will be generated if the symbol is a keyword)
30N/A * @param line the line number on which the symbol appears
30N/A * @throws IOException if an error occurs while writing to the stream
30N/A */
77N/A protected void writeSymbol(String symbol, Set<String> keywords, int line)
77N/A throws IOException {
30N/A if (keywords.contains(symbol)) {
30N/A // This is a keyword, so we don't create a link.
58N/A out.append("<b>").append(symbol).append("</b>");
145N/A
145N/A } else if (defs != null && defs.hasDefinitionAt(symbol, line)) {
145N/A // This is the definition of the symbol.
145N/A
145N/A // 1) Create an anchor for direct links. (Perhaps, we should only
58N/A // do this when there's exactly one definition of the symbol in
77N/A // this file? Otherwise, we may end up with multiple anchors with
490N/A // the same name.)
490N/A out.append("<a class=\"d\" name=\"").append(symbol).append("\"/>");
490N/A
490N/A // 2) Create a link that searches for all references to this symbol.
490N/A out.append("<a href=\"").append(urlPrefix).append("refs=");
490N/A out.append(symbol);
490N/A appendProject();
490N/A out.append("\" class=\"d\">").append(symbol).append("</a>");
490N/A
490N/A } else if (defs == null || defs.occurrences(symbol) == 0) {
490N/A // This is a symbol that is not defined in this file.
490N/A
490N/A // Create a link that searches for all definitions of the symbol.
993N/A out.append("<a href=\"").append(urlPrefix).append("defs=");
993N/A out.append(symbol);
993N/A appendProject();
993N/A out.append("\">").append(symbol).append("</a>");
993N/A
993N/A } else if (defs.occurrences(symbol) == 1) {
993N/A // This is a reference to a symbol defined exactly once in this file.
993N/A
77N/A // Generate a direct link to the symbol definition.
77N/A out.append("<a class=\"f\" href=\"#").append(symbol).append("\">")
77N/A .append(symbol).append("</a>");
77N/A
58N/A } else {
145N/A // This is a symbol that is defined multiple times in this file.
58N/A assert defs.occurrences(symbol) > 1;
58N/A
77N/A // Don't generate a link (FIXME: this is bug #3435)
77N/A out.append("<span class=\"mf\">").append(symbol).append("</span>");
77N/A }
77N/A }
30N/A
58N/A}
58N/A