1 19 package org.netbeans.modules.javacore.jmiimpl.javamodel; 20 21 import java.util.Arrays ; 22 import org.netbeans.api.java.classpath.ClassPath; 23 import org.netbeans.jmi.javamodel.*; 24 import org.netbeans.jmi.javamodel.JavaModelPackage; 25 import org.netbeans.mdr.handlers.ClassProxyHandler; 26 import org.netbeans.mdr.storagemodel.StorableClass; 27 import org.netbeans.mdr.storagemodel.StorableBaseObject; 28 import org.netbeans.mdr.persistence.StorageException; 29 import org.netbeans.modules.javacore.ClassIndex; 30 import org.netbeans.modules.javacore.internalapi.JavaMetamodel; 31 import java.util.List ; 32 import org.netbeans.modules.javacore.parser.NameRef; 33 34 38 public abstract class JavaClassClassImpl extends ClassProxyHandler implements JavaClassClass { 39 42 43 public JavaClassClassImpl(StorableClass s) { 44 super(s); 45 } 46 47 51 public JavaClass createJavaClass() { 52 return create(null, null, 0, null, null, null, null, null, null); 53 } 54 55 public JavaClass createJavaClass(java.lang.String name, List annotations, int modifiers, java.lang.String javadocText, JavaDoc javadoc, List features, MultipartId superClassName, List interfaceNames, List typeArguments) { 56 return create(name, annotations, modifiers, javadocText, javadoc, features, superClassName, interfaceNames, typeArguments); 57 } 58 59 protected abstract JavaClass super_createJavaClass(java.lang.String name, List annotations, int modifiers, java.lang.String javadocText, JavaDoc javadoc, List features, MultipartId superClassName, List interfaceNames, List typeArguments); 60 protected abstract JavaClass super_createJavaClass(); 61 62 private JavaClassImpl create(java.lang.String name, List annotations, int modifiers, java.lang.String javadocText, JavaDoc javadoc, List features, MultipartId superClassName, List interfaceNames, List typeArguments) { 63 boolean fail = true; 64 _lock(true); 65 try { 66 JavaClassImpl result = create(name, modifiers, (NameRef) SemiPersistentElement.typeReferenceToTypeRef(superClassName, 0), interfaceNames == null ? null : (NameRef[]) SemiPersistentElement.typeReferencesToTypeRef(interfaceNames).toArray(new NameRef[interfaceNames.size()]), false); 67 result.setNew(); 68 result.setData(annotations, javadocText, javadoc, features, superClassName, interfaceNames, typeArguments); 69 fail = false; 70 return result; 71 } finally { 72 _unlock(fail); 73 } 74 } 75 76 protected SemiPersistentElement createTransient() { 77 try { 78 StorableBaseObject s = _getDelegate(); 79 DeferredObject o = new DeferredObject(null, s.getMdrStorage(), s.getImmediatePackageId(), s.getOutermostPackageId(), s.getMetaObject(), (StorableClass) s, null, true); 80 SemiPersistentElement result = (SemiPersistentElement) _getRepository().getHandler(o); 81 return result; 82 } catch (StorageException e) { 83 throw new RuntimeException (); 84 } 85 } 86 87 public JavaClassImpl create(String name, int modifiers, NameRef superclass, NameRef[] interfaces, boolean isTransient) { 88 JavaClassImpl result; 89 if (isTransient) { 90 result = (JavaClassImpl) createTransient(); 91 boolean changes = result.disableChanges; 92 result.disableChanges = true; 93 try { 94 result.setName(name); 95 result.setModifiers(modifiers); 96 } finally { 97 result.disableChanges = changes; 98 } 99 } else { 100 result = (JavaClassImpl) super_createJavaClass(name, null, modifiers, null, null, null, null, null, null); 101 if (name != null) { 102 JavaModelPackage srcExtent = (JavaModelPackage) refOutermostPackage(); 103 ClassIndex index = ClassIndex.getIndex(srcExtent); 104 index.addClass(result, name, result.getSimpleName()); 105 } 108 } 109 result.setSuperclassRef(superclass); 110 result.setInterfaceRefs(interfaces == null ? null : Arrays.asList(interfaces)); 111 return result; 112 } 113 114 120 public JavaClass resolveClass(String name, boolean onlyResolved) { 121 if (name == null) return null; 122 _lock(false); 123 try { 124 ClassPath cp = JavaMetamodel.getManager().getClassPath(); 125 JavaClass result = ClassIndex.getClassByFqn(name,cp); 126 if (result == null && !onlyResolved) { 127 UnresolvedClassClassImpl cls = (UnresolvedClassClassImpl) JavaMetamodel.getManager().getDefaultExtent().getUnresolvedClass(); 129 result = cls.resolveUnresolved(name); 130 } 131 return result; 132 } finally { 133 _unlock(); 134 } 135 } 136 137 public org.netbeans.jmi.javamodel.Type resolve(java.lang.String name) { 138 JavaModelPackage pkg = (JavaModelPackage) refImmediatePackage(); 139 return pkg.getType().resolve(name); 140 } 141 } 142 | Popular Tags |