Package org.eclipse.jdt.internal.compiler.impl

Examples of org.eclipse.jdt.internal.compiler.impl.ReferenceContext


  public final boolean isDefinedInMethod(MethodBinding method) {
    method = method.original(); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=350738
    Scope scope = this;
    do {
      if (scope instanceof MethodScope) {
        ReferenceContext refContext = ((MethodScope) scope).referenceContext;
        if (refContext instanceof AbstractMethodDeclaration)
          if (((AbstractMethodDeclaration) refContext).binding == method)
            return true;
      }
      scope = scope.parent;
View Full Code Here


      if(this.typePtr > -1) {
        length = this.typePtr + 1;
        foundTypes = new TypeDeclaration[length];
        System.arraycopy(this.types, 0, foundTypes, 0, length);
      }
      ReferenceContext oldContext = Parser.this.referenceContext;
      Parser.this.recoveryScanner.resetTo(initializer.bodyStart, initializer.bodyEnd);
      Scanner oldScanner = Parser.this.scanner;
      Parser.this.scanner = Parser.this.recoveryScanner;
      parseStatements(
          this.enclosingType,
View Full Code Here

      if(this.typePtr > -1) {
        length = this.typePtr + 1;
        foundTypes = new TypeDeclaration[length];
        System.arraycopy(this.types, 0, foundTypes, 0, length);
      }
      ReferenceContext oldContext = Parser.this.referenceContext;
      Parser.this.recoveryScanner.resetTo(methodDeclaration.bodyStart, methodDeclaration.bodyEnd);
      Scanner oldScanner = Parser.this.scanner;
      Parser.this.scanner = Parser.this.recoveryScanner;
      parseStatements(
          methodDeclaration,
View Full Code Here

  }

  @Override
  public boolean visit(Argument argument, BlockScope scope) {
    Annotation[] annotations = argument.annotations;
    ReferenceContext referenceContext = scope.referenceContext();
    if (referenceContext instanceof AbstractMethodDeclaration) {
      MethodBinding binding = ((AbstractMethodDeclaration) referenceContext).binding;
      if (binding != null) {
        TypeDeclaration typeDeclaration = scope.referenceType();
        typeDeclaration.binding.resolveTypesFor(binding);
View Full Code Here

   * and filename will be set to null.
   * @return
   */
  public static AptProblem createProblem(Kind kind, CharSequence msg, Element e,
      AnnotationMirror a, AnnotationValue v) {
    ReferenceContext referenceContext = null;
    Annotation[] elementAnnotations = null;
    int startPosition = 0;
    int endPosition = 0;
    if (e != null) {
      switch(e.getKind()) {
        case ANNOTATION_TYPE :
        case INTERFACE :
        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;
              endPosition = fieldDeclaration.sourceEnd;
            }
          } else if (binding instanceof AptSourceLocalVariableBinding){
            AptSourceLocalVariableBinding parameterBinding = (AptSourceLocalVariableBinding) binding;
            LocalDeclaration parameterDeclaration = parameterBinding.declaration;
            if (parameterDeclaration != null) {
              MethodBinding methodBinding = parameterBinding.methodBinding;
              if (methodBinding != null) {
                referenceContext = methodBinding.sourceMethod();
              }
              elementAnnotations = parameterDeclaration.annotations;
              startPosition = parameterDeclaration.sourceStart;
              endPosition = parameterDeclaration.sourceEnd;
            }
          }
          break;
        case INSTANCE_INIT :
        case STATIC_INIT :
          break;
        case LOCAL_VARIABLE :
          break;
        case TYPE_PARAMETER :
        default:
          break;
      }
    }
    StringBuilder builder = new StringBuilder();
    if (msg != null) {
      builder.append(msg);
    }
    if (a != null && elementAnnotations != null) {
      AnnotationBinding annotationBinding = ((AnnotationMirrorImpl) a)._binding;
      Annotation annotation = null;
      for (int i = 0; annotation == null && i < elementAnnotations.length; i++) {
        if (annotationBinding == elementAnnotations[i].getCompilerAnnotation()) {
          annotation = elementAnnotations[i];
        }
      }
      if (annotation != null) {
        startPosition = annotation.sourceStart;
        endPosition = annotation.sourceEnd;
        if (v != null && v instanceof AnnotationMemberValue) {
          MethodBinding methodBinding = ((AnnotationMemberValue) v).getMethodBinding();
          MemberValuePair[] memberValuePairs = annotation.memberValuePairs();
          MemberValuePair memberValuePair = null;
          for (int i = 0; memberValuePair == null && i < memberValuePairs.length; i++) {
            if (methodBinding == memberValuePairs[i].binding) {
              memberValuePair = memberValuePairs[i];
            }
          }
          if (memberValuePair != null) {
            startPosition = memberValuePair.sourceStart;
            endPosition = memberValuePair.sourceEnd;
          }
        }
      }
    }
    int lineNumber = 0;
    int columnNumber = 1;
    char[] fileName = null;
    if (referenceContext != null) {
      CompilationResult result = referenceContext.compilationResult();
      fileName = result.fileName;
      int[] lineEnds = null;
      lineNumber = startPosition >= 0
          ? Util.getLineNumber(startPosition, lineEnds = result.getLineSeparatorPositions(), 0, lineEnds.length-1)
          : 0;
View Full Code Here

   * @return a String, or null if the comment is not available
   */
  private char[] getUnparsedDocComment(Element e)
  {
    Javadoc javadoc = null;
    ReferenceContext referenceContext = null;
    switch(e.getKind()) {
      case ANNOTATION_TYPE :
      case CLASS :
      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;
          }
        }
        break;
      default:
        return null;
    }
    if (javadoc != null && referenceContext != null) {
      char[] contents = referenceContext.compilationResult().getCompilationUnit().getContents();
      if (contents != null) {
        return CharOperation.subarray(contents, javadoc.sourceStart, javadoc.sourceEnd - 1);
      }
    }
    return null;
View Full Code Here

      }
    }
    this.resolvedType = returnType;
  }
  if (this.receiver.isSuper() && compilerOptions.getSeverity(CompilerOptions.OverridingMethodWithoutSuperInvocation) != ProblemSeverities.Ignore) {
    final ReferenceContext referenceContext = scope.methodScope().referenceContext;
    if (referenceContext instanceof AbstractMethodDeclaration) {
      final AbstractMethodDeclaration abstractMethodDeclaration = (AbstractMethodDeclaration) referenceContext;
      MethodBinding enclosingMethodBinding = abstractMethodDeclaration.binding;
      if (enclosingMethodBinding.isOverriding()
          && CharOperation.equals(this.binding.selector, enclosingMethodBinding.selector)
View Full Code Here

  public final boolean isDefinedInMethod(MethodBinding method) {
    method = method.original(); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=350738
    Scope scope = this;
    do {
      if (scope instanceof MethodScope) {
        ReferenceContext refContext = ((MethodScope) scope).referenceContext;
        if (refContext instanceof AbstractMethodDeclaration)
          if (((AbstractMethodDeclaration) refContext).binding == method)
            return true;
      }
      scope = scope.parent;
View Full Code Here

  }

  if (type.isParameterizedType()) {
    List missingTypes = type.collectMissingTypes(null);
    if (missingTypes != null) {
      ReferenceContext savedContext = this.referenceContext;
      for (Iterator iterator = missingTypes.iterator(); iterator.hasNext(); ) {
        try {
          invalidType(location, (TypeBinding) iterator.next());
        } finally {
          this.referenceContext = savedContext;
View Full Code Here

      if(this.typePtr > -1) {
        length = this.typePtr + 1;
        foundTypes = new TypeDeclaration[length];
        System.arraycopy(this.types, 0, foundTypes, 0, length);
      }
      ReferenceContext oldContext = Parser.this.referenceContext;
      Parser.this.recoveryScanner.resetTo(initializer.bodyStart, initializer.bodyEnd);
      Scanner oldScanner = Parser.this.scanner;
      Parser.this.scanner = Parser.this.recoveryScanner;
      parseStatements(
          this.enclosingType,
          initializer.bodyStart,
          initializer.bodyEnd,
          foundTypes,
          Parser.this.compilationUnit);
      Parser.this.scanner = oldScanner;
      Parser.this.referenceContext = oldContext;

      for (int i = 0; i < length; i++) {
        foundTypes[i].traverse(this.typeVisitor, scope);
      }
    }
    public void endVisit(MethodDeclaration methodDeclaration, ClassScope scope) {
      endVisitMethod(methodDeclaration, scope);
    }
    private void endVisitMethod(AbstractMethodDeclaration methodDeclaration, ClassScope scope) {
      TypeDeclaration[] foundTypes = null;
      int length = 0;
      if(this.typePtr > -1) {
        length = this.typePtr + 1;
        foundTypes = new TypeDeclaration[length];
        System.arraycopy(this.types, 0, foundTypes, 0, length);
      }
      ReferenceContext oldContext = Parser.this.referenceContext;
      Parser.this.recoveryScanner.resetTo(methodDeclaration.bodyStart, methodDeclaration.bodyEnd);
      Scanner oldScanner = Parser.this.scanner;
      Parser.this.scanner = Parser.this.recoveryScanner;
      parseStatements(
          methodDeclaration,
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.impl.ReferenceContext

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.