コード例 #1
0
 public void createPackageInfoType() {
   TypeDeclaration declaration = new TypeDeclaration(this.compilationResult);
   declaration.name = TypeConstants.PACKAGE_INFO_NAME;
   declaration.modifiers = ClassFileConstants.AccDefault | ClassFileConstants.AccInterface;
   declaration.javadoc = this.javadoc;
   this.types[0] = declaration; // Assumes the first slot is meant for this type
 }
コード例 #2
0
  protected void consumeClassHeaderName1() {
    // ClassHeaderName ::= Modifiersopt 'class' 'Identifier'
    TypeDeclaration typeDecl;
    if (this.nestedMethod[this.nestedType] == 0) {
      if (this.nestedType != 0) {
        typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
        typeDecl.bits |= ASTNode.IsMemberTypeMASK;
      } else {
        typeDecl = new CodeSnippetTypeDeclaration(this.compilationUnit.compilationResult);
      }
    } else {
      // Record that the block has a declaration for local types
      typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
      typeDecl.bits |= ASTNode.IsLocalTypeMASK;
      markEnclosingMemberWithLocalType();
      blockReal();
    }

    // highlight the name of the type
    long pos = this.identifierPositionStack[this.identifierPtr];
    typeDecl.sourceEnd = (int) pos;
    typeDecl.sourceStart = (int) (pos >>> 32);
    typeDecl.name = this.identifierStack[this.identifierPtr--];
    this.identifierLengthPtr--;

    // compute the declaration source too
    typeDecl.declarationSourceStart = this.intStack[this.intPtr--];
    this.intPtr--;
    // 'class' and 'interface' push an int position
    typeDecl.modifiersSourceStart = this.intStack[this.intPtr--];
    typeDecl.modifiers = this.intStack[this.intPtr--];
    if (typeDecl.modifiersSourceStart >= 0) {
      typeDecl.declarationSourceStart = typeDecl.modifiersSourceStart;
    }
    typeDecl.bodyStart = typeDecl.sourceEnd + 1;
    pushOnAstStack(typeDecl);

    this.listLength = 0; // will be updated when reading super-interfaces
    // recovery
    if (this.currentElement != null) {
      this.lastCheckPoint = typeDecl.bodyStart;
      this.currentElement = this.currentElement.add(typeDecl, 0);
      this.lastIgnoredToken = -1;
    }
    // javadoc
    typeDecl.javadoc = this.javadoc;
    this.javadoc = null;
  }
コード例 #3
0
 /*
  * @see ASTVisitor#visit(TypeDeclaration)
  */
 @Override
 public boolean visit(TypeDeclaration node) {
   if (node.getJavadoc() != null) {
     node.getJavadoc().accept(this);
   }
   if (node.getAST().apiLevel() >= JLS3) {
     printModifiers(node.modifiers());
   }
   this.fBuffer.append(node.isInterface() ? "interface " : "class "); // $NON-NLS-2$//$NON-NLS-1$
   node.getName().accept(this);
   if (node.getAST().apiLevel() >= JLS3) {
     if (!node.typeParameters().isEmpty()) {
       this.fBuffer.append("<"); // $NON-NLS-1$
       for (Iterator<TypeParameter> it = node.typeParameters().iterator(); it.hasNext(); ) {
         TypeParameter t = it.next();
         t.accept(this);
         if (it.hasNext()) {
           this.fBuffer.append(","); // $NON-NLS-1$
         }
       }
       this.fBuffer.append(">"); // $NON-NLS-1$
     }
   }
   this.fBuffer.append(" "); // $NON-NLS-1$
   if (node.getAST().apiLevel() >= JLS3) {
     if (node.getSuperclassType() != null) {
       this.fBuffer.append("extends "); // $NON-NLS-1$
       node.getSuperclassType().accept(this);
       this.fBuffer.append(" "); // $NON-NLS-1$
     }
     if (!node.superInterfaceTypes().isEmpty()) {
       this.fBuffer.append(
           node.isInterface() ? "extends " : "implements "); // $NON-NLS-2$//$NON-NLS-1$
       for (Iterator<Type> it = node.superInterfaceTypes().iterator(); it.hasNext(); ) {
         Type t = it.next();
         t.accept(this);
         if (it.hasNext()) {
           this.fBuffer.append(", "); // $NON-NLS-1$
         }
       }
       this.fBuffer.append(" "); // $NON-NLS-1$
     }
   }
   this.fBuffer.append("{"); // $NON-NLS-1$
   BodyDeclaration prev = null;
   for (Iterator<BodyDeclaration> it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
     BodyDeclaration d = it.next();
     if (prev instanceof EnumConstantDeclaration) {
       // enum constant declarations do not include punctuation
       if (d instanceof EnumConstantDeclaration) {
         // enum constant declarations are separated by commas
         this.fBuffer.append(", "); // $NON-NLS-1$
       } else {
         // semicolon separates last enum constant declaration from
         // first class body declarations
         this.fBuffer.append("; "); // $NON-NLS-1$
       }
     }
     d.accept(this);
     prev = d;
   }
   this.fBuffer.append("}"); // $NON-NLS-1$
   return false;
 }