MCPcopy Create free account
hub / github.com/beanshell/beanshell / getImportedClassImpl

Method getImportedClassImpl

src/bsh/NameSpace.java:1125–1201  ·  view source on GitHub ↗

Try to make the name into an imported class. This method takes into account only imports (class or package) found directly in this NameSpace (no parent chain).

( String name )

Source from the content-addressed store, hash-verified

1123 found directly in this NameSpace (no parent chain).
1124 */
1125 private Class getImportedClassImpl( String name )
1126 throws UtilEvalError
1127 {
1128 // Try explicitly imported class, e.g. import foo.Bar;
1129 String fullname = null;
1130 if ( importedClasses != null )
1131 fullname = importedClasses.get(name);
1132
1133 // not sure if we should really recurse here for explicitly imported
1134 // class in parent...
1135
1136 if ( fullname != null )
1137 {
1138 /*
1139 Found the full name in imported classes.
1140 */
1141 // Try to make the full imported name
1142 Class clas = classForName(fullname);
1143
1144 if ( clas != null )
1145 return clas;
1146
1147 // Handle imported inner class case
1148 // Imported full name wasn't found as an absolute class
1149 // If it is compound, try to resolve to an inner class.
1150 // (maybe this should happen in the BshClassManager?)
1151
1152 if ( Name.isCompound( fullname ) )
1153 try {
1154 clas = getNameResolver( fullname ).toClass();
1155 } catch ( ClassNotFoundException e ) { /* not a class */ }
1156 else
1157 if ( Interpreter.DEBUG ) Interpreter.debug(
1158 "imported unpackaged name not found:" +fullname);
1159
1160 // If found cache the full name in the BshClassManager
1161 if ( clas != null ) {
1162 // (should we cache info in not a class case too?)
1163 getClassManager().cacheClassInfo( fullname, clas );
1164 return clas;
1165 }
1166
1167 // It was explicitly imported, but we don't know what it is.
1168 // should we throw an error here??
1169 return null;
1170 }
1171
1172 /*
1173 Try imported packages, e.g. "import foo.bar.*;"
1174 in reverse order of import...
1175 (give later imports precedence...)
1176 */
1177 if ( importedPackages != null )
1178 for(int i=importedPackages.size()-1; i>=0; i--)
1179 {
1180 String s = importedPackages.get(i) + "." + name;
1181 Class c=classForName(s);
1182 if ( c != null )

Callers 1

getClassImplMethod · 0.95

Calls 11

classForNameMethod · 0.95
isCompoundMethod · 0.95
getNameResolverMethod · 0.95
debugMethod · 0.95
getClassManagerMethod · 0.95
hasSuperImportMethod · 0.95
getClassNameByUnqNameMethod · 0.95
cacheClassInfoMethod · 0.80
getMethod · 0.65
toClassMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected