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

org.apache.xmlbeans.impl.jam.internal.elements.ClassImpl Maven / Gradle / Ivy

There is a newer version: 5.2.0_1
Show newest version
/*   Copyright 2004 The Apache Software Foundation
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.apache.xmlbeans.impl.jam.internal.elements;

import org.apache.xmlbeans.impl.jam.JAnnotation;
import org.apache.xmlbeans.impl.jam.JAnnotationValue;
import org.apache.xmlbeans.impl.jam.JClass;
import org.apache.xmlbeans.impl.jam.JComment;
import org.apache.xmlbeans.impl.jam.JConstructor;
import org.apache.xmlbeans.impl.jam.JField;
import org.apache.xmlbeans.impl.jam.JMethod;
import org.apache.xmlbeans.impl.jam.JPackage;
import org.apache.xmlbeans.impl.jam.JProperty;
import org.apache.xmlbeans.impl.jam.JSourcePosition;
import org.apache.xmlbeans.impl.jam.internal.JamClassLoaderImpl;
import org.apache.xmlbeans.impl.jam.internal.classrefs.JClassRef;
import org.apache.xmlbeans.impl.jam.internal.classrefs.JClassRefContext;
import org.apache.xmlbeans.impl.jam.internal.classrefs.QualifiedJClassRef;
import org.apache.xmlbeans.impl.jam.internal.classrefs.UnqualifiedJClassRef;
import org.apache.xmlbeans.impl.jam.mutable.MClass;
import org.apache.xmlbeans.impl.jam.mutable.MConstructor;
import org.apache.xmlbeans.impl.jam.mutable.MField;
import org.apache.xmlbeans.impl.jam.mutable.MMethod;
import org.apache.xmlbeans.impl.jam.provider.JamClassPopulator;
import org.apache.xmlbeans.impl.jam.visitor.JVisitor;
import org.apache.xmlbeans.impl.jam.visitor.MVisitor;

import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

/**
 * 

Implementation of JClass and MClass.

* * @author Patrick Calahan */ public class ClassImpl extends MemberImpl implements MClass, JClassRef, JClassRefContext { // ======================================================================== // Constants public static final int NEW = 1; public static final int UNPOPULATED = 2; public static final int POPULATING = 3; public static final int UNINITIALIZED = 4; public static final int INITIALIZING = 5; public static final int LOADED = 6; // ======================================================================== // Variables private int mState = NEW; private boolean mIsAnnotationType = false; private boolean mIsInterface = false; private boolean mIsEnum = false; private String mPackageName = null; private JClassRef mSuperClassRef = null; // classrefs to the class we extend private ArrayList mInterfaceRefs = null; // refs to interfaces we elements. private ArrayList mFields = null; private ArrayList mMethods = null; private ArrayList mConstructors = null; private ArrayList mProperties = null; private ArrayList mDeclaredProperties = null; private ArrayList mInnerClasses = null; private String[] mImports = null; private JamClassPopulator mPopulator; // FIXME implement this - we should only create one UnqualifiedJClassRef // for each unqualified name so as to avoid resolving them over and over. //private Map mName2Uqref = null; // ======================================================================== // Constructors public ClassImpl(String packageName, String simpleName, ElementContext ctx, String[] importSpecs, JamClassPopulator populator) { super(ctx); super.setSimpleName(simpleName); mPackageName = packageName.trim(); mImports = importSpecs; mPopulator = populator; setState(UNPOPULATED); } public ClassImpl(String packageName, String simpleName, ElementContext ctx, String[] importSpecs) { super(ctx); super.setSimpleName(simpleName); mPackageName = packageName.trim(); mImports = importSpecs; mPopulator = null; setState(UNINITIALIZED); } private ClassImpl(String packageName, String simpleName, String[] importSpecs, ClassImpl parent) { super(parent); super.setSimpleName(simpleName); mPackageName = packageName.trim(); mImports = importSpecs; mPopulator = null; setState(UNINITIALIZED); } // ======================================================================== // JClass implementation public JPackage getContainingPackage() { return getClassLoader().getPackage(mPackageName); } public JClass getSuperclass() { ensureLoaded(); if (mSuperClassRef == null) { return null; } else { return mSuperClassRef.getRefClass(); } } public JClass[] getInterfaces() { ensureLoaded(); if (mInterfaceRefs == null || mInterfaceRefs.size() == 0) { return new JClass[0]; } else { JClass[] out = new JClass[mInterfaceRefs.size()]; for(int i=0; i 0) ? (mPackageName + '.') : "") + mSimpleName; } // ======================================================================== // JClassRef implementation (to accommodate direct references) public JClass getRefClass() { return this; } // ======================================================================== // JClassRefContext implementation public String getPackageName() { return mPackageName; } public String[] getImportSpecs() { ensureLoaded(); if (mImports == null) return new String[0]; return mImports; } // ======================================================================== // Public methods for internal use only public void setState(int state) { mState = state; } // ======================================================================== // Public static utility methods /** * Throws an IllegalArgument exception if the given string is not a valid * class name. Useful for parameter checking in several places. */ public static void validateClassName(String className) throws IllegalArgumentException { if (className == null) { throw new IllegalArgumentException("null class name specified"); } if (!Character.isJavaIdentifierStart(className.charAt(0))) { throw new IllegalArgumentException ("Invalid first character in class name: "+className); } for(int i=1; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy