@@ -395,7 +395,12 @@ static Symbol resolveSymbol(Symbol sym){
395395 }
396396 Object o = currentNS ().getMapping (sym );
397397 if (o == null )
398+ {
399+ Class ac = HostExpr .maybeArrayClass (sym );
400+ if (ac != null )
401+ return HostExpr .arrayTypeToSymbol (ac );
398402 return Symbol .intern (currentNS ().name .name , sym .name );
403+ }
399404 else if (o instanceof Class )
400405 return Symbol .intern (null , ((Class ) o ).getName ());
401406 else if (o instanceof Var )
@@ -1023,8 +1028,12 @@ public static Class maybeClass(Object form, boolean stringOk) {
10231028 {
10241029 if (Util .equals (sym ,COMPILE_STUB_SYM .get ()))
10251030 return (Class ) COMPILE_STUB_CLASS .get ();
1026- if (sym .name .indexOf ('.' ) > 0 || sym .name .charAt (0 ) == '[' )
1027- c = RT .classForNameNonLoading (sym .name );
1031+ else if (sym .name .indexOf ('.' ) > 0 || sym .name .charAt (0 ) == '[' )
1032+ {
1033+ c = maybeArrayClass (sym );
1034+ if (c == null )
1035+ c = RT .classForNameNonLoading (sym .name );
1036+ }
10281037 else
10291038 {
10301039 Object o = currentNS ().getMapping (sym );
@@ -1035,7 +1044,12 @@ else if(LOCAL_ENV.deref() != null && ((java.util.Map)LOCAL_ENV.deref()).contains
10351044 else
10361045 {
10371046 try {
1038- c = RT .classForNameNonLoading (sym .name );
1047+ if (c == null )
1048+ {
1049+ c = maybeArrayClass (sym );
1050+ if (c == null )
1051+ c = RT .classForNameNonLoading (sym .name );
1052+ }
10391053 }
10401054 catch (Exception e ){
10411055 // aargh
@@ -1097,6 +1111,60 @@ else if(sym.name.equals("booleans"))
10971111 return c ;
10981112 }
10991113
1114+ static String getArrayComponentClassDescriptor (Class c ) {
1115+ if (c .isPrimitive ())
1116+ return Type .getType (c ).getDescriptor ();
1117+
1118+ return "L" + c .getName () + ";" ;
1119+ }
1120+
1121+ // componentArrayType (maybe qualified or prim) ending in 1+ *'s, e.g. java.lang.String**
1122+ // capture group 1 = componentArrayType, group 2 = dimension *'s
1123+ final static Pattern ARRAY_TYPE_PATTERN = Pattern .compile ("([^*]+)(\\ *+)" );
1124+
1125+ public static Class maybeArrayClass (Symbol sym ) {
1126+ if (!sym .name .endsWith ("*" )) return null ;
1127+
1128+ Matcher matcher = ARRAY_TYPE_PATTERN .matcher (sym .name );
1129+
1130+ if (!matcher .matches ()) return null ;
1131+
1132+ Symbol rootSymbol = Symbol .intern (matcher .group (1 ));
1133+ String stars = matcher .group (2 );
1134+ Class componentClass = maybeClass (rootSymbol , false );
1135+
1136+ if (componentClass == null )
1137+ componentClass = primClass (rootSymbol );
1138+
1139+ if (componentClass == null ) return null ;
1140+
1141+ String componentDescriptor = getArrayComponentClassDescriptor (componentClass );
1142+ StringBuilder arrayDescriptor = new StringBuilder ();
1143+ arrayDescriptor .append (stars .replace ('*' , '[' ));
1144+ arrayDescriptor .append (componentDescriptor );
1145+ return maybeClass (arrayDescriptor .toString (), true );
1146+ }
1147+
1148+ public static Symbol arrayTypeToSymbol (Class c ) {
1149+ if (!c .isArray ()) return null ;
1150+
1151+ int dim = 1 ;
1152+
1153+ Class componentClass = c .getComponentType ();
1154+
1155+ while (componentClass .isArray ()) {
1156+ dim ++;
1157+ componentClass = componentClass .getComponentType ();
1158+ }
1159+
1160+ String componentClassName = componentClass .getName ();
1161+ StringBuilder repr = new StringBuilder (componentClassName .length () + dim );
1162+ repr .append (componentClassName );
1163+ for (int i =0 ; i <dim ; i ++)
1164+ repr .append ("*" );
1165+
1166+ return Symbol .intern (null , repr .toString ());
1167+ }
11001168
11011169 static Class tagToClass (Object tag ) {
11021170 Class c = null ;
@@ -7719,7 +7787,11 @@ else if(v.ns != currentNS() && !v.isPublic() && !allowPrivate)
77197787 }
77207788 else if (sym .name .indexOf ('.' ) > 0 || sym .name .charAt (0 ) == '[' )
77217789 {
7722- return RT .classForName (sym .name );
7790+ Class ac = HostExpr .maybeArrayClass (sym );
7791+ if (ac != null )
7792+ return ac ;
7793+ else
7794+ return RT .classForName (sym .name );
77237795 }
77247796 else if (sym .equals (NS ))
77257797 return RT .NS_VAR ;
@@ -7732,7 +7804,12 @@ else if(sym.equals(IN_NS))
77327804 Object o = n .getMapping (sym );
77337805 if (o == null )
77347806 {
7735- if (RT .booleanCast (RT .ALLOW_UNRESOLVED_VARS .deref ()))
7807+ o = HostExpr .maybeArrayClass (sym );
7808+ if (o != null )
7809+ {
7810+ return o ;
7811+ }
7812+ else if (RT .booleanCast (RT .ALLOW_UNRESOLVED_VARS .deref ()))
77367813 {
77377814 return sym ;
77387815 }
0 commit comments