alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

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-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.java.bridge;

// import java.beans.PropertyChangeEvent;
import java.util.*;

import org.openide.src.*;

import javax.jmi.reflect.RefObject;
import javax.jmi.reflect.InvalidObjectException;

import org.netbeans.jmi.javamodel.Method;
import org.netbeans.jmi.javamodel.Parameter;
import org.netbeans.jmi.javamodel.TypeReference;

class MethodsCollection extends ObjectsCollection {

    static final MethodElement[] EMPTY = new MethodElement[0];
    
    public MethodsCollection(FeaturesCollection members) {
        super (members);
    }        

    public RefObject createFeature(RefObject parent, Element elem) {
        Method res = members.createMethod ((MethodElement) elem);
        // res.setDeclaringClass ((JavaClass) parent);
        return res;
    }

    public Element [] getEmptyArray () {
        return EMPTY;
    }
    
    public String getPropertyName () {
        return ElementProperties.PROP_METHODS;
    }
    
    public boolean isOfType (RefObject feature) {
        return feature instanceof Method;
    }
    
    public Element createElement (RefObject method) {
        return (MethodElement) members.model.createMethod (members.getParentClass (), (Method)method).getElement ();
    }
 
    public MethodElement getMethod(Identifier name, Type[] argtypes) {
        try {            
            String methodName = name.getName();
            if (argtypes == null)
                argtypes = ObjectsCollection.NO_TYPES;
            List args = members.typesToDescriptors (argtypes);
            Method method = members.javaClass.getMethod (methodName, args, false);                        
            return method == null ? null : (MethodElement)cachedElement (method);
        } catch (InvalidObjectException e) {
            return null;
        }
    }
    
    public MethodElement [] getMethods() {
        return (MethodElement []) getElements ();
    }
    
    public boolean matches (Element elem, RefObject f) {
        Method method = (Method) f;
        MethodElement methodElem = (MethodElement) elem;
        
        // check name
        if (!methodElem.getName ().getName ().equals (method.getName ()))
            return false;
        
        // check return type
        Type returnType2 = methodElem.getReturn ();
        TypeReference returnType = method.getTypeName();
        if (returnType == null) {
            if (returnType2 != null)
                return false;
        } else if (!members.parentImpl.typeReferenceToType (returnType).equals (returnType2))
            return false;
        
        // check parameters
        List params = method.getParameters();
        MethodParameter [] params2 = methodElem.getParameters ();
        if (params.size () != params2.length)
            return false;
        Iterator iter = params.iterator ();
        for (int x = 0; x < params2.length; x++) {
            TypeReference typeRef = ((Parameter) iter.next ()).getTypeName ();
            Type type2 = params2 [x].getType ();
            if (typeRef == null) {
                if (type2 != null)
                    return false;
            } else if (!members.parentImpl.typeReferenceToType (typeRef).equals (type2))
                return false;
        }
        
        return true;
    }
    
    public int getPositionalValue () {
        return ObjectsCollection.POS_VAL_METHOD;
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.