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 javax.jmi.reflect.RefObject;
import javax.jmi.reflect.InvalidObjectException;
import org.netbeans.jmi.javamodel.Constructor;
import org.netbeans.jmi.javamodel.Parameter;
import org.netbeans.jmi.javamodel.TypeReference;

import org.openide.src.*;

class ConstructorsCollection extends ObjectsCollection {

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

    public RefObject createFeature(RefObject parent, Element elem) {
        Constructor res = members.createConstructor ((ConstructorElement) elem);
        // res.setDeclaringClass ((JavaClass) parent);
        return res;
    }
    
    public Element [] getEmptyArray () {
        return EMPTY;
    }
    
    public String getPropertyName () {
        return ElementProperties.PROP_CONSTRUCTORS;
    }
    
    public boolean isOfType (RefObject feature) {
        return feature instanceof Constructor;
    }
    
    public Element createElement (RefObject constr) {
        return (ConstructorElement) members.model.createConstructor (members.getParentClass (), (Constructor)constr).getElement ();
    }
    
    public ConstructorElement getConstructor(Type[] argtypes) {
        try {
            if (argtypes == null)
                argtypes = NO_TYPES;
            List args = members.typesToDescriptors (argtypes);
            Constructor constr = members.javaClass.getConstructor (args, false);
            return constr == null ? null : (ConstructorElement)cachedElement (constr);
        } catch (InvalidObjectException e) {
            return null;
        }
    }
    
    public ConstructorElement [] getConstructors() {
        return (ConstructorElement []) getElements ();
    }
    
    // [PENDING] this code nearly duplicates MethodsCollection.matches () ...    
    public boolean matches (Element elem, RefObject f) {
        Constructor method = (Constructor) f;
        ConstructorElement methodElem = (ConstructorElement) elem;
        
        // 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_CONSTRUCTOR;
    }
    
}
... 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.