All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fife.rsta.ac.java.MethodCompletion Maven / Gradle / Ivy

/*
 * 03/21/2010
 *
 * Copyright (C) 2010 Robert Futrell
 * robert_futrell at users.sourceforge.net
 * http://fifesoft.com/rsyntaxtextarea
 *
 * This code is licensed under the LGPL.  See the "license.txt" file included
 * with this project.
 */
package org.fife.rsta.ac.java;

import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Icon;
import javax.swing.text.JTextComponent;

import org.fife.rsta.ac.java.classreader.MethodInfo;
import org.fife.rsta.ac.java.rjc.ast.FormalParameter;
import org.fife.rsta.ac.java.rjc.ast.Method;
import org.fife.ui.autocomplete.CompletionProvider;
import org.fife.ui.autocomplete.FunctionCompletion;
import org.fife.ui.autocomplete.ParameterizedCompletion;

/**
 * A completion for a Java method.  This completion gets its information from
 * one of two sources:
 * 
 * 
    *
  • A {@link MethodInfo} instance, which is loaded by parsing a class * file. This is used when this completion represents a method found * in a compiled library.
  • *
  • A {@link Method} instance, which is created when parsing a Java * source file. This is used when the completion represents a method * found in uncompiled source, such as the source in an * RSyntaxTextArea, or in a loose file on disk.
  • *
* * @author Robert Futrell * @version 1.0 */ class MethodCompletion extends FunctionCompletion implements MemberCompletion { /** * The data source for our completion attributes. */ private Data data; /** * Creates a completion for a method discovered when parsing a Java * source file. * * @param provider * @param m Meta data about the method. * @param typeName */ public MethodCompletion(CompletionProvider provider, Method m, String typeName) { // NOTE: "void" might not be right - I think this might be constructors super(provider, m.getName(), m.getType()==null ? "void" : m.getType().toString()); setDefinedIn(typeName); this.data = new MethodData(m); int count = m.getParameterCount(); List params = new ArrayList(count); for (int i=0; i-1) { temp = temp.substring(lastDot+1); } return temp; } public Icon getIcon() { return IconFactory.get().getIcon(data); } public String getSignature() { return data.getSignature(); } public String getSummary() { String summary = data.getSummary(); // Could be just the method name // If it's the Javadoc for the method... if (summary!=null && summary.startsWith("/**")) { summary = org.fife.rsta.ac.java.Util.docCommentToHtml(summary); } return summary; } public int hashCode() { return getSignature().hashCode(); } public boolean isDeprecated() { return data.isDeprecated(); } /** * {@inheritDoc} */ public void rendererText(Graphics g, int x, int y, boolean selected) { rendererText(this, g, x, y, selected); } /** * {@inheritDoc} */ public String toString() { return getSignature(); } /** * Renders a member completion. * * @param mc * @param g * @param x * @param y * @param selected */ public static void rendererText(MemberCompletion mc, Graphics g, int x, int y, boolean selected) { String shortType = mc.getType(); int dot = shortType.lastIndexOf('.'); if (dot>-1) { shortType = shortType.substring(dot+1); } // Draw the method signature String sig = mc.getSignature(); FontMetrics fm = g.getFontMetrics(); g.drawString(sig, x, y); int newX = x + fm.stringWidth(sig); if (mc.isDeprecated()) { int midY = y + fm.getDescent() - fm.getHeight()/2; g.drawLine(x, midY, newX, midY); } x = newX; // Append the return type StringBuffer sb = new StringBuffer(" : ").append(shortType); sb.append(" - "); String s = sb.toString(); g.drawString(s, x, y); x += fm.stringWidth(s); // Append the type of the containing class of this member. Color origColor = g.getColor(); if (!selected) { g.setColor(Color.GRAY); } g.drawString(org.fife.rsta.ac.java.Util.getUnqualified(mc.getDefinedIn()), x, y); if (!selected) { g.setColor(origColor); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy