< prev index next >

buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ScriptClassInfoCollector.java

Print this page




 189 
 190                 if (annoKind != null) {
 191                     if ((methodAccess & Opcodes.ACC_STATIC) == 0) {
 192                         error(methodName, methodDesc, "nasgen method annotations cannot be on instance methods");
 193                     }
 194 
 195                     final MemberInfo memInfo = new MemberInfo();
 196 
 197                     // annoKind == GETTER or SPECIALIZED_FUNCTION
 198                     memInfo.setKind(annoKind);
 199                     memInfo.setJavaName(methodName);
 200                     memInfo.setJavaDesc(methodDesc);
 201                     memInfo.setJavaAccess(methodAccess);
 202 
 203                     addScriptMember(memInfo);
 204 
 205                     return new AnnotationVisitor(Main.ASM_VERSION, delegateAV) {
 206                         // These could be "null" if values are not supplied,
 207                         // in which case we have to use the default values.
 208                         private String  name;

 209                         private Integer attributes;
 210                         private Integer arity;
 211                         private Where   where;
 212                         private boolean isSpecializedConstructor;
 213                         private boolean isOptimistic;
 214                         private Type    linkLogicClass = MethodGenerator.EMPTY_LINK_LOGIC_TYPE;
 215 
 216                         @Override
 217                         public void visit(final String annotationName, final Object annotationValue) {
 218                             switch (annotationName) {
 219                             case "name":
 220                                 this.name = (String)annotationValue;
 221                                 if (name.isEmpty()) {
 222                                     name = null;
 223                                 }
 224                                 break;







 225                             case "attributes":
 226                                 this.attributes = (Integer)annotationValue;
 227                                 break;
 228                             case "arity":
 229                                 this.arity = (Integer)annotationValue;
 230                                 break;
 231                             case "isConstructor":
 232                                 assert annoKind == Kind.SPECIALIZED_FUNCTION;
 233                                 this.isSpecializedConstructor = (Boolean)annotationValue;
 234                                 break;
 235                             case "isOptimistic":
 236                                 assert annoKind == Kind.SPECIALIZED_FUNCTION;
 237                                 this.isOptimistic = (Boolean)annotationValue;
 238                                 break;
 239                             case "linkLogic":
 240                                 this.linkLogicClass = (Type)annotationValue;
 241                                 break;
 242                             default:
 243                                 break;
 244                             }


 253                                 if (WHERE_ENUM_DESC.equals(desc)) {
 254                                     this.where = Where.valueOf(enumValue);
 255                                 }
 256                                 break;
 257                             default:
 258                                 break;
 259                             }
 260                             super.visitEnum(enumName, desc, enumValue);
 261                         }
 262 
 263                         @SuppressWarnings("fallthrough")
 264                         @Override
 265                         public void visitEnd() {
 266                             super.visitEnd();
 267 
 268                             if (memInfo.getKind() == Kind.CONSTRUCTOR) {
 269                                 memInfo.setName(name == null ? scriptClassName : name);
 270                             } else {
 271                                 memInfo.setName(name == null ? methodName : name);
 272                             }


 273                             memInfo.setAttributes(attributes == null ? MemberInfo.DEFAULT_ATTRIBUTES : attributes);
 274 
 275                             memInfo.setArity((arity == null)? MemberInfo.DEFAULT_ARITY : arity);
 276                             if (where == null) {
 277                                 // by default @Getter/@Setter belongs to INSTANCE
 278                                 // @Function belong to PROTOTYPE.
 279                                 switch (memInfo.getKind()) {
 280                                     case GETTER:
 281                                     case SETTER:
 282                                         where = Where.INSTANCE;
 283                                         break;
 284                                     case CONSTRUCTOR:
 285                                         where = Where.CONSTRUCTOR;
 286                                         break;
 287                                     case FUNCTION:
 288                                         where = Where.PROTOTYPE;
 289                                         break;
 290                                     case SPECIALIZED_FUNCTION:
 291                                         where = isSpecializedConstructor? Where.CONSTRUCTOR : Where.PROTOTYPE;
 292                                         //fallthru




 189 
 190                 if (annoKind != null) {
 191                     if ((methodAccess & Opcodes.ACC_STATIC) == 0) {
 192                         error(methodName, methodDesc, "nasgen method annotations cannot be on instance methods");
 193                     }
 194 
 195                     final MemberInfo memInfo = new MemberInfo();
 196 
 197                     // annoKind == GETTER or SPECIALIZED_FUNCTION
 198                     memInfo.setKind(annoKind);
 199                     memInfo.setJavaName(methodName);
 200                     memInfo.setJavaDesc(methodDesc);
 201                     memInfo.setJavaAccess(methodAccess);
 202 
 203                     addScriptMember(memInfo);
 204 
 205                     return new AnnotationVisitor(Main.ASM_VERSION, delegateAV) {
 206                         // These could be "null" if values are not supplied,
 207                         // in which case we have to use the default values.
 208                         private String  name;
 209                         private String  documentation;
 210                         private Integer attributes;
 211                         private Integer arity;
 212                         private Where   where;
 213                         private boolean isSpecializedConstructor;
 214                         private boolean isOptimistic;
 215                         private Type    linkLogicClass = MethodGenerator.EMPTY_LINK_LOGIC_TYPE;
 216 
 217                         @Override
 218                         public void visit(final String annotationName, final Object annotationValue) {
 219                             switch (annotationName) {
 220                             case "name":
 221                                 this.name = (String)annotationValue;
 222                                 if (name.isEmpty()) {
 223                                     name = null;
 224                                 }
 225                                 break;
 226                             case "documentation":
 227                                 this.documentation = (String)annotationValue;
 228                                 if (documentation.isEmpty()) {
 229                                     documentation = null;
 230                                 }
 231 
 232                                 break;
 233                             case "attributes":
 234                                 this.attributes = (Integer)annotationValue;
 235                                 break;
 236                             case "arity":
 237                                 this.arity = (Integer)annotationValue;
 238                                 break;
 239                             case "isConstructor":
 240                                 assert annoKind == Kind.SPECIALIZED_FUNCTION;
 241                                 this.isSpecializedConstructor = (Boolean)annotationValue;
 242                                 break;
 243                             case "isOptimistic":
 244                                 assert annoKind == Kind.SPECIALIZED_FUNCTION;
 245                                 this.isOptimistic = (Boolean)annotationValue;
 246                                 break;
 247                             case "linkLogic":
 248                                 this.linkLogicClass = (Type)annotationValue;
 249                                 break;
 250                             default:
 251                                 break;
 252                             }


 261                                 if (WHERE_ENUM_DESC.equals(desc)) {
 262                                     this.where = Where.valueOf(enumValue);
 263                                 }
 264                                 break;
 265                             default:
 266                                 break;
 267                             }
 268                             super.visitEnum(enumName, desc, enumValue);
 269                         }
 270 
 271                         @SuppressWarnings("fallthrough")
 272                         @Override
 273                         public void visitEnd() {
 274                             super.visitEnd();
 275 
 276                             if (memInfo.getKind() == Kind.CONSTRUCTOR) {
 277                                 memInfo.setName(name == null ? scriptClassName : name);
 278                             } else {
 279                                 memInfo.setName(name == null ? methodName : name);
 280                             }
 281 
 282                             memInfo.setDocumentation(documentation);
 283                             memInfo.setAttributes(attributes == null ? MemberInfo.DEFAULT_ATTRIBUTES : attributes);
 284 
 285                             memInfo.setArity((arity == null)? MemberInfo.DEFAULT_ARITY : arity);
 286                             if (where == null) {
 287                                 // by default @Getter/@Setter belongs to INSTANCE
 288                                 // @Function belong to PROTOTYPE.
 289                                 switch (memInfo.getKind()) {
 290                                     case GETTER:
 291                                     case SETTER:
 292                                         where = Where.INSTANCE;
 293                                         break;
 294                                     case CONSTRUCTOR:
 295                                         where = Where.CONSTRUCTOR;
 296                                         break;
 297                                     case FUNCTION:
 298                                         where = Where.PROTOTYPE;
 299                                         break;
 300                                     case SPECIALIZED_FUNCTION:
 301                                         where = isSpecializedConstructor? Where.CONSTRUCTOR : Where.PROTOTYPE;
 302                                         //fallthru


< prev index next >