Package org.eclipse.jdt.internal.ui.text.correction

Examples of org.eclipse.jdt.internal.ui.text.correction.AssistContext


    IFile file = (IFile) type.getResource();
    viewer = getViewer(file);
  }

  protected ASTNode getASTNode(ISourceRange sourceRange, IType type, ISourceViewer viewer) {
    AssistContext assistContext = new AssistContext(type.getCompilationUnit(), viewer, sourceRange.getOffset(),
        sourceRange.getLength());
    return assistContext.getCoveringNode();
  }
View Full Code Here


    ITextViewer viewer = javaContext.getViewer();
    if (viewer instanceof SourceViewer) {
      ICompilationUnit cu = javaContext.getCompilationUnit();
      SourceViewer sourceViewer = (SourceViewer) javaContext.getViewer();
      int invocationOffset = javaContext.getInvocationOffset();
      AssistContext assistContext = new AssistContext(cu, sourceViewer, invocationOffset, 0);
      ASTNode node = ((SourceRefElement) a).findNode(assistContext.getASTRoot());

      if (node == null) {
        node = assistContext.getCoveredNode();
      }

      if (!(a instanceof Annotation)) {
        return Collections.emptyList();
      }
      Annotation annotation = (Annotation) a;

      LocationInformation locationInfo = null;
      if (node instanceof NormalAnnotation) {
        NormalAnnotation normalAnnotation = (NormalAnnotation) node;
        @SuppressWarnings("unchecked")
        List<MemberValuePair> pairs = normalAnnotation.values();

        for (MemberValuePair pair : pairs) {
          Expression expression = pair.getValue();
          if (expression instanceof StringLiteral) {
            locationInfo = getLocationInformation((StringLiteral) expression, javaContext);
          }
        }
      }
      else if (node instanceof SingleMemberAnnotation) {
        SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation) node;
        Expression expression = singleMemberAnnotation.getValue();
        locationInfo = getLocationInformation((StringLiteral) expression, javaContext);
      }

      if (locationInfo == null) {
        return Collections.emptyList();
      }
      // if (viewer instanceof SourceViewer) {
      //
      // // check for annotation to avoid performance overhead in all
      // other
      // // cases
      // if (ProposalCalculatorUtil.hasAnnotationInParameters(method,
      // "Qualifier")) {

      ISourceRange methodSourceRange = method.getSourceRange();
      assistContext = new AssistContext(javaContext.getCompilationUnit(), sourceViewer,
          methodSourceRange.getOffset(), methodSourceRange.getLength());
      node = assistContext.getCoveringNode();
      if (node instanceof MethodDeclaration) {
        MethodDeclaration methodDecl = (MethodDeclaration) node;
        @SuppressWarnings("unchecked")
        List<SingleVariableDeclaration> parameters = methodDecl.parameters();
        for (SingleVariableDeclaration parameter : parameters) {
View Full Code Here

    ITextViewer viewer = javaContext.getViewer();
    if (viewer instanceof SourceViewer) {
      ICompilationUnit cu = javaContext.getCompilationUnit();
      SourceViewer sourceViewer = (SourceViewer) javaContext.getViewer();
      int invocationOffset = javaContext.getInvocationOffset();
      AssistContext assistContext = new AssistContext(cu, sourceViewer, invocationOffset, 0);
      ASTNode node = ((SourceRefElement) a).findNode(assistContext.getASTRoot());

      if (node == null) {
        node = assistContext.getCoveredNode();
      }

      LocationInformation locationInfo = null;
      if (node instanceof NormalAnnotation) {
        NormalAnnotation normalAnnotation = (NormalAnnotation) node;
        @SuppressWarnings("unchecked")
        List<MemberValuePair> pairs = normalAnnotation.values();

        for (MemberValuePair pair : pairs) {
          Expression expression = pair.getValue();
          if (expression instanceof StringLiteral) {
            locationInfo = getLocationInformation((StringLiteral) expression, javaContext);
          }
        }
      }
      else if (node instanceof SingleMemberAnnotation) {
        SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation) node;
        Expression expression = singleMemberAnnotation.getValue();
        locationInfo = getLocationInformation((StringLiteral) expression, javaContext);
      }

      if (locationInfo == null) {
        return Collections.emptyList();
      }

      ISourceRange fieldSourceRange = field.getSourceRange();
      assistContext = new AssistContext(javaContext.getCompilationUnit(), sourceViewer,
          fieldSourceRange.getOffset(), fieldSourceRange.getLength());
      node = assistContext.getCoveringNode();
      if (node instanceof FieldDeclaration) {
        // int invocationOffset = javaContext.getInvocationOffset();
        FieldDeclaration fieldDecl = (FieldDeclaration) node;
        // Set<Annotation> annotations =
        // ProposalCalculatorUtil.findAnnotations("Qualifier",
View Full Code Here

          if (start > 0) {
            if (document.getChar(start - 1) == '@') {
              String annotation = document.get(start, end - start);
              if ("qualifier".startsWith(annotation.toLowerCase())) {
                if (viewer instanceof ISourceViewer) {
                  AssistContext assistContext = new AssistContext(javaContext.getCompilationUnit(),
                      (ISourceViewer) viewer, start - 1, end - start + 1);
                  ASTNode annotationNode = assistContext.getCoveredNode();
                  BodyDeclaration decl = getParentDeclaration(annotationNode);

                  if (decl instanceof FieldDeclaration) {
                    // FieldDeclaration fieldDecl =
                    // (FieldDeclaration) decl;
View Full Code Here

    ITextViewer viewer = javaContext.getViewer();
    if (viewer instanceof SourceViewer) {
      ICompilationUnit cu = javaContext.getCompilationUnit();
      SourceViewer sourceViewer = (SourceViewer) javaContext.getViewer();
      int invocationOffset = javaContext.getInvocationOffset();
      AssistContext assistContext = new AssistContext(cu, sourceViewer, invocationOffset, 0,
          SharedASTProvider.WAIT_NO);
      ASTNode node = ((SourceRefElement) a).findNode(assistContext.getASTRoot());

      if (node == null) {
        node = assistContext.getCoveredNode();
      }

      if (!(node instanceof Annotation)) {
        return proposals;
      }

      LocationInformation locationInfo = null;
      if (node instanceof NormalAnnotation) {
        NormalAnnotation normalAnnotation = (NormalAnnotation) node;
        @SuppressWarnings("unchecked")
        List<MemberValuePair> pairs = normalAnnotation.values();

        for (MemberValuePair pair : pairs) {
          Expression expression = pair.getValue();
          if (expression instanceof StringLiteral) {
            locationInfo = getLocationInformation((StringLiteral) expression, javaContext);
          }
        }
      }
      else if (node instanceof SingleMemberAnnotation) {
        SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation) node;
        Expression expression = singleMemberAnnotation.getValue();
        if (expression instanceof StringLiteral) {
          locationInfo = getLocationInformation((StringLiteral) expression, javaContext);
        }
      }

      if (locationInfo == null) {
        return proposals;
      }

      int locationOffset = locationInfo.getOffset();
      int locationLength = locationInfo.getLength();
      String content = locationInfo.getFilter();

      if (invocationOffset >= locationOffset && invocationOffset <= locationOffset + locationLength) {
        int startIndex;
        int index = 0;
        boolean found = false;
        while (!found) {
          startIndex = content.indexOf("{");
          if (startIndex < 0 || startIndex + locationOffset >= invocationOffset) {
            break;
          }

          content = content.substring(startIndex + 1);
          index += startIndex + 1;
          if (!(content.contains("{"))) {
            found = true;
          }
        }

        locationOffset += 1; // ignore opening quote

        if (found) {
          ISourceRange sourceRange = element.getSourceRange();
          //Now get the 'real' ast.
          assistContext = new AssistContext(javaContext.getCompilationUnit(), sourceViewer,
              sourceRange.getOffset(), sourceRange.getLength(), SharedASTProvider.WAIT_YES);

          node = assistContext.getCoveringNode();
          Annotation annotation = (Annotation) ((SourceRefElement) a).findNode(assistContext.getASTRoot());

          if (content.endsWith("}")) {
            content = content.substring(0, content.length() - 1);
          }
View Full Code Here

      ICompilationUnit compilationUnit = getCompilationUnit(variable);
      file = (IFile) compilationUnit.getResource();

      try {
        ISourceRange sourceRange = variable.getSourceRange();
        AssistContext assistContext = new AssistContext(compilationUnit, null, sourceRange.getOffset(),
            sourceRange.getLength());
        ASTNode node = assistContext.getCoveringNode();

        if (node instanceof SingleVariableDeclaration) {
          SingleVariableDeclaration varDecl = (SingleVariableDeclaration) node;
          Set<Annotation> annotations = ProposalCalculatorUtil.findAnnotations("PathVariable", varDecl);
          SimpleName varDeclName = varDecl.getName();
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.ui.text.correction.AssistContext

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.