Package org.eclipse.jdt.internal.compiler.ast

Examples of org.eclipse.jdt.internal.compiler.ast.TypeDeclaration


  /**
   * TODO: log real errors, replacing GenerateJavaScriptAST?
   */
  private static List<JsniMethod> collectJsniMethods(TreeLogger logger,
      String loc, String source, CompiledClass compiledClass, JsProgram program) {
    TypeDeclaration typeDecl = compiledClass.getTypeDeclaration();
    int[] lineEnds = typeDecl.compilationResult.getLineSeparatorPositions();
    List<JsniMethod> jsniMethods = new ArrayList<JsniMethod>();
    String enclosingType = compiledClass.getBinaryName().replace('/', '.');
    AbstractMethodDeclaration[] methods = typeDecl.methods;
    if (methods != null) {
View Full Code Here


   * @return type declaration or null if not found
   */
  private static TypeDeclaration findType(CompilationUnitDeclaration unit,
      String binaryName) {
    List<char[]> classChain = getClassChain(binaryName);
    TypeDeclaration curType = findType(unit.types, classChain.get(0));
    for (int i = 1; i < classChain.size(); ++i) {
      if (curType == null) {
        return null;
      }
      curType = findType(curType.memberTypes, classChain.get(i));
View Full Code Here

    JClassType topType = getTopmostType(type);
    CompilationUnitDeclaration cud = getCudForTopLevelType(topType);
    if (cud == null) {
      return null;
    }
    TypeDeclaration jdtType = findType(cud, type.getQualifiedBinaryName());
    if (jdtType == null) {
      // TODO(jat): any thing else to do here?
      return null;
    }
    AbstractMethodDeclaration jdtMethod = findMethod(jdtType, method);
View Full Code Here

    int methodIndex = 0, methodCount = (typeDeclaration.methods == null) ? 0 : typeDeclaration.methods.length;
    AbstractMethodDeclaration method = methodCount == 0 ? null : typeDeclaration.methods[methodIndex];
    int methodStart = method == null ? Integer.MAX_VALUE : method.declarationSourceStart;

    int typeIndex = 0, typeCount = (typeDeclaration.memberTypes == null) ? 0 : typeDeclaration.memberTypes.length;
    TypeDeclaration type = typeCount == 0 ? null : typeDeclaration.memberTypes[typeIndex];
    int typeStart = type == null ? Integer.MAX_VALUE : type.declarationSourceStart;

    final int memberLength = fieldCount+methodCount+typeCount;
    ASTNode[] members = new ASTNode[memberLength];
    if (memberLength != 0) {
View Full Code Here

      this.preferences.insert_space_after_comma_in_enum_constant_arguments,
      this.preferences.alignment_for_arguments_in_enum_constant);

    Expression initialization = enumConstant.initialization;
    if (initialization instanceof QualifiedAllocationExpression) {
      TypeDeclaration typeDeclaration = ((QualifiedAllocationExpression) initialization).anonymousType;
      int fieldsCount = typeDeclaration.fields == null ? 0 : typeDeclaration.fields.length;
      int methodsCount = typeDeclaration.methods == null ? 0 : typeDeclaration.methods.length;
      int membersCount = typeDeclaration.memberTypes == null ? 0 : typeDeclaration.memberTypes.length;

      /*
 
View Full Code Here

      this.scribe.exitAlignment(argumentsAlignment, true);
      this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_method_invocation);
    } else {
      this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_between_empty_parens_in_method_invocation);
    }
    final TypeDeclaration anonymousType = qualifiedAllocationExpression.anonymousType;
    if (anonymousType != null) {
      formatLeftCurlyBrace(line, this.preferences.brace_position_for_anonymous_type_declaration);
      formatAnonymousTypeDeclaration(anonymousType);
    }
    if (numberOfParens > 0) {
View Full Code Here

    classFile.addDefaultAbstractMethods();
  }
  // propagate generation of (problem) member types
  if (typeDeclaration.memberTypes != null) {
    for (int i = 0, max = typeDeclaration.memberTypes.length; i < max; i++) {
      TypeDeclaration memberType = typeDeclaration.memberTypes[i];
      if (memberType.binding != null) {
        ClassFile.createProblemType(memberType, unitResult);
      }
    }
  }
View Full Code Here

    final LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding;
    if (declaringMethod == null) {
      ReferenceContext referenceContext = localVariableBinding.declaringScope.referenceContext();
      if (referenceContext instanceof TypeDeclaration){
        // Local variable is declared inside an initializer
        TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
        JavaElement typeHandle = null;
        typeHandle = Util.getUnresolvedJavaElement(
          typeDeclaration.binding,
          defaultBindingResolver.workingCopyOwner,
          defaultBindingResolver.getBindingsToNodesMap());
View Full Code Here

    if (packageName.length > 0) {
      compilationUnit.currentPackage = new ImportReference(packageName, new long[]{0}, false, ClassFileConstants.AccDefault);
    }

    /* convert type */
    TypeDeclaration typeDeclaration = convert(type, null, null);

    IType alreadyComputedMember = type;
    IType parent = type.getDeclaringType();
    TypeDeclaration previousDeclaration = typeDeclaration;
    while(parent != null) {
      TypeDeclaration declaration = convert(parent, alreadyComputedMember, previousDeclaration);

      alreadyComputedMember = parent;
      previousDeclaration = declaration;
      parent = parent.getDeclaringType();
    }
View Full Code Here

    return methodDeclaration;
  }

  private TypeDeclaration convert(IType type, IType alreadyComputedMember,TypeDeclaration alreadyComputedMemberDeclaration) throws JavaModelException {
    /* create type declaration - can be member type */
    TypeDeclaration typeDeclaration = new TypeDeclaration(this.compilationResult);

    if (type.getDeclaringType() != null) {
      typeDeclaration.bits |= ASTNode.IsMemberType;
    }
    typeDeclaration.name = type.getElementName().toCharArray();
    typeDeclaration.modifiers = type.getFlags();


    /* set superclass and superinterfaces */
    if (type.getSuperclassName() != null) {
      TypeReference typeReference = createTypeReference(type.getSuperclassTypeSignature());
      if (typeReference != null) {
        typeDeclaration.superclass = typeReference;
        typeDeclaration.superclass.bits |= ASTNode.IsSuperType;
      }
    }

    String[] interfaceTypes = type.getSuperInterfaceTypeSignatures();
    int interfaceCount = interfaceTypes == null ? 0 : interfaceTypes.length;
    typeDeclaration.superInterfaces = new TypeReference[interfaceCount];
    int count = 0;
    for (int i = 0; i < interfaceCount; i++) {
      TypeReference typeReference = createTypeReference(interfaceTypes[i]);
      if (typeReference != null) {
        typeDeclaration.superInterfaces[count] = typeReference;
        typeDeclaration.superInterfaces[count++].bits |= ASTNode.IsSuperType;
      }
    }
    if (count != interfaceCount) {
      System.arraycopy(typeDeclaration.fields, 0, typeDeclaration.superInterfaces = new TypeReference[interfaceCount], 0, interfaceCount);
    }

    // convert 1.5 specific constructs only if compliance is 1.5 or above
    if (this.has1_5Compliance) {

      /* convert type parameters */
      ITypeParameter[] typeParameters = type.getTypeParameters();
      if (typeParameters != null && typeParameters.length > 0) {
        int parameterCount = typeParameters.length;
        org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParams = new org.eclipse.jdt.internal.compiler.ast.TypeParameter[parameterCount];
        for (int i = 0; i < parameterCount; i++) {
          ITypeParameter typeParameter = typeParameters[i];
          typeParams[i] =
            createTypeParameter(
                typeParameter.getElementName().toCharArray(),
                stringArrayToCharArray(typeParameter.getBounds()),
                0,
                0);
        }

        typeDeclaration.typeParameters = typeParams;
      }
    }

    /* convert member types */
    IType[] memberTypes = type.getTypes();
    int memberTypeCount =  memberTypes == null ? 0 : memberTypes.length;
    typeDeclaration.memberTypes = new TypeDeclaration[memberTypeCount];
    for (int i = 0; i < memberTypeCount; i++) {
      if(alreadyComputedMember != null && alreadyComputedMember.getFullyQualifiedName().equals(memberTypes[i].getFullyQualifiedName())) {
        typeDeclaration.memberTypes[i] = alreadyComputedMemberDeclaration;
      } else {
        typeDeclaration.memberTypes[i] = convert(memberTypes[i], null, null);
      }
      typeDeclaration.memberTypes[i].enclosingType = typeDeclaration;
    }

    /* convert fields */
    IField[] fields = type.getFields();
    int fieldCount = fields == null ? 0 : fields.length;
    typeDeclaration.fields = new FieldDeclaration[fieldCount];
    count = 0;
    for (int i = 0; i < fieldCount; i++) {
      FieldDeclaration fieldDeclaration = convert(fields[i], type);
      if (fieldDeclaration != null) {
        typeDeclaration.fields[count++] = fieldDeclaration;
      }
    }
    if (count != fieldCount) {
      System.arraycopy(typeDeclaration.fields, 0, typeDeclaration.fields = new FieldDeclaration[count], 0, count);
    }

    /* convert methods - need to add default constructor if necessary */
    IMethod[] methods = type.getMethods();
    int methodCount = methods == null ? 0 : methods.length;

    /* source type has a constructor ?           */
    /* by default, we assume that one is needed. */
    int neededCount = 1;
    for (int i = 0; i < methodCount; i++) {
      if (methods[i].isConstructor()) {
        neededCount = 0;
        // Does not need the extra constructor since one constructor already exists.
        break;
      }
    }
    boolean isInterface = type.isInterface();
    neededCount = isInterface ? 0 : neededCount;
    typeDeclaration.methods = new AbstractMethodDeclaration[methodCount + neededCount];
    if (neededCount != 0) { // add default constructor in first position
      typeDeclaration.methods[0] = typeDeclaration.createDefaultConstructor(false, false);
    }
    boolean hasAbstractMethods = false;
    count = 0;
    for (int i = 0; i < methodCount; i++) {
      AbstractMethodDeclaration method = convert(methods[i], type);
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.ast.TypeDeclaration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.