|
What this is
This file is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn
Java by Example" TM.
Other links
The source code
/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.java.ui.nodes.elements;
import org.netbeans.jmi.javamodel.Method;
import org.netbeans.jmi.javamodel.CallableFeature;
import org.netbeans.jmi.javamodel.TypedElement;
import org.openide.nodes.Children;
import org.openide.nodes.Sheet;
import org.openide.nodes.Node;
import org.openide.src.ElementProperties;
import java.lang.reflect.Modifier;
import java.util.Map;
import java.util.HashMap;
/** Node for a method element.
* @see org.netbeans.jmi.javamodel.Method
* @author Petr Hamernik, Jan Pokorsky
* XXX help ids
*/
public class MethodNode extends ElementNode {
private static final Map mapAttributeName;
static {
mapAttributeName = new HashMap();
mapAttributeName.put(PROP_MODIFIERS, PROP_MODIFIERS);
mapAttributeName.put(ElementProperties.PROP_NAME, ElementProperties.PROP_NAME);
mapAttributeName.put(PROP_PARAMETERS, PROP_PARAMETERS);
mapAttributeName.put("typeName", PROP_RETURN); // NOI18N
mapAttributeName.put("exceptionNames", PROP_EXCEPTIONS); // NOI18N
}
/** Create a new method node.
* @param element method element to represent
* @param writeable true to be writable
*/
public MethodNode(Method element, boolean writeable) {
super(element, Children.LEAF, writeable, SourceOptions.PROP_METHOD_FORMAT);
setElementFormat0(getElementFormatProperty());
superSetName(element.getName());
}
protected String resolveIconBase() {
int modif = getMethod().getModifiers();
if (Modifier.isStatic(modif)) {
// static method...
if (Modifier.isPrivate(modif))
return METHOD_ST_PRIVATE;
else if (Modifier.isProtected(modif))
return METHOD_ST_PROTECTED;
else if (Modifier.isPublic(modif))
return METHOD_ST_PUBLIC;
else
return METHOD_ST_PACKAGE;
}
else {
// non-static method...
if (Modifier.isPrivate(modif))
return METHOD_PRIVATE;
else if (Modifier.isProtected(modif))
return METHOD_PROTECTED;
else if (Modifier.isPublic(modif))
return METHOD_PUBLIC;
else
return METHOD_PACKAGE;
}
}
protected ElementFormat getElementFormatProperty() {
return getSourceOptions().getMethodElementFormat();
}
/* This method resolve the appropriate hint format for the type
* of the element. It defines the short description.
*/
protected ElementFormat getHintElementFormat() {
return getSourceOptions().getMethodElementLongFormat();
}
protected Map getAttributeNameMap() {
return mapAttributeName;
}
/* Creates property set for this node */
protected Sheet createSheet () {
Sheet sheet = Sheet.createDefault();
Sheet.Set ps = sheet.get(Sheet.PROPERTIES);
ps.put(createModifiersProperty(writeable));
ps.put(createNameProperty(getMethod()));
ps.put(createTypeParametersProperty());
ps.put(createParametersProperty(false));
ps.put(createReturnProperty(writeable));
ps.put(createExceptionsProperty(writeable));
return sheet;
}
private Node.Property createParametersProperty(boolean canW) {
// this should be read-olny -> refactoring job
Node.Property p = createParametersProperty(getMethod(), canW);
p.setValue("changeImmediate" /* PropertyEnv.PROP_CHANGE_IMMEDIATE */,Boolean.FALSE); // NOI18N
return p;
}
/** Create a node property for constructor exceptions.
* @param canW false to force property to be read-only
* @return the property
*/
private Node.Property createExceptionsProperty(boolean canW) {
Node.Property p = createExceptionsProperty(getMethod(), canW);
p.setValue("changeImmediate" /* PropertyEnv.PROP_CHANGE_IMMEDIATE */,Boolean.FALSE); // NOI18N
return p;
}
Node.Property createTypeParametersProperty() {
Node.Property np = createTypeParametersProperty(PROP_TYPE_PARAMETERS, getMethod(), false);
np.setValue("changeImmediate" /* PropertyEnv.PROP_CHANGE_IMMEDIATE */, Boolean.FALSE); // NOI18N
return np;
}
/** Create a property for the method return value.
* @param canW false to force property to be read-only
* @return the property
*/
private Node.Property createReturnProperty(boolean canW) {
return createTypeProperty(PROP_RETURN, getMethod(), canW);
}
private Method getMethod() {
return (Method) this.element;
}
}
|