|
What this is
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-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.javacore.jmiimpl.javamodel; import org.netbeans.jmi.javamodel.ArrayClass; import org.netbeans.jmi.javamodel.JavaModelPackage; import org.netbeans.jmi.javamodel.ParameterizedType; import org.netbeans.jmi.javamodel.Type; import org.netbeans.jmi.javamodel.Array; import org.netbeans.jmi.javamodel.TypeClass; import org.netbeans.mdr.storagemodel.StorableClass; /** * * @author Martin Matula */ public abstract class TypeClassImpl extends SemiPersistentClass implements TypeClass { /** Creates a new instance of JavaClassClassImpl */ public TypeClassImpl(StorableClass s) { super(s); } public Type resolve(String name) { if (name == null) return null; // throw new NullPointerException(); _lock(false); try { int dimension = 0; while (name.endsWith("[]")) { // NOI18N dimension++; name = name.substring(0, name.length() - 2); } JavaModelPackage pkg = (JavaModelPackage) refImmediatePackage(); PrimitiveTypeClassImpl pt = (PrimitiveTypeClassImpl) pkg.getPrimitiveType(); Type result = pt.resolveType(name); if (result == null) { JavaClassClassImpl cls = (JavaClassClassImpl) pkg.getJavaClass(); result = cls.resolveClass(name, true); } if (result == null) { // class was not found - create UnresolvedClass UnresolvedClassClassImpl cls = (UnresolvedClassClassImpl) pkg.getUnresolvedClass(); result = cls.resolveUnresolved(name); } ArrayClassImpl ar = (ArrayClassImpl) pkg.getArray(); for (int i = 0; i < dimension; i++) { result = ar.resolveArray(result); } return result; } finally { _unlock(); } } public static Type getRealType(Type type) { if (type instanceof ParameterizedType) { return ((ParameterizedType) type).getDefinition(); } else if (type instanceof Array) { int dimCount = 1; Type elemType = ((Array) type).getType(); while (elemType instanceof Array) { elemType = ((Array) elemType).getType(); dimCount++; } if (elemType instanceof ParameterizedType) { ArrayClass proxy = ((JavaModelPackage)type.refOutermostPackage()).getArray(); type = ((ParameterizedType) elemType).getDefinition(); for (; dimCount > 0; dimCount--) { type = proxy.resolveArray(type); } } } return type; } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.