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

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


  /**
   * Returns <code>true</code> if this is a local type, or if this type is
   * nested inside of any local type.
   */
  private static boolean isLocalType(SourceTypeBinding binding) {
    SourceTypeBinding b = binding;
    while (!b.isStatic()) {
      if (b instanceof LocalTypeBinding) {
        return true;
      }
      b = ((NestedTypeBinding) b).enclosingType;
    }
View Full Code Here


  CompiledClass(CompilationUnit unit, TypeDeclaration typeDeclaration,
      CompiledClass enclosingClass) {
    this.unit = unit;
    this.typeDeclaration = typeDeclaration;
    this.enclosingClass = enclosingClass;
    SourceTypeBinding binding = typeDeclaration.binding;
    this.internalName = CharOperation.charToString(binding.constantPoolName());
    ClassFile classFile = getClassFile(typeDeclaration, internalName);
    byte[] bytes = classFile.getBytes();
    this.cacheToken = diskCache.writeByteArray(bytes);
    this.isLocal = isLocalType(binding);
  }
View Full Code Here

     */
    private boolean process(TypeDeclaration typeDeclaration) {
      CompilationResult compResult = typeDeclaration.compilationResult;
      currentSeparatorPositions = compResult.lineSeparatorPositions;
      currentFileName = String.valueOf(compResult.fileName);
      SourceTypeBinding binding = typeDeclaration.binding;

      if (binding.constantPoolName() == null) {
        /*
         * Weird case: if JDT determines that this local class is totally
         * uninstantiable, it won't bother allocating a local name.
         */
        return false;
      }
      JDeclaredType type = (JDeclaredType) typeMap.get(binding);
      try {
        // Create an override for getClass().
        if (type instanceof JClassType
            && type != program.getTypeJavaLangObject()
            && type != program.getIndexedType("Array")) {
          JMethod getClassMethod = program.createMethod(
              type.getSourceInfo().makeChild(BuildDeclMapVisitor.class,
                  "Synthetic getClass()"), "getClass".toCharArray(), type,
              program.getTypeJavaLangClass(), false, false, false, false, false);
          assert (type.getMethods().get(2) == getClassMethod);
          getClassMethod.freezeParamTypes();
        }

        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) {
              SyntheticArgumentBinding arg = nestedBinding.enclosingInstances[i];
              if (arg.matchingField != null) {
                createField(arg, type);
              }
            }
          }

          if (nestedBinding.outerLocalVariables != null) {
            for (int i = 0; i < nestedBinding.outerLocalVariables.length; ++i) {
              SyntheticArgumentBinding arg = nestedBinding.outerLocalVariables[i];
              createField(arg, type);
            }
          }
        }

        ReferenceBinding superClassBinding = binding.superclass();
        if (superClassBinding != null) {
          // TODO: handle separately?
          assert (binding.superclass().isClass() || binding.superclass().isEnum());
          JClassType superClass = (JClassType) typeMap.get(superClassBinding);
          type.setSuperClass(superClass);
        }

        ReferenceBinding[] superInterfaces = binding.superInterfaces();
        for (int i = 0; i < superInterfaces.length; ++i) {
          ReferenceBinding superInterfaceBinding = superInterfaces[i];
          assert (superInterfaceBinding.isInterface());
          JInterfaceType superInterface = (JInterfaceType) typeMap.get(superInterfaceBinding);
          type.addImplements(superInterface);
View Full Code Here

    }

    private boolean process(TypeDeclaration typeDeclaration) {
      try {
        char[][] name = typeDeclaration.binding.compoundName;
        SourceTypeBinding binding = typeDeclaration.binding;
        if (binding instanceof LocalTypeBinding) {
          char[] localName = binding.constantPoolName();
          if (localName == null) {
            /*
             * Weird case: if JDT determines that this local class is totally
             * uninstantiable, it won't bother allocating a local name.
             */
            return false;
          }

          for (int i = 0, c = localName.length; i < c; ++i) {
            if (localName[i] == '/') {
              localName[i] = '.';
            }
          }
          name = new char[1][0];
          name[0] = localName;
        }

        SourceInfo info = makeSourceInfo(typeDeclaration);
        JDeclaredType newType;
        if (binding.isClass()) {
          newType = program.createClass(info, name, binding.isAbstract(),
              binding.isFinal());
        } else if (binding.isInterface() || binding.isAnnotationType()) {
          newType = program.createInterface(info, name);
        } else if (binding.isEnum()) {
          if (binding.isAnonymousType()) {
            // Don't model an enum subclass as a JEnumType.
            newType = program.createClass(info, name, false, true);
          } else {
            newType = program.createEnum(info, name);
          }
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

          MethodScope methodScope = (MethodScope) currentScope;
          staticsOnly |= methodScope.isStatic | methodScope.isConstructorCall;
          break;
        case Scope.CLASS_SCOPE :
          ClassScope classScope = (ClassScope) currentScope;
          SourceTypeBinding enclosingType = classScope.referenceContext.binding;

          searchVisibleFields(
              enclosingType,
              classScope,
              invocationSite,
              scope,
              staticsOnly,
              notInJavadoc,
              localsFound,
              fieldsFound);

          searchVisibleMethods(
              enclosingType,
              classScope,
              invocationSite,
              scope,
              staticsOnly,
              notInJavadoc,
              methodsFound);

          staticsOnly |= enclosingType.isStatic();
          break;

        case Scope.COMPILATION_UNIT_SCOPE :
          break done2;
      }
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;
  if (methodDecls != null) {
    if (typeBinding.isInterface()) {
      // we cannot create problem methods for an interface. So we have to generate a clinit
      // which should contain all the problem
      classFile.addProblemClinit(problemsCopy);
      for (int i = 0, length = methodDecls.length; i < length; i++) {
        AbstractMethodDeclaration methodDecl = methodDecls[i];
        MethodBinding method = methodDecl.binding;
        if (method == null || method.isConstructor()) continue;
        method.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract;
        classFile.addAbstractMethod(methodDecl, method);
      }
    } else {
      for (int i = 0, length = methodDecls.length; i < length; i++) {
        AbstractMethodDeclaration methodDecl = methodDecls[i];
        MethodBinding method = methodDecl.binding;
        if (method == null) continue;
        if (method.isConstructor()) {
          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

    }

  } else if (this.receiver instanceof QualifiedSuperReference){ // qualified super

    // qualified super need emulation always
    SourceTypeBinding destinationType = (SourceTypeBinding)(((QualifiedSuperReference)this.receiver).currentCompatibleType);
    this.syntheticAccessor = destinationType.addSyntheticMethod(codegenBinding, isSuperAccess());
    currentScope.problemReporter().needToEmulateMethodAccess(codegenBinding, this);
    return;

  } else if (this.binding.isProtected()){

    SourceTypeBinding enclosingSourceType;
    if (((this.bits & ASTNode.DepthMASK) != 0)
        && codegenBinding.declaringClass.getPackage()
          != (enclosingSourceType = currentScope.enclosingSourceType()).getPackage()){

      SourceTypeBinding currentCompatibleType = (SourceTypeBinding)enclosingSourceType.enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT);
      this.syntheticAccessor = currentCompatibleType.addSyntheticMethod(codegenBinding, isSuperAccess());
      currentScope.problemReporter().needToEmulateMethodAccess(codegenBinding, this);
      return;
    }
  }
}
View Full Code Here

  AbstractMethodDeclaration method = currentMethod.sourceMethod();
  int sourceStart = 0;
  int sourceEnd = 0;
  if (method == null) {
    if (declaringClass instanceof SourceTypeBinding) {
      SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) declaringClass;
      sourceStart = sourceTypeBinding.sourceStart();
      sourceEnd = sourceTypeBinding.sourceEnd();
    }
  } else if (method.isConstructor()){
    sourceStart = method.sourceStart;
    sourceEnd = method.sourceEnd;
  } else {
View Full Code Here

    this.assertionSyntheticFieldBinding = assertionSyntheticFieldBinding;

    // we need to add the field right now, because the field infos are generated before the methods
    if (needClassLiteralField) {
      SourceTypeBinding sourceType =
        this.scope.outerMostClassScope().enclosingSourceType();
      // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=22334
      if (!sourceType.isInterface() && !sourceType.isBaseType()) {
        this.classLiteralSyntheticField = sourceType.addSyntheticFieldForClassLiteral(sourceType, this.scope);
      }
    }
  }
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.