Package org.eclipse.jdt.internal.compiler.lookup

Examples of org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding


      /*
       * It's okay to defer creation of synthetic fields, they can't be
       * referenced until we analyze the code.
       */
      int index = 0;
      SourceTypeBinding binding = x.binding;
      if (binding.isNestedType() && !binding.isStatic()) {
        // add synthetic fields for outer this and locals
        assert (type instanceof JClassType);
        NestedTypeBinding nestedBinding = (NestedTypeBinding) binding;
        if (nestedBinding.enclosingInstances != null) {
          for (int i = 0; i < nestedBinding.enclosingInstances.length; ++i) {
View Full Code Here


  IJavaElement res;
  if(fieldBinding.declaringClass instanceof ParameterizedTypeBinding) {
    LocalTypeBinding localTypeBinding = (LocalTypeBinding)((ParameterizedTypeBinding)fieldBinding.declaringClass).genericType();
    res = findLocalElement(localTypeBinding.sourceStart());
  } else {
    SourceTypeBinding typeBinding = (SourceTypeBinding)fieldBinding.declaringClass;
    res = findLocalElement(typeBinding.sourceStart());
  }
  if (res != null && res.getElementType() == IJavaElement.TYPE) {
    IType type = (IType) res;
    IField field= type.getField(new String(fieldBinding.name));
    if (field.exists()) {
View Full Code Here

  IJavaElement res;
  if(typeVariableBinding.declaringElement instanceof ParameterizedTypeBinding) {
    LocalTypeBinding localTypeBinding = (LocalTypeBinding)((ParameterizedTypeBinding)typeVariableBinding.declaringElement).genericType();
    res = findLocalElement(localTypeBinding.sourceStart());
  } else {
    SourceTypeBinding typeBinding = (SourceTypeBinding)typeVariableBinding.declaringElement;
    res = findLocalElement(typeBinding.sourceStart());
  }
  if (res != null && res.getElementType() == IJavaElement.TYPE) {
    IType type = (IType) res;
    ITypeParameter typeParameter = type.getTypeParameter(new String(typeVariableBinding.sourceName));
    if (typeParameter.exists()) {
View Full Code Here

*
* @param typeDeclaration org.eclipse.jdt.internal.compiler.ast.TypeDeclaration
* @param unitResult org.eclipse.jdt.internal.compiler.CompilationUnitResult
*/
public static void createProblemType(TypeDeclaration typeDeclaration, CompilationResult unitResult) {
  SourceTypeBinding typeBinding = typeDeclaration.binding;
  ClassFile classFile = new CodeSnippetClassFile(typeBinding, null, true);

  // inner attributes
  if (typeBinding.hasMemberTypes()) {
    // see bug 180109
    ReferenceBinding[] members = typeBinding.memberTypes;
    for (int i = 0, l = members.length; i < l; i++)
      classFile.recordInnerClasses(members[i]);
  }
  // TODO (olivier) handle cases where a field cannot be generated (name too long)
  // TODO (olivier) handle too many methods
  // inner attributes
  if (typeBinding.isNestedType()) {
    classFile.recordInnerClasses(typeBinding);
  }
  TypeVariableBinding[] typeVariables = typeBinding.typeVariables();
  for (int i = 0, max = typeVariables.length; i < max; i++) {
    TypeVariableBinding typeVariableBinding = typeVariables[i];
    if ((typeVariableBinding.tagBits & TagBits.ContainsNestedTypeReferences) != 0) {
      Util.recordNestedType(classFile, typeVariableBinding);
    }
  }

  // add its fields
  FieldBinding[] fields = typeBinding.fields();
  if ((fields != null) && (fields != Binding.NO_FIELDS)) {
    classFile.addFieldInfos();
  } else {
    // we have to set the number of fields to be equals to 0
    classFile.contents[classFile.contentsOffset++] = 0;
    classFile.contents[classFile.contentsOffset++] = 0;
  }
  // leave some space for the methodCount
  classFile.setForMethodInfos();
  // add its user defined methods
  int problemsLength;
  CategorizedProblem[] problems = unitResult.getErrors();
  if (problems == null) {
    problems = new CategorizedProblem[0];
  }
  CategorizedProblem[] problemsCopy = new CategorizedProblem[problemsLength = problems.length];
  System.arraycopy(problems, 0, problemsCopy, 0, problemsLength);
  AbstractMethodDeclaration[] methodDecls = typeDeclaration.methods;
  boolean abstractMethodsOnly = false;
  if (methodDecls != null) {
    if (typeBinding.isInterface()) {
      if (typeBinding.scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_8)
        abstractMethodsOnly = true;
      // We generate a clinit which contains all the problems, since we may not be able to generate problem methods (< 1.8) and problem constructors (all levels).
      classFile.addProblemClinit(problemsCopy);
    }
    for (int i = 0, length = methodDecls.length; i < length; i++) {
      AbstractMethodDeclaration methodDecl = methodDecls[i];
      MethodBinding method = methodDecl.binding;
      if (method == null) continue;
      if (abstractMethodsOnly) {
        method.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract;
      }
      if (method.isConstructor()) {
        if (typeBinding.isInterface()) continue;
        classFile.addProblemConstructor(methodDecl, method, problemsCopy);
      } else if (method.isAbstract()) {
        classFile.addAbstractMethod(methodDecl, method);
      } else {
        classFile.addProblemMethod(methodDecl, method, problemsCopy);
      }
    }
    // add abstract methods
    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);
      }
    }
  }
  classFile.addAttributes();
  unitResult.record(typeBinding.constantPoolName(), classFile);
}
View Full Code Here

   *
   * @param typeDeclaration org.eclipse.jdt.internal.compiler.ast.TypeDeclaration
   * @param unitResult org.eclipse.jdt.internal.compiler.CompilationUnitResult
   */
  public static void createProblemType(TypeDeclaration typeDeclaration, CompilationResult unitResult) {
    SourceTypeBinding typeBinding = typeDeclaration.binding;
    ClassFile classFile = ClassFile.getNewInstance(typeBinding);
    classFile.initialize(typeBinding, null, true);

    if (typeBinding.hasMemberTypes()) {
      // see bug 180109
      ReferenceBinding[] members = typeBinding.memberTypes;
      for (int i = 0, l = members.length; i < l; i++)
        classFile.recordInnerClasses(members[i]);
    }
    // TODO (olivier) handle cases where a field cannot be generated (name too long)
    // TODO (olivier) handle too many methods
    // inner attributes
    if (typeBinding.isNestedType()) {
      classFile.recordInnerClasses(typeBinding);
    }
    TypeVariableBinding[] typeVariables = typeBinding.typeVariables();
    for (int i = 0, max = typeVariables.length; i < max; i++) {
      TypeVariableBinding typeVariableBinding = typeVariables[i];
      if ((typeVariableBinding.tagBits & TagBits.ContainsNestedTypeReferences) != 0) {
        Util.recordNestedType(classFile, typeVariableBinding);
      }
    }
    // add its fields
    FieldBinding[] fields = typeBinding.fields();
    if ((fields != null) && (fields != Binding.NO_FIELDS)) {
      classFile.addFieldInfos();
    } else {
      // we have to set the number of fields to be equals to 0
      classFile.contents[classFile.contentsOffset++] = 0;
      classFile.contents[classFile.contentsOffset++] = 0;
    }
    // leave some space for the methodCount
    classFile.setForMethodInfos();
    // add its user defined methods
    int problemsLength;
    CategorizedProblem[] problems = unitResult.getErrors();
    if (problems == null) {
      problems = new CategorizedProblem[0];
    }
    CategorizedProblem[] problemsCopy = new CategorizedProblem[problemsLength = problems.length];
    System.arraycopy(problems, 0, problemsCopy, 0, problemsLength);

    AbstractMethodDeclaration[] methodDecls = typeDeclaration.methods;
    boolean abstractMethodsOnly = false;
    if (methodDecls != null) {
      if (typeBinding.isInterface()) {
        if (typeBinding.scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_8)
          abstractMethodsOnly = true;
        // We generate a clinit which contains all the problems, since we may not be able to generate problem methods (< 1.8) and problem constructors (all levels).
        classFile.addProblemClinit(problemsCopy);
      }
      for (int i = 0, length = methodDecls.length; i < length; i++) {
        AbstractMethodDeclaration methodDecl = methodDecls[i];
        MethodBinding method = methodDecl.binding;
        if (method == null) continue;
        if (abstractMethodsOnly) {
          method.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract;
        }
        if (method.isConstructor()) {
          if (typeBinding.isInterface()) continue;
          classFile.addProblemConstructor(methodDecl, method, problemsCopy);
        } else if (method.isAbstract()) {
          classFile.addAbstractMethod(methodDecl, method);
        } else {
          classFile.addProblemMethod(methodDecl, method, problemsCopy);
        }
      }
      // add abstract methods
      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);
        }
      }
    }
    classFile.addAttributes();
    unitResult.record(typeBinding.constantPoolName(), classFile);
  }
View Full Code Here

   * This includes:
   * - a field info for each defined field of that class
   * - a field info for each synthetic field (e.g. this$0)
   */
  public void addFieldInfos() {
    SourceTypeBinding currentBinding = this.referenceBinding;
    FieldBinding[] syntheticFields = currentBinding.syntheticFields();
    int fieldCount =   currentBinding.fieldCount() + (syntheticFields == null ? 0 : syntheticFields.length);

    // write the number of fields
    if (fieldCount > 0xFFFF) {
      this.referenceBinding.scope.problemReporter().tooManyFields(this.referenceBinding.scope.referenceType());
    }
View Full Code Here

    int localVariableTableOffset = localContentsOffset;
    // leave space for attribute_length and local_variable_table_length
    localContentsOffset += 6;
    int nameIndex;
    int descriptorIndex;
    SourceTypeBinding declaringClassBinding = null;
    if (!methodDeclarationIsStatic && !isSynthetic) {
      numberOfEntries++;
      this.contents[localContentsOffset++] = 0; // the startPC for this is always 0
      this.contents[localContentsOffset++] = 0;
      this.contents[localContentsOffset++] = (byte) (code_length >> 8);
      this.contents[localContentsOffset++] = (byte) code_length;
      nameIndex = this.constantPool.literalIndex(ConstantPool.This);
      this.contents[localContentsOffset++] = (byte) (nameIndex >> 8);
      this.contents[localContentsOffset++] = (byte) nameIndex;
      declaringClassBinding = (SourceTypeBinding)
          (this.codeStream.methodDeclaration != null ? this.codeStream.methodDeclaration.binding.declaringClass : this.codeStream.lambdaExpression.binding.declaringClass);
      descriptorIndex =
        this.constantPool.literalIndex(
          declaringClassBinding.signature());
      this.contents[localContentsOffset++] = (byte) (descriptorIndex >> 8);
      this.contents[localContentsOffset++] = (byte) descriptorIndex;
      this.contents[localContentsOffset++] = 0;// the resolved position for this is always 0
      this.contents[localContentsOffset++] = 0;
    }
    // used to remember the local variable with a generic type
    int genericLocalVariablesCounter = 0;
    LocalVariableBinding[] genericLocalVariables = null;
    int numberOfGenericEntries = 0;

    for (int i = 0, max = this.codeStream.allLocalsCounter; i < max; i++) {
      LocalVariableBinding localVariable = this.codeStream.locals[i];
      int initializationCount = localVariable.initializationCount;
      if (initializationCount == 0) continue;
      if (localVariable.declaration == null) continue;
      final TypeBinding localVariableTypeBinding = localVariable.type;
      boolean isParameterizedType = localVariableTypeBinding.isParameterizedType() || localVariableTypeBinding.isTypeVariable();
      if (isParameterizedType) {
        if (genericLocalVariables == null) {
          // we cannot have more than max locals
          genericLocalVariables = new LocalVariableBinding[max];
        }
        genericLocalVariables[genericLocalVariablesCounter++] = localVariable;
      }
      for (int j = 0; j < initializationCount; j++) {
        int startPC = localVariable.initializationPCs[j << 1];
        int endPC = localVariable.initializationPCs[(j << 1) + 1];
        if (startPC != endPC) { // only entries for non zero length
          if (endPC == -1) {
            localVariable.declaringScope.problemReporter().abortDueToInternalError(
                Messages.bind(Messages.abort_invalidAttribute, new String(localVariable.name)),
                (ASTNode) localVariable.declaringScope.methodScope().referenceContext);
          }
          if (isParameterizedType) {
            numberOfGenericEntries++;
          }
          // now we can safely add the local entry
          numberOfEntries++;
          this.contents[localContentsOffset++] = (byte) (startPC >> 8);
          this.contents[localContentsOffset++] = (byte) startPC;
          int length = endPC - startPC;
          this.contents[localContentsOffset++] = (byte) (length >> 8);
          this.contents[localContentsOffset++] = (byte) length;
          nameIndex = this.constantPool.literalIndex(localVariable.name);
          this.contents[localContentsOffset++] = (byte) (nameIndex >> 8);
          this.contents[localContentsOffset++] = (byte) nameIndex;
          descriptorIndex = this.constantPool.literalIndex(localVariableTypeBinding.signature());
          this.contents[localContentsOffset++] = (byte) (descriptorIndex >> 8);
          this.contents[localContentsOffset++] = (byte) descriptorIndex;
          int resolvedPosition = localVariable.resolvedPosition;
          this.contents[localContentsOffset++] = (byte) (resolvedPosition >> 8);
          this.contents[localContentsOffset++] = (byte) resolvedPosition;
        }
      }
    }
    int value = numberOfEntries * 10 + 2;
    this.contents[localVariableTableOffset++] = (byte) (value >> 24);
    this.contents[localVariableTableOffset++] = (byte) (value >> 16);
    this.contents[localVariableTableOffset++] = (byte) (value >> 8);
    this.contents[localVariableTableOffset++] = (byte) value;
    this.contents[localVariableTableOffset++] = (byte) (numberOfEntries >> 8);
    this.contents[localVariableTableOffset] = (byte) numberOfEntries;
    attributesNumber++;

    final boolean currentInstanceIsGeneric =
      !methodDeclarationIsStatic
      && declaringClassBinding != null
      && declaringClassBinding.typeVariables != Binding.NO_TYPE_VARIABLES;
    if (genericLocalVariablesCounter != 0 || currentInstanceIsGeneric) {
      // add the local variable type table attribute
      numberOfGenericEntries += (currentInstanceIsGeneric ? 1 : 0);
      maxOfEntries = 8 + numberOfGenericEntries * 10;
      // reserve enough space
      if (localContentsOffset + maxOfEntries >= this.contents.length) {
        resizeContents(maxOfEntries);
      }
      int localVariableTypeNameIndex =
        this.constantPool.literalIndex(AttributeNamesConstants.LocalVariableTypeTableName);
      this.contents[localContentsOffset++] = (byte) (localVariableTypeNameIndex >> 8);
      this.contents[localContentsOffset++] = (byte) localVariableTypeNameIndex;
      value = numberOfGenericEntries * 10 + 2;
      this.contents[localContentsOffset++] = (byte) (value >> 24);
      this.contents[localContentsOffset++] = (byte) (value >> 16);
      this.contents[localContentsOffset++] = (byte) (value >> 8);
      this.contents[localContentsOffset++] = (byte) value;
      this.contents[localContentsOffset++] = (byte) (numberOfGenericEntries >> 8);
      this.contents[localContentsOffset++] = (byte) numberOfGenericEntries;
      if (currentInstanceIsGeneric) {
        this.contents[localContentsOffset++] = 0; // the startPC for this is always 0
        this.contents[localContentsOffset++] = 0;
        this.contents[localContentsOffset++] = (byte) (code_length >> 8);
        this.contents[localContentsOffset++] = (byte) code_length;
        nameIndex = this.constantPool.literalIndex(ConstantPool.This);
        this.contents[localContentsOffset++] = (byte) (nameIndex >> 8);
        this.contents[localContentsOffset++] = (byte) nameIndex;
        descriptorIndex = this.constantPool.literalIndex(declaringClassBinding.genericTypeSignature());
        this.contents[localContentsOffset++] = (byte) (descriptorIndex >> 8);
        this.contents[localContentsOffset++] = (byte) descriptorIndex;
        this.contents[localContentsOffset++] = 0;// the resolved position for this is always 0
        this.contents[localContentsOffset++] = 0;
      }
View Full Code Here

/**
* For now, remember the compiled type using its compound name.
*/
public void record(char[] typeName, ClassFile classFile) {
    SourceTypeBinding sourceType = classFile.referenceBinding;
    if (!sourceType.isLocalType() && sourceType.isHierarchyInconsistent()) {
        this.hasInconsistentToplevelHierarchies = true;
    }
  this.compiledTypes.put(typeName, classFile);
}
View Full Code Here

      method.addThrownException(type);
    }
  }

  private void resolveTypeRefs(TypeDeclaration x) {
    SourceTypeBinding binding = x.binding;
    JDeclaredType type = (JDeclaredType) typeMap.get(binding);
    try {
      ReferenceBinding superClassBinding = binding.superclass();
      if (type instanceof JClassType && superClassBinding != null) {
        assert (binding.superclass().isClass() || binding.superclass().isEnum());
        JClassType superClass = (JClassType) typeMap.get(superClassBinding);
        ((JClassType) type).setSuperClass(superClass);
      }

      ReferenceBinding[] superInterfaces = binding.superInterfaces();
      for (ReferenceBinding superInterfaceBinding : superInterfaces) {
        assert (superInterfaceBinding.isInterface());
        JInterfaceType superInterface = (JInterfaceType) typeMap.get(superInterfaceBinding);
        type.addImplements(superInterface);
      }

      ReferenceBinding enclosingBinding = binding.enclosingType();
      if (enclosingBinding != null) {
        type.setEnclosingType((JDeclaredType) typeMap.get(enclosingBinding));
      }
      if (x.memberTypes != null) {
        for (TypeDeclaration memberType : x.memberTypes) {
View Full Code Here

    JsInteropUtil.maybeSetExportedField(x, field);
    typeMap.setField(binding, field);
  }

  private void createMembers(TypeDeclaration x) {
    SourceTypeBinding binding = x.binding;
    JDeclaredType type = (JDeclaredType) typeMap.get(binding);
    SourceInfo info = type.getSourceInfo();
    try {
      /**
       * We emulate static initializers and instance initializers as methods. As
       * in other cases, this gives us: simpler AST, easier to optimize, more
       * like output JavaScript. Clinit is always in slot 0, init (if it exists)
       * is always in slot 1.
       */
      assert type.getMethods().size() == 0;
      createSyntheticMethod(info, "$clinit", type, JPrimitiveType.VOID, false, true, true,
          AccessModifier.PRIVATE);

      if (type instanceof JClassType) {
        assert type.getMethods().size() == 1;
        createSyntheticMethod(info, "$init", type, JPrimitiveType.VOID, false, false, true,
            AccessModifier.PRIVATE);

        // Add a getClass() implementation for all non-Object, non-String classes.
        if (isSyntheticGetClassNeeded(x, type)) {
          assert type.getMethods().size() == 2;
          createSyntheticMethod(info, "getClass", type, javaLangClass, false, false, false,
              AccessModifier.PUBLIC);
        }
      }

      if (type instanceof JEnumType) {
        {
          assert type.getMethods().size() == 3;
          MethodBinding valueOfBinding =
              binding.getExactMethod(VALUE_OF, new TypeBinding[]{x.scope.getJavaLangString()},
                  curCud.scope);
          assert valueOfBinding != null;
          createSyntheticMethodFromBinding(info, valueOfBinding, new String[]{"name"});
        }
        {
          assert type.getMethods().size() == 4;
          MethodBinding valuesBinding = binding.getExactMethod(VALUES, NO_TYPES, curCud.scope);
          assert valuesBinding != null;
          createSyntheticMethodFromBinding(info, valuesBinding, null);
        }
      }

View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding

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.