1.1 --- a/src/share/classes/com/sun/tools/javah/LLNI.java Wed Sep 23 18:48:13 2009 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javah/LLNI.java Wed Sep 23 19:15:04 2009 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -26,49 +26,65 @@ 1.11 1.12 package com.sun.tools.javah; 1.13 1.14 -import java.io.File; 1.15 import java.io.OutputStream; 1.16 import java.io.PrintWriter; 1.17 -import java.util.Hashtable; 1.18 -import com.sun.javadoc.*; 1.19 +import java.util.ArrayList; 1.20 +import java.util.HashSet; 1.21 +import java.util.List; 1.22 1.23 - /* 1.24 - * @author Sucheta Dambalkar(Revised) 1.25 - */ 1.26 +import java.util.Set; 1.27 +import javax.lang.model.element.Element; 1.28 +import javax.lang.model.element.ExecutableElement; 1.29 +import javax.lang.model.element.Modifier; 1.30 +import javax.lang.model.element.Name; 1.31 +import javax.lang.model.element.TypeElement; 1.32 +import javax.lang.model.element.VariableElement; 1.33 +import javax.lang.model.type.ArrayType; 1.34 +import javax.lang.model.type.PrimitiveType; 1.35 +import javax.lang.model.type.TypeKind; 1.36 +import javax.lang.model.type.TypeMirror; 1.37 +import javax.lang.model.type.TypeVisitor; 1.38 +import javax.lang.model.util.ElementFilter; 1.39 +import javax.lang.model.util.SimpleTypeVisitor6; 1.40 + 1.41 +/* 1.42 + * <p><b>This is NOT part of any API supported by Sun Microsystems. 1.43 + * If you write code that depends on this, you do so at your own 1.44 + * risk. This code and its internal interfaces are subject to change 1.45 + * or deletion without notice.</b></p> 1.46 + * 1.47 + * @author Sucheta Dambalkar(Revised) 1.48 + */ 1.49 public class LLNI extends Gen { 1.50 1.51 - protected final char pathChar = File.separatorChar; 1.52 protected final char innerDelim = '$'; /* For inner classes */ 1.53 - protected Hashtable<Object, Object> doneHandleTypes; 1.54 - MemberDoc []fields; 1.55 - MemberDoc [] methods; 1.56 + protected Set<String> doneHandleTypes; 1.57 + List<VariableElement> fields; 1.58 + List<ExecutableElement> methods; 1.59 private boolean doubleAlign; 1.60 private int padFieldNum = 0; 1.61 1.62 - 1.63 - LLNI(boolean doubleAlign, RootDoc root) { 1.64 - super(root); 1.65 + LLNI(boolean doubleAlign, Util util) { 1.66 + super(util); 1.67 this.doubleAlign = doubleAlign; 1.68 } 1.69 1.70 - 1.71 protected String getIncludes() { 1.72 return ""; 1.73 } 1.74 1.75 - protected void write(OutputStream o, ClassDoc clazz) 1.76 - throws ClassNotFoundException { 1.77 - String cname = mangleClassName(clazz.qualifiedName()); 1.78 + protected void write(OutputStream o, TypeElement clazz) throws Util.Exit { 1.79 + String cname = mangleClassName(clazz.getQualifiedName().toString()); 1.80 PrintWriter pw = wrapWriter(o); 1.81 - fields = clazz.fields(); 1.82 - methods = clazz.methods(); 1.83 + fields = ElementFilter.fieldsIn(clazz.getEnclosedElements()); 1.84 + methods = ElementFilter.methodsIn(clazz.getEnclosedElements()); 1.85 generateDeclsForClass(pw, clazz, cname); 1.86 + // FIXME check if errors occurred on the PrintWriter and throw exception if so 1.87 } 1.88 1.89 protected void generateDeclsForClass(PrintWriter pw, 1.90 - ClassDoc clazz, String cname) 1.91 - throws ClassNotFoundException { 1.92 - doneHandleTypes = new Hashtable<Object, Object>(); 1.93 + TypeElement clazz, String cname) throws Util.Exit { 1.94 + doneHandleTypes = new HashSet<String>(); 1.95 /* The following handle types are predefined in "typedefs.h". Suppress 1.96 inclusion in the output by generating them "into the blue" here. */ 1.97 genHandleType(null, "java.lang.Class"); 1.98 @@ -79,7 +95,7 @@ 1.99 genHandleType(null, "java.lang.ThreadGroup"); 1.100 genHandleType(null, "java.lang.Throwable"); 1.101 1.102 - pw.println("/* LLNI Header for class " + clazz.qualifiedName() + " */" + lineSep); 1.103 + pw.println("/* LLNI Header for class " + clazz.getQualifiedName() + " */" + lineSep); 1.104 pw.println("#ifndef _Included_" + cname); 1.105 pw.println("#define _Included_" + cname); 1.106 pw.println("#include \"typedefs.h\""); 1.107 @@ -94,8 +110,8 @@ 1.108 1.109 protected void genHandleType(PrintWriter pw, String clazzname) { 1.110 String cname = mangleClassName(clazzname); 1.111 - if (!doneHandleTypes.containsKey(cname)) { 1.112 - doneHandleTypes.put(cname, cname); 1.113 + if (!doneHandleTypes.contains(cname)) { 1.114 + doneHandleTypes.add(cname); 1.115 if (pw != null) { 1.116 pw.println("#ifndef DEFINED_" + cname); 1.117 pw.println(" #define DEFINED_" + cname); 1.118 @@ -107,31 +123,29 @@ 1.119 1.120 protected String mangleClassName(String s) { 1.121 return s.replace('.', '_') 1.122 - .replace(pathChar, '_') 1.123 + .replace('/', '_') 1.124 .replace(innerDelim, '_'); 1.125 } 1.126 1.127 - protected void forwardDecls(PrintWriter pw, ClassDoc clazz) 1.128 - throws ClassNotFoundException { 1.129 - ClassDoc clazzfield = null; 1.130 + protected void forwardDecls(PrintWriter pw, TypeElement clazz) { 1.131 + TypeElement object = elems.getTypeElement("java.lang.Object"); 1.132 + if (clazz.equals(object)) 1.133 + return; 1.134 1.135 - if (clazz.qualifiedName().equals("java.lang.Object")) 1.136 - return; 1.137 - genHandleType(pw, clazz.qualifiedName()); 1.138 - ClassDoc superClass = clazz.superclass(); 1.139 + genHandleType(pw, clazz.getQualifiedName().toString()); 1.140 + TypeElement superClass = (TypeElement) (types.asElement(clazz.getSuperclass())); 1.141 1.142 - if(superClass != null){ 1.143 - String superClassName = superClass.qualifiedName(); 1.144 + if (superClass != null) { 1.145 + String superClassName = superClass.getQualifiedName().toString(); 1.146 forwardDecls(pw, superClass); 1.147 } 1.148 1.149 - for (int i = 0; i < fields.length; i++) { 1.150 - FieldDoc field = (FieldDoc)fields[i]; 1.151 + for (VariableElement field: fields) { 1.152 1.153 - if (!field.isStatic()) { 1.154 - Type t = field.type(); 1.155 - String tname = t.qualifiedTypeName(); 1.156 - TypeSignature newTypeSig = new TypeSignature(root); 1.157 + if (!field.getModifiers().contains(Modifier.STATIC)) { 1.158 + TypeMirror t = types.erasure(field.asType()); 1.159 + TypeSignature newTypeSig = new TypeSignature(elems); 1.160 + String tname = newTypeSig.qualifiedTypeName(t); 1.161 String sig = newTypeSig.getTypeSignature(tname); 1.162 1.163 if (sig.charAt(0) != '[') 1.164 @@ -139,13 +153,12 @@ 1.165 } 1.166 } 1.167 1.168 - for (int i = 0; i < methods.length; i++) { 1.169 - MethodDoc method = (MethodDoc)methods[i]; 1.170 + for (ExecutableElement method: methods) { 1.171 1.172 - if (method.isNative()) { 1.173 - Type retType = method.returnType(); 1.174 - String typesig = method.signature(); 1.175 - TypeSignature newTypeSig = new TypeSignature(root); 1.176 + if (method.getModifiers().contains(Modifier.NATIVE)) { 1.177 + TypeMirror retType = types.erasure(method.getReturnType()); 1.178 + String typesig = signature(method); 1.179 + TypeSignature newTypeSig = new TypeSignature(elems); 1.180 String sig = newTypeSig.getTypeSignature(typesig, retType); 1.181 1.182 if (sig.charAt(0) != '[') 1.183 @@ -173,10 +186,9 @@ 1.184 } 1.185 1.186 protected void structSectionForClass(PrintWriter pw, 1.187 - ClassDoc jclazz, String cname) 1.188 - throws ClassNotFoundException { 1.189 + TypeElement jclazz, String cname) { 1.190 1.191 - String jname = jclazz.qualifiedName(); 1.192 + String jname = jclazz.getQualifiedName().toString(); 1.193 1.194 if (cname.equals("java_lang_Object")) { 1.195 pw.println("/* struct java_lang_Object is defined in typedefs.h. */"); 1.196 @@ -207,8 +219,8 @@ 1.197 public boolean bottomMost; 1.198 public boolean printedOne = false; 1.199 1.200 - FieldDefsRes(ClassDoc clazz, FieldDefsRes parent, boolean bottomMost) { 1.201 - this.className = clazz.qualifiedName(); 1.202 + FieldDefsRes(TypeElement clazz, FieldDefsRes parent, boolean bottomMost) { 1.203 + this.className = clazz.getQualifiedName().toString(); 1.204 this.parent = parent; 1.205 this.bottomMost = bottomMost; 1.206 int byteSize = 0; 1.207 @@ -218,9 +230,8 @@ 1.208 } 1.209 1.210 /* Returns "true" iff added a field. */ 1.211 - private boolean doField(FieldDefsRes res, FieldDoc field, 1.212 - String cname, boolean padWord) 1.213 - throws ClassNotFoundException { 1.214 + private boolean doField(FieldDefsRes res, VariableElement field, 1.215 + String cname, boolean padWord) { 1.216 1.217 String fieldDef = addStructMember(field, cname, padWord); 1.218 if (fieldDef != null) { 1.219 @@ -242,16 +253,14 @@ 1.220 return false; 1.221 } 1.222 1.223 - private int doTwoWordFields(FieldDefsRes res, ClassDoc clazz, 1.224 - int offset, String cname, boolean padWord) 1.225 - throws ClassNotFoundException { 1.226 + private int doTwoWordFields(FieldDefsRes res, TypeElement clazz, 1.227 + int offset, String cname, boolean padWord) { 1.228 boolean first = true; 1.229 - FieldDoc[] fields = clazz.fields(); 1.230 + List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements()); 1.231 1.232 - for (int i = 0; i <fields.length; i++) { 1.233 - FieldDoc field = fields[i]; 1.234 - String tc =field.type().typeName(); 1.235 - boolean twoWords = (tc.equals("long") || tc.equals("double")); 1.236 + for (VariableElement field: fields) { 1.237 + TypeKind tk = field.asType().getKind(); 1.238 + boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE); 1.239 if (twoWords && doField(res, field, cname, first && padWord)) { 1.240 offset += 8; first = false; 1.241 } 1.242 @@ -259,22 +268,21 @@ 1.243 return offset; 1.244 } 1.245 1.246 - protected String fieldDefs(ClassDoc clazz, String cname) 1.247 - throws ClassNotFoundException { 1.248 + String fieldDefs(TypeElement clazz, String cname) { 1.249 FieldDefsRes res = fieldDefs(clazz, cname, true); 1.250 return res.s; 1.251 } 1.252 1.253 - protected FieldDefsRes fieldDefs(ClassDoc clazz, String cname, 1.254 - boolean bottomMost) 1.255 - throws ClassNotFoundException { 1.256 + FieldDefsRes fieldDefs(TypeElement clazz, String cname, 1.257 + boolean bottomMost){ 1.258 FieldDefsRes res; 1.259 int offset; 1.260 boolean didTwoWordFields = false; 1.261 - ClassDoc superclazz = clazz.superclass(); 1.262 + 1.263 + TypeElement superclazz = (TypeElement) types.asElement(clazz.getSuperclass()); 1.264 1.265 if (superclazz != null) { 1.266 - String supername = superclazz.qualifiedName(); 1.267 + String supername = superclazz.getQualifiedName().toString(); 1.268 res = new FieldDefsRes(clazz, 1.269 fieldDefs(superclazz, cname, false), 1.270 bottomMost); 1.271 @@ -284,18 +292,17 @@ 1.272 offset = 0; 1.273 } 1.274 1.275 - FieldDoc[] fields = clazz.fields(); 1.276 + List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements()); 1.277 1.278 - for (int i = 0; i < fields.length; i++) { 1.279 - FieldDoc field = fields[i]; 1.280 + for (VariableElement field: fields) { 1.281 1.282 if (doubleAlign && !didTwoWordFields && (offset % 8) == 0) { 1.283 offset = doTwoWordFields(res, clazz, offset, cname, false); 1.284 didTwoWordFields = true; 1.285 } 1.286 1.287 - String tc = field.type().typeName(); 1.288 - boolean twoWords = (tc.equals("long") ||tc.equals("double")); 1.289 + TypeKind tk = field.asType().getKind(); 1.290 + boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE); 1.291 1.292 if (!doubleAlign || !twoWords) { 1.293 if (doField(res, field, cname, false)) offset += 4; 1.294 @@ -313,19 +320,19 @@ 1.295 } 1.296 1.297 /* OVERRIDE: This method handles instance fields */ 1.298 - protected String addStructMember(FieldDoc member, String cname, 1.299 - boolean padWord) 1.300 - throws ClassNotFoundException { 1.301 + protected String addStructMember(VariableElement member, String cname, 1.302 + boolean padWord) { 1.303 String res = null; 1.304 1.305 - if (member.isStatic()) { 1.306 + if (member.getModifiers().contains(Modifier.STATIC)) { 1.307 res = addStaticStructMember(member, cname); 1.308 // if (res == null) /* JNI didn't handle it, print comment. */ 1.309 // res = " /* Inaccessible static: " + member + " */" + lineSep; 1.310 } else { 1.311 + TypeMirror mt = types.erasure(member.asType()); 1.312 if (padWord) res = " java_int padWord" + padFieldNum++ + ";" + lineSep; 1.313 - res = " " + llniType(member.type(), false, false) + " " + llniFieldName(member); 1.314 - if (isLongOrDouble(member.type())) res = res + "[2]"; 1.315 + res = " " + llniType(mt, false, false) + " " + llniFieldName(member); 1.316 + if (isLongOrDouble(mt)) res = res + "[2]"; 1.317 res = res + ";" + lineSep; 1.318 } 1.319 return res; 1.320 @@ -337,36 +344,42 @@ 1.321 /* 1.322 * This method only handles static final fields. 1.323 */ 1.324 - protected String addStaticStructMember(FieldDoc field, String cname) 1.325 - throws ClassNotFoundException { 1.326 + protected String addStaticStructMember(VariableElement field, String cname) { 1.327 String res = null; 1.328 Object exp = null; 1.329 1.330 - if (!field.isStatic()) 1.331 + if (!field.getModifiers().contains(Modifier.STATIC)) 1.332 return res; 1.333 - if (!field.isFinal()) 1.334 + if (!field.getModifiers().contains(Modifier.FINAL)) 1.335 return res; 1.336 1.337 - exp = field.constantValue(); 1.338 + exp = field.getConstantValue(); 1.339 1.340 if (exp != null) { 1.341 /* Constant. */ 1.342 1.343 - String cn = cname + "_" + field.name(); 1.344 + String cn = cname + "_" + field.getSimpleName(); 1.345 String suffix = null; 1.346 long val = 0; 1.347 /* Can only handle int, long, float, and double fields. */ 1.348 - if (exp instanceof Integer) { 1.349 + if (exp instanceof Byte 1.350 + || exp instanceof Short 1.351 + || exp instanceof Integer) { 1.352 suffix = "L"; 1.353 - val = ((Integer)exp).intValue(); 1.354 + val = ((Number)exp).intValue(); 1.355 } 1.356 - if (exp instanceof Long) { 1.357 + else if (exp instanceof Long) { 1.358 // Visual C++ supports the i64 suffix, not LL 1.359 suffix = isWindows ? "i64" : "LL"; 1.360 val = ((Long)exp).longValue(); 1.361 } 1.362 - if (exp instanceof Float) suffix = "f"; 1.363 - if (exp instanceof Double) suffix = ""; 1.364 + else if (exp instanceof Float) suffix = "f"; 1.365 + else if (exp instanceof Double) suffix = ""; 1.366 + else if (exp instanceof Character) { 1.367 + suffix = "L"; 1.368 + Character ch = (Character) exp; 1.369 + val = ((int) ch) & 0xffff; 1.370 + } 1.371 if (suffix != null) { 1.372 // Some compilers will generate a spurious warning 1.373 // for the integer constants for Integer.MIN_VALUE 1.374 @@ -376,9 +389,12 @@ 1.375 res = " #undef " + cn + lineSep 1.376 + " #define " + cn 1.377 + " (" + (val + 1) + suffix + "-1)" + lineSep; 1.378 + } else if (suffix.equals("L") || suffix.endsWith("LL")) { 1.379 + res = " #undef " + cn + lineSep 1.380 + + " #define " + cn + " " + val + suffix + lineSep; 1.381 } else { 1.382 res = " #undef " + cn + lineSep 1.383 - + " #define " + cn + " "+ exp.toString() + suffix + lineSep; 1.384 + + " #define " + cn + " " + exp + suffix + lineSep; 1.385 } 1.386 } 1.387 } 1.388 @@ -386,8 +402,8 @@ 1.389 } 1.390 1.391 protected void methodSectionForClass(PrintWriter pw, 1.392 - ClassDoc clazz, String cname) 1.393 - throws ClassNotFoundException { 1.394 + TypeElement clazz, String cname) 1.395 + throws Util.Exit { 1.396 String methods = methodDecls(clazz, cname); 1.397 1.398 if (methods.length() != 0) { 1.399 @@ -402,81 +418,77 @@ 1.400 } 1.401 } 1.402 1.403 - protected String methodDecls(ClassDoc clazz, String cname) 1.404 - throws ClassNotFoundException { 1.405 + protected String methodDecls(TypeElement clazz, String cname) throws Util.Exit { 1.406 1.407 String res = ""; 1.408 - for (int i = 0; i < methods.length; i++) { 1.409 - MethodDoc method = (MethodDoc)methods[i]; 1.410 - if (method.isNative()) 1.411 + for (ExecutableElement method: methods) { 1.412 + if (method.getModifiers().contains(Modifier.NATIVE)) 1.413 res = res + methodDecl(method, clazz, cname); 1.414 } 1.415 return res; 1.416 } 1.417 1.418 - protected String methodDecl(MethodDoc method, 1.419 - ClassDoc clazz, String cname) 1.420 - throws ClassNotFoundException { 1.421 + protected String methodDecl(ExecutableElement method, 1.422 + TypeElement clazz, String cname) 1.423 + throws Util.Exit { 1.424 String res = null; 1.425 1.426 - Type retType = method.returnType(); 1.427 - String typesig = method.signature(); 1.428 - TypeSignature newTypeSig = new TypeSignature(root); 1.429 + TypeMirror retType = types.erasure(method.getReturnType()); 1.430 + String typesig = signature(method); 1.431 + TypeSignature newTypeSig = new TypeSignature(elems); 1.432 String sig = newTypeSig.getTypeSignature(typesig, retType); 1.433 boolean longName = needLongName(method, clazz); 1.434 1.435 if (sig.charAt(0) != '(') 1.436 - Util.error("invalid.method.signature", sig); 1.437 + util.error("invalid.method.signature", sig); 1.438 1.439 1.440 res = "JNIEXPORT " + jniType(retType) + " JNICALL" + lineSep + jniMethodName(method, cname, longName) 1.441 + "(JNIEnv *, " + cRcvrDecl(method, cname); 1.442 - Parameter[] params = method.parameters(); 1.443 - Type argTypes[] = new Type[params.length]; 1.444 - for(int p = 0; p < params.length; p++){ 1.445 - argTypes[p] = params[p].type(); 1.446 + List<? extends VariableElement> params = method.getParameters(); 1.447 + List<TypeMirror> argTypes = new ArrayList<TypeMirror>(); 1.448 + for (VariableElement p: params){ 1.449 + argTypes.add(types.erasure(p.asType())); 1.450 } 1.451 1.452 /* It would have been nice to include the argument names in the 1.453 declaration, but there seems to be a bug in the "BinaryField" 1.454 class, causing the getArguments() method to return "null" for 1.455 most (non-constructor) methods. */ 1.456 - for (int i = 0; i < argTypes.length; i++) 1.457 - res = res + ", " + jniType(argTypes[i]); 1.458 + for (TypeMirror argType: argTypes) 1.459 + res = res + ", " + jniType(argType); 1.460 res = res + ");" + lineSep; 1.461 return res; 1.462 } 1.463 1.464 - protected final boolean needLongName(MethodDoc method, 1.465 - ClassDoc clazz) 1.466 - throws ClassNotFoundException { 1.467 - String methodName = method.name(); 1.468 - for (int i = 0; i < methods.length; i++) { 1.469 - MethodDoc memberMethod = (MethodDoc) methods[i]; 1.470 + protected final boolean needLongName(ExecutableElement method, 1.471 + TypeElement clazz) { 1.472 + Name methodName = method.getSimpleName(); 1.473 + for (ExecutableElement memberMethod: methods) { 1.474 if ((memberMethod != method) && 1.475 - memberMethod.isNative() && (methodName == memberMethod.name())) 1.476 + memberMethod.getModifiers().contains(Modifier.NATIVE) && 1.477 + (methodName.equals(memberMethod.getSimpleName()))) 1.478 return true; 1.479 } 1.480 return false; 1.481 } 1.482 1.483 - protected final String jniMethodName(MethodDoc method, String cname, 1.484 + protected final String jniMethodName(ExecutableElement method, String cname, 1.485 boolean longName) { 1.486 - String res = "Java_" + cname + "_" + method.name(); 1.487 + String res = "Java_" + cname + "_" + method.getSimpleName(); 1.488 1.489 if (longName) { 1.490 - Type mType = method.returnType(); 1.491 - Parameter[] params = method.parameters(); 1.492 - Type argTypes[] = new Type[params.length]; 1.493 - for(int p = 0; p < params.length; p++){ 1.494 - argTypes[p] = params[p].type(); 1.495 + TypeMirror mType = types.erasure(method.getReturnType()); 1.496 + List<? extends VariableElement> params = method.getParameters(); 1.497 + List<TypeMirror> argTypes = new ArrayList<TypeMirror>(); 1.498 + for (VariableElement param: params) { 1.499 + argTypes.add(types.erasure(param.asType())); 1.500 } 1.501 1.502 res = res + "__"; 1.503 - for (int i = 0; i < argTypes.length; i++){ 1.504 - Type t = argTypes[i]; 1.505 - String tname = t.typeName(); 1.506 - TypeSignature newTypeSig = new TypeSignature(root); 1.507 + for (TypeMirror t: argTypes) { 1.508 + String tname = t.toString(); 1.509 + TypeSignature newTypeSig = new TypeSignature(elems); 1.510 String sig = newTypeSig.getTypeSignature(tname); 1.511 res = res + nameToIdentifier(sig); 1.512 } 1.513 @@ -484,88 +496,143 @@ 1.514 return res; 1.515 } 1.516 1.517 - protected final String jniType(Type t) { 1.518 - String elmT =t.typeName(); 1.519 - if (t.dimension().indexOf("[]") != -1) { 1.520 - if(elmT.equals("boolean"))return "jbooleanArray"; 1.521 - else if(elmT.equals("byte"))return "jbyteArray"; 1.522 - else if(elmT.equals("char"))return "jcharArray"; 1.523 - else if(elmT.equals("short"))return "jshortArray"; 1.524 - else if(elmT.equals("int"))return "jintArray"; 1.525 - else if(elmT.equals("long"))return "jlongArray"; 1.526 - else if(elmT.equals("float"))return "jfloatArray"; 1.527 - else if(elmT.equals("double"))return "jdoubleArray"; 1.528 - else if((t.dimension().indexOf("[][]") != -1) || (t.asClassDoc() != null)) return "jobjectArray"; 1.529 - } else { 1.530 - if(elmT.equals("void"))return "void"; 1.531 - else if(elmT.equals("boolean"))return "jboolean"; 1.532 - else if(elmT.equals("byte"))return "jbyte"; 1.533 - else if(elmT.equals("char"))return "jchar"; 1.534 - else if(elmT.equals("short"))return "jshort"; 1.535 - else if(elmT.equals("int"))return "jint"; 1.536 - else if(elmT.equals("long"))return "jlong"; 1.537 - else if(elmT.equals("float"))return "jfloat"; 1.538 - else if(elmT.equals("double"))return "jdouble"; 1.539 - else if (t.asClassDoc() != null) { 1.540 - if (elmT.equals("String")) 1.541 + // copied from JNI.java 1.542 + protected final String jniType(TypeMirror t) throws Util.Exit { 1.543 + TypeElement throwable = elems.getTypeElement("java.lang.Throwable"); 1.544 + TypeElement jClass = elems.getTypeElement("java.lang.Class"); 1.545 + TypeElement jString = elems.getTypeElement("java.lang.String"); 1.546 + Element tclassDoc = types.asElement(t); 1.547 + 1.548 + switch (t.getKind()) { 1.549 + case ARRAY: { 1.550 + TypeMirror ct = ((ArrayType) t).getComponentType(); 1.551 + switch (ct.getKind()) { 1.552 + case BOOLEAN: return "jbooleanArray"; 1.553 + case BYTE: return "jbyteArray"; 1.554 + case CHAR: return "jcharArray"; 1.555 + case SHORT: return "jshortArray"; 1.556 + case INT: return "jintArray"; 1.557 + case LONG: return "jlongArray"; 1.558 + case FLOAT: return "jfloatArray"; 1.559 + case DOUBLE: return "jdoubleArray"; 1.560 + case ARRAY: 1.561 + case DECLARED: return "jobjectArray"; 1.562 + default: throw new Error(ct.toString()); 1.563 + } 1.564 + } 1.565 + 1.566 + case VOID: return "void"; 1.567 + case BOOLEAN: return "jboolean"; 1.568 + case BYTE: return "jbyte"; 1.569 + case CHAR: return "jchar"; 1.570 + case SHORT: return "jshort"; 1.571 + case INT: return "jint"; 1.572 + case LONG: return "jlong"; 1.573 + case FLOAT: return "jfloat"; 1.574 + case DOUBLE: return "jdouble"; 1.575 + 1.576 + case DECLARED: { 1.577 + if (tclassDoc.equals(jString)) 1.578 return "jstring"; 1.579 - else if (t.asClassDoc().subclassOf(root.classNamed("java.lang.Class"))) 1.580 + else if (types.isAssignable(t, throwable.asType())) 1.581 + return "jthrowable"; 1.582 + else if (types.isAssignable(t, jClass.asType())) 1.583 return "jclass"; 1.584 else 1.585 return "jobject"; 1.586 } 1.587 } 1.588 - Util.bug("jni.unknown.type"); 1.589 + 1.590 + util.bug("jni.unknown.type"); 1.591 return null; /* dead code. */ 1.592 } 1.593 1.594 - protected String llniType(Type t, boolean handleize, boolean longDoubleOK) { 1.595 + protected String llniType(TypeMirror t, boolean handleize, boolean longDoubleOK) { 1.596 String res = null; 1.597 - String elmt = t.typeName(); 1.598 - if (t.dimension().indexOf("[]") != -1) { 1.599 - if((t.dimension().indexOf("[][]") != -1) 1.600 - || (t.asClassDoc() != null)) res = "IArrayOfRef"; 1.601 - else if(elmt.equals("boolean")) res = "IArrayOfBoolean"; 1.602 - else if(elmt.equals("byte")) res = "IArrayOfByte"; 1.603 - else if(elmt.equals("char")) res = "IArrayOfChar"; 1.604 - else if(elmt.equals("int")) res = "IArrayOfInt"; 1.605 - else if(elmt.equals("long")) res = "IArrayOfLong"; 1.606 - else if(elmt.equals("float")) res = "IArrayOfFloat"; 1.607 - else if(elmt.equals("double")) res = "IArrayOfDouble"; 1.608 - if (!handleize) res = "DEREFERENCED_" + res; 1.609 - } else { 1.610 - if(elmt.equals("void")) res = "void"; 1.611 - else if( (elmt.equals("boolean")) || (elmt.equals("byte")) 1.612 - ||(elmt.equals("char")) || (elmt.equals("short")) 1.613 - || (elmt.equals("int"))) res = "java_int"; 1.614 - else if(elmt.equals("long")) res = longDoubleOK 1.615 - ? "java_long" : "val32 /* java_long */"; 1.616 - else if(elmt.equals("float")) res = "java_float"; 1.617 - else if(elmt.equals("double")) res = res = longDoubleOK 1.618 - ? "java_double" : "val32 /* java_double */"; 1.619 - else if(t.asClassDoc() != null) { 1.620 - res = "I" + mangleClassName(t.asClassDoc().qualifiedName()); 1.621 + 1.622 + switch (t.getKind()) { 1.623 + case ARRAY: { 1.624 + TypeMirror ct = ((ArrayType) t).getComponentType(); 1.625 + switch (ct.getKind()) { 1.626 + case BOOLEAN: res = "IArrayOfBoolean"; break; 1.627 + case BYTE: res = "IArrayOfByte"; break; 1.628 + case CHAR: res = "IArrayOfChar"; break; 1.629 + case SHORT: res = "IArrayOfShort"; break; 1.630 + case INT: res = "IArrayOfInt"; break; 1.631 + case LONG: res = "IArrayOfLong"; break; 1.632 + case FLOAT: res = "IArrayOfFloat"; break; 1.633 + case DOUBLE: res = "IArrayOfDouble"; break; 1.634 + case ARRAY: 1.635 + case DECLARED: res = "IArrayOfRef"; break; 1.636 + default: throw new Error(ct.getKind() + " " + ct); 1.637 + } 1.638 if (!handleize) res = "DEREFERENCED_" + res; 1.639 + break; 1.640 } 1.641 + 1.642 + case VOID: 1.643 + res = "void"; 1.644 + break; 1.645 + 1.646 + case BOOLEAN: 1.647 + case BYTE: 1.648 + case CHAR: 1.649 + case SHORT: 1.650 + case INT: 1.651 + res = "java_int" ; 1.652 + break; 1.653 + 1.654 + case LONG: 1.655 + res = longDoubleOK ? "java_long" : "val32 /* java_long */"; 1.656 + break; 1.657 + 1.658 + case FLOAT: 1.659 + res = "java_float"; 1.660 + break; 1.661 + 1.662 + case DOUBLE: 1.663 + res = longDoubleOK ? "java_double" : "val32 /* java_double */"; 1.664 + break; 1.665 + 1.666 + case DECLARED: 1.667 + TypeElement e = (TypeElement) types.asElement(t); 1.668 + res = "I" + mangleClassName(e.getQualifiedName().toString()); 1.669 + if (!handleize) res = "DEREFERENCED_" + res; 1.670 + break; 1.671 + 1.672 + default: 1.673 + throw new Error(t.getKind() + " " + t); // FIXME 1.674 } 1.675 + 1.676 return res; 1.677 } 1.678 1.679 - protected final String cRcvrDecl(MemberDoc field, String cname) { 1.680 - return (field.isStatic() ? "jclass" : "jobject"); 1.681 + protected final String cRcvrDecl(Element field, String cname) { 1.682 + return (field.getModifiers().contains(Modifier.STATIC) ? "jclass" : "jobject"); 1.683 } 1.684 1.685 protected String maskName(String s) { 1.686 return "LLNI_mask(" + s + ")"; 1.687 } 1.688 1.689 - protected String llniFieldName(MemberDoc field) { 1.690 - return maskName(field.name()); 1.691 + protected String llniFieldName(VariableElement field) { 1.692 + return maskName(field.getSimpleName().toString()); 1.693 } 1.694 1.695 - protected final boolean isLongOrDouble(Type t) { 1.696 - String tc = t.typeName(); 1.697 - return (tc.equals("long") || tc.equals("double")); 1.698 + protected final boolean isLongOrDouble(TypeMirror t) { 1.699 + TypeVisitor<Boolean,Void> v = new SimpleTypeVisitor6<Boolean,Void>() { 1.700 + public Boolean defaultAction(TypeMirror t, Void p){ 1.701 + return false; 1.702 + } 1.703 + public Boolean visitArray(ArrayType t, Void p) { 1.704 + return visit(t.getComponentType(), p); 1.705 + } 1.706 + public Boolean visitPrimitive(PrimitiveType t, Void p) { 1.707 + TypeKind tk = t.getKind(); 1.708 + return (tk == TypeKind.LONG || tk == TypeKind.DOUBLE); 1.709 + } 1.710 + }; 1.711 + return v.visit(t, null); 1.712 } 1.713 1.714 /* Do unicode to ansi C identifier conversion. 1.715 @@ -602,3 +669,4 @@ 1.716 return false; 1.717 } 1.718 } 1.719 +