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

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


    return false;
  }

  @Override
  public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) {
    SourceTypeBinding binding = memberTypeDeclaration.binding;
    if (binding == null) {
      return false;
    }
    Annotation[] annotations = memberTypeDeclaration.annotations;
    if (annotations != null) {
View Full Code Here


    return true;
  }

  @Override
  public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) {
    SourceTypeBinding binding = typeDeclaration.binding;
    if (binding == null) {
      return false;
    }
    Annotation[] annotations = typeDeclaration.annotations;
    if (annotations != null) {
View Full Code Here

        case CLASS :
        case ENUM :
          TypeElementImpl typeElementImpl = (TypeElementImpl) e;
          Binding typeBinding = typeElementImpl._binding;
          if (typeBinding instanceof SourceTypeBinding) {
            SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) typeBinding;
            TypeDeclaration typeDeclaration = (TypeDeclaration) sourceTypeBinding.scope.referenceContext();
            referenceContext = typeDeclaration;
            elementAnnotations = typeDeclaration.annotations;
            startPosition = typeDeclaration.sourceStart;
            endPosition = typeDeclaration.sourceEnd;
          }
          break;
        case PACKAGE :
          // nothing to do: there is no reference context for a package
          break;
        case CONSTRUCTOR :
        case METHOD :
          ExecutableElementImpl executableElementImpl = (ExecutableElementImpl) e;
          Binding binding = executableElementImpl._binding;
          if (binding instanceof MethodBinding) {
            MethodBinding methodBinding = (MethodBinding) binding;
            AbstractMethodDeclaration sourceMethod = methodBinding.sourceMethod();
            if (sourceMethod != null) {
              referenceContext = sourceMethod;
              elementAnnotations = sourceMethod.annotations;
              startPosition = sourceMethod.sourceStart;
              endPosition = sourceMethod.sourceEnd;
            }
          }
          break;
        case ENUM_CONSTANT :
          break;
        case EXCEPTION_PARAMETER :
          break;
        case FIELD :
        case PARAMETER :
          VariableElementImpl variableElementImpl = (VariableElementImpl) e;
          binding = variableElementImpl._binding;
          if (binding instanceof FieldBinding) {
            FieldBinding fieldBinding = (FieldBinding) binding;
            FieldDeclaration fieldDeclaration = fieldBinding.sourceField();
            if (fieldDeclaration != null) {
              ReferenceBinding declaringClass = fieldBinding.declaringClass;
              if (declaringClass instanceof SourceTypeBinding) {
                SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) declaringClass;
                TypeDeclaration typeDeclaration = (TypeDeclaration) sourceTypeBinding.scope.referenceContext();
                referenceContext = typeDeclaration;
              }
              elementAnnotations = fieldDeclaration.annotations;
              startPosition = fieldDeclaration.sourceStart;
View Full Code Here

      case ENUM :
      case INTERFACE :
        TypeElementImpl typeElementImpl = (TypeElementImpl) e;
        ReferenceBinding referenceBinding = (ReferenceBinding)typeElementImpl._binding;
        if (referenceBinding instanceof SourceTypeBinding) {
          SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) referenceBinding;
          referenceContext = sourceTypeBinding.scope.referenceContext;
          javadoc = ((TypeDeclaration) referenceContext).javadoc;
        }
        break;
      case PACKAGE :
        // might need to handle javadoc of package-info.java file
        PackageElementImpl packageElementImpl = (PackageElementImpl) e;
        PackageBinding packageBinding = (PackageBinding) packageElementImpl._binding;
        char[][] compoundName = CharOperation.arrayConcat(packageBinding.compoundName, TypeConstants.PACKAGE_INFO_NAME);
        ReferenceBinding type = this._env.getLookupEnvironment().getType(compoundName);
        if (type != null && type.isValidBinding() && (type instanceof SourceTypeBinding)) {
          SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) type;
          referenceContext = sourceTypeBinding.scope.referenceContext;
          javadoc = ((TypeDeclaration) referenceContext).javadoc;
        }
        break;
      case CONSTRUCTOR :
      case METHOD :
        ExecutableElementImpl executableElementImpl = (ExecutableElementImpl) e;
        MethodBinding methodBinding = (MethodBinding) executableElementImpl._binding;
        AbstractMethodDeclaration sourceMethod = methodBinding.sourceMethod();
        if (sourceMethod != null) {
          javadoc = sourceMethod.javadoc;
          referenceContext = sourceMethod;
        }
        break;
      case ENUM_CONSTANT :
      case FIELD :
        VariableElementImpl variableElementImpl = (VariableElementImpl) e;
        FieldBinding fieldBinding = (FieldBinding) variableElementImpl._binding;
        FieldDeclaration sourceField = fieldBinding.sourceField();
        if (sourceField != null) {
          javadoc = sourceField.javadoc;
          if (fieldBinding.declaringClass instanceof SourceTypeBinding) {
            SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) fieldBinding.declaringClass;
            referenceContext = sourceTypeBinding.scope.referenceContext;
          }
        }
    }
    if (javadoc != null && referenceContext != null) {
View Full Code Here

      if (field.isStatic()) {
        if ((field.modifiers & ClassFileConstants.AccEnum) != 0) { // enum constants are checked even when qualified)
          ReferenceBinding declaringClass = field.original().declaringClass;
          MethodScope methodScope = scope.methodScope();
          SourceTypeBinding sourceType = methodScope.enclosingSourceType();
          if ((this.bits & ASTNode.IsStrictlyAssigned) == 0
              && sourceType == declaringClass
              && methodScope.lastVisibleFieldID >= 0
              && field.id >= methodScope.lastVisibleFieldID
              && (!field.isStatic() || methodScope.isStatic)) {
View Full Code Here

          this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits
          this.bits |= Binding.FIELD;
          FieldBinding fieldBinding = (FieldBinding) this.binding;
          MethodScope methodScope = scope.methodScope();
          ReferenceBinding declaringClass = fieldBinding.original().declaringClass;
          SourceTypeBinding sourceType = methodScope.enclosingSourceType();
          // check for forward references
          if ((this.indexOfFirstFieldBinding == 1 || (fieldBinding.modifiers & ClassFileConstants.AccEnum) != 0) // enum constants are checked even when qualified
              && sourceType == declaringClass
              && methodScope.lastVisibleFieldID >= 0
              && fieldBinding.id >= methodScope.lastVisibleFieldID
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

  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

  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

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.