Java 类org.eclipse.jdt.core.dom.Initializer 实例源码

项目:eclipse.jdt.ls    文件:ExtractMethodRefactoring.java   
private void initializeDestinations() {
    List<ASTNode> result = new ArrayList<>();
    BodyDeclaration decl = fAnalyzer.getEnclosingBodyDeclaration();
    ASTNode current = ASTResolving.findParentType(decl.getParent());
    if (fAnalyzer.isValidDestination(current)) {
        result.add(current);
    }
    if (current != null && (decl instanceof MethodDeclaration || decl instanceof Initializer || decl instanceof FieldDeclaration)) {
        ITypeBinding binding = ASTNodes.getEnclosingType(current);
        ASTNode next = ASTResolving.findParentType(current.getParent());
        while (next != null && binding != null && binding.isNested()) {
            if (fAnalyzer.isValidDestination(next)) {
                result.add(next);
            }
            current = next;
            binding = ASTNodes.getEnclosingType(current);
            next = ASTResolving.findParentType(next.getParent());
        }
    }
    fDestinations = result.toArray(new ASTNode[result.size()]);
    fDestination = fDestinations[fDestinationIndex];
}
项目:che    文件:RenameLocalVariableProcessor.java   
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
  initAST();
  if (fTempDeclarationNode == null || fTempDeclarationNode.resolveBinding() == null)
    return RefactoringStatus.createFatalErrorStatus(
        RefactoringCoreMessages.RenameTempRefactoring_must_select_local);

  if (!Checks.isDeclaredIn(fTempDeclarationNode, MethodDeclaration.class)
      && !Checks.isDeclaredIn(fTempDeclarationNode, Initializer.class)
      && !Checks.isDeclaredIn(fTempDeclarationNode, LambdaExpression.class)) {
    if (JavaModelUtil.is18OrHigher(fCu.getJavaProject()))
      return RefactoringStatus.createFatalErrorStatus(
          RefactoringCoreMessages.RenameTempRefactoring_only_in_methods_initializers_and_lambda);

    return RefactoringStatus.createFatalErrorStatus(
        RefactoringCoreMessages.RenameTempRefactoring_only_in_methods_and_initializers);
  }

  initNames();
  return new RefactoringStatus();
}
项目:che    文件:ExtractMethodRefactoring.java   
private void initializeDestinations() {
  List<ASTNode> result = new ArrayList<ASTNode>();
  BodyDeclaration decl = fAnalyzer.getEnclosingBodyDeclaration();
  ASTNode current = ASTResolving.findParentType(decl.getParent());
  if (fAnalyzer.isValidDestination(current)) {
    result.add(current);
  }
  if (current != null
      && (decl instanceof MethodDeclaration
          || decl instanceof Initializer
          || decl instanceof FieldDeclaration)) {
    ITypeBinding binding = ASTNodes.getEnclosingType(current);
    ASTNode next = ASTResolving.findParentType(current.getParent());
    while (next != null && binding != null && binding.isNested()) {
      if (fAnalyzer.isValidDestination(next)) {
        result.add(next);
      }
      current = next;
      binding = ASTNodes.getEnclosingType(current);
      next = ASTResolving.findParentType(next.getParent());
    }
  }
  fDestinations = result.toArray(new ASTNode[result.size()]);
  fDestination = fDestinations[fDestinationIndex];
}
项目:che    文件:ExtractConstantRefactoring.java   
private void computeConstantDeclarationLocation() throws JavaModelException {
  if (isDeclarationLocationComputed()) return;

  BodyDeclaration lastStaticDependency = null;
  Iterator<BodyDeclaration> decls =
      getContainingTypeDeclarationNode().bodyDeclarations().iterator();

  while (decls.hasNext()) {
    BodyDeclaration decl = decls.next();

    int modifiers;
    if (decl instanceof FieldDeclaration) modifiers = ((FieldDeclaration) decl).getModifiers();
    else if (decl instanceof Initializer) modifiers = ((Initializer) decl).getModifiers();
    else {
      continue; /* this declaration is not a field declaration
                or initializer, so the placement of the constant
                declaration relative to it does not matter */
    }

    if (Modifier.isStatic(modifiers) && depends(getSelectedExpression(), decl))
      lastStaticDependency = decl;
  }

  if (lastStaticDependency == null) fInsertFirst = true;
  else fToInsertAfter = lastStaticDependency;
}
项目:che    文件:ExtractConstantRefactoring.java   
private static boolean isStaticFieldOrStaticInitializer(BodyDeclaration node) {
  if (node instanceof MethodDeclaration || node instanceof AbstractTypeDeclaration) return false;

  int modifiers;
  if (node instanceof FieldDeclaration) {
    modifiers = ((FieldDeclaration) node).getModifiers();
  } else if (node instanceof Initializer) {
    modifiers = ((Initializer) node).getModifiers();
  } else {
    Assert.isTrue(false);
    return false;
  }

  if (!Modifier.isStatic(modifiers)) return false;

  return true;
}
项目:che    文件:NullAnnotationsCorrectionProcessor.java   
/**
 * Fix for {@link IProblem#NullableFieldReference}
 *
 * @param context context
 * @param problem problem to be fixed
 * @param proposals accumulator for computed proposals
 */
public static void addExtractCheckedLocalProposal(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
  CompilationUnit compilationUnit = context.getASTRoot();
  ICompilationUnit cu = (ICompilationUnit) compilationUnit.getJavaElement();

  ASTNode selectedNode = problem.getCoveringNode(compilationUnit);

  SimpleName name = findProblemFieldName(selectedNode, problem.getProblemId());
  if (name == null) return;

  ASTNode method = ASTNodes.getParent(selectedNode, MethodDeclaration.class);
  if (method == null) method = ASTNodes.getParent(selectedNode, Initializer.class);
  if (method == null) return;

  proposals.add(new ExtractToNullCheckedLocalProposal(cu, compilationUnit, name, method));
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameLocalVariableProcessor.java   
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
    initAST();
    if (fTempDeclarationNode == null || fTempDeclarationNode.resolveBinding() == null)
        return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.RenameTempRefactoring_must_select_local);

    if (!Checks.isDeclaredIn(fTempDeclarationNode, MethodDeclaration.class)
            && !Checks.isDeclaredIn(fTempDeclarationNode, Initializer.class)
            && !Checks.isDeclaredIn(fTempDeclarationNode, LambdaExpression.class)) {
        if (JavaModelUtil.is18OrHigher(fCu.getJavaProject()))
            return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.RenameTempRefactoring_only_in_methods_initializers_and_lambda);

        return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.RenameTempRefactoring_only_in_methods_and_initializers);
    }

    initNames();
    return new RefactoringStatus();
}
项目:Eclipse-Postfix-Code-Completion    文件:ExtractMethodRefactoring.java   
private void initializeDestinations() {
    List<ASTNode> result= new ArrayList<ASTNode>();
    BodyDeclaration decl= fAnalyzer.getEnclosingBodyDeclaration();
    ASTNode current= ASTResolving.findParentType(decl.getParent());
    if (fAnalyzer.isValidDestination(current)) {
        result.add(current);
    }
    if (current != null && (decl instanceof MethodDeclaration || decl instanceof Initializer || decl instanceof FieldDeclaration)) {
        ITypeBinding binding= ASTNodes.getEnclosingType(current);
        ASTNode next= ASTResolving.findParentType(current.getParent());
        while (next != null && binding != null && binding.isNested()) {
            if (fAnalyzer.isValidDestination(next)) {
                result.add(next);
            }
            current= next;
            binding= ASTNodes.getEnclosingType(current);
            next= ASTResolving.findParentType(next.getParent());
        }
    }
    fDestinations= result.toArray(new ASTNode[result.size()]);
    fDestination= fDestinations[fDestinationIndex];
}
项目:Eclipse-Postfix-Code-Completion    文件:ExtractConstantRefactoring.java   
private static boolean isStaticFieldOrStaticInitializer(BodyDeclaration node) {
    if(node instanceof MethodDeclaration || node instanceof AbstractTypeDeclaration)
        return false;

    int modifiers;
    if(node instanceof FieldDeclaration) {
        modifiers = ((FieldDeclaration) node).getModifiers();
    } else if(node instanceof Initializer) {
        modifiers = ((Initializer) node).getModifiers();
    } else {
        Assert.isTrue(false);
        return false;
    }

    if(!Modifier.isStatic(modifiers))
        return false;

    return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:NullAnnotationsCorrectionProcessor.java   
/**
 * Fix for {@link IProblem#NullableFieldReference}
 * @param context context
 * @param problem problem to be fixed
 * @param proposals accumulator for computed proposals
 */
public static void addExtractCheckedLocalProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    CompilationUnit compilationUnit = context.getASTRoot();
    ICompilationUnit cu= (ICompilationUnit) compilationUnit.getJavaElement();

    ASTNode selectedNode= problem.getCoveringNode(compilationUnit);

    SimpleName name= findProblemFieldName(selectedNode, problem.getProblemId());
    if (name == null)
        return;

    ASTNode method= ASTNodes.getParent(selectedNode, MethodDeclaration.class);
    if (method == null)
        method= ASTNodes.getParent(selectedNode, Initializer.class);
    if (method == null)
        return;

    proposals.add(new ExtractToNullCheckedLocalProposal(cu, compilationUnit, name, method));
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ExtractMethodAnalyzer.java   
private void computeLastStatementSelected() {
    ASTNode[] nodes= getSelectedNodes();
    if (nodes.length == 0) {
        fIsLastStatementSelected= false;
    } else {
        Block body= null;
        if (fEnclosingBodyDeclaration instanceof MethodDeclaration) {
            body= ((MethodDeclaration) fEnclosingBodyDeclaration).getBody();
        } else if (fEnclosingBodyDeclaration instanceof Initializer) {
            body= ((Initializer) fEnclosingBodyDeclaration).getBody();
        }
        if (body != null) {
            List<Statement> statements= body.statements();
            fIsLastStatementSelected= nodes[nodes.length - 1] == statements.get(statements.size() - 1);
        }
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ExtractMethodRefactoring.java   
private void initializeDestinations() {
    List<ASTNode> result= new ArrayList<ASTNode>();
    BodyDeclaration decl= fAnalyzer.getEnclosingBodyDeclaration();
    ASTNode current= getNextParent(decl);
    result.add(current);
    if (decl instanceof MethodDeclaration || decl instanceof Initializer || decl instanceof FieldDeclaration) {
        ITypeBinding binding= ASTNodes.getEnclosingType(current);
        ASTNode next= getNextParent(current);
        while (next != null && binding != null && binding.isNested()) {
            result.add(next);
            current= next;
            binding= ASTNodes.getEnclosingType(current);
            next= getNextParent(next);
        }
    }
    fDestinations= result.toArray(new ASTNode[result.size()]);
    fDestination= fDestinations[fDestinationIndex];
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ExtractConstantRefactoring.java   
private static boolean isStaticFieldOrStaticInitializer(BodyDeclaration node) {
    if(node instanceof MethodDeclaration || node instanceof AbstractTypeDeclaration)
        return false;

    int modifiers;
    if(node instanceof FieldDeclaration) {
        modifiers = ((FieldDeclaration) node).getModifiers();
    } else if(node instanceof Initializer) {
        modifiers = ((Initializer) node).getModifiers();
    } else {
        Assert.isTrue(false);
        return false;
    }

    if(!Modifier.isStatic(modifiers))
        return false;

    return true;
}
项目:jive    文件:StaticModelFactoryAdapterForAST.java   
private int lineFromNumber(final ASTNode node)
{
  int nodeStart = node.getStartPosition();
  /**
   * Skip the java documentation in body declaration nodes.
   */
  if (node instanceof AbstractTypeDeclaration)
  {
    nodeStart = ((AbstractTypeDeclaration) node).getName().getStartPosition();
  }
  else if (node instanceof EnumConstantDeclaration)
  {
    nodeStart = ((EnumConstantDeclaration) node).getName().getStartPosition();
  }
  else if (node instanceof Initializer)
  {
    nodeStart = ((Initializer) node).getBody().getStartPosition();
  }
  else if (node instanceof MethodDeclaration)
  {
    nodeStart = ((MethodDeclaration) node).getName().getStartPosition();
  }
  return ASTTools.lineNumber(node, nodeStart);
}
项目:jive    文件:StatementVisitor.java   
/**
 * Type or instance initializer (entry point).
 * 
 * ['static'] '{' statement '}'
 */
@Override
public boolean visit(final Initializer node)
{
  // initializers are processed only at the top level
  if (mdg.parent() != null)
  {
    return false;
  }
  final int lineNo = lineStart(node);
  // new dependence
  createDependence(LK_INITIALIZER, lineNo, mdg.parent());
  // recursively append "body" dependences
  if (node.getBody() != null)
  {
    appendRecursive(lineNo, mdg.parent(), node.getBody());
    processJumpDependences();
  }
  // visit children
  return false;
}
项目:byteman-editor    文件:JavaUtils.java   
public static IMember getMemberFromOffset(ITextEditor javaEditor, int offset) throws JavaModelException {
    ITypeRoot element= JavaUI.getEditorInputTypeRoot(javaEditor.getEditorInput());
    CompilationUnit ast = SharedASTProvider.getAST(element, SharedASTProvider.WAIT_YES, null);
    NodeFinder finder= new NodeFinder(ast, offset, 0);
    ASTNode node= finder.getCoveringNode();

    while(node != null) {
        if(node instanceof Initializer) {
            TypeDeclaration typeDeclaration = (TypeDeclaration) node.getParent();
            IType type = (IType) typeDeclaration.resolveBinding().getJavaElement();
            for(IInitializer initializer : type.getInitializers()) {
                if(node.getStartPosition() == initializer.getSourceRange().getOffset()
                        && Flags.isStatic(initializer.getFlags())) {
                    return initializer;
                }
            }
        }
        if(node instanceof MethodDeclaration) {
            IMethodBinding binding = ((MethodDeclaration) node).resolveBinding();
            return (IMethod) binding.getJavaElement();
        }
        node = node.getParent();
    }
    return null;
}
项目:eclipse.jdt.ls    文件:FlowAnalyzer.java   
@Override
public void endVisit(Initializer node) {
    if (skipNode(node)) {
        return;
    }
    assignFlowInfo(node, node.getBody());
}
项目:eclipse.jdt.ls    文件:SurroundWithAnalyzer.java   
@Override
public void endVisit(CompilationUnit node) {
    postProcessSelectedNodes(internalGetSelectedNodes());
    ASTNode enclosingNode = null;
    superCall: {
        if (getStatus().hasFatalError()) {
            break superCall;
        }
        if (!hasSelectedNodes()) {
            ASTNode coveringNode = getLastCoveringNode();
            if (coveringNode instanceof Block) {
                Block block = (Block) coveringNode;
                Message[] messages = ASTNodes.getMessages(block, ASTNodes.NODE_ONLY);
                if (messages.length > 0) {
                    invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_compile_errors, JavaStatusContext.create(getCompilationUnit(), block));
                    break superCall;
                }
            }
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotCover);
            break superCall;
        }
        enclosingNode = getEnclosingNode(getFirstSelectedNode());
        boolean isValidEnclosingNode = enclosingNode instanceof MethodDeclaration || enclosingNode instanceof Initializer;
        if (fSurroundWithTryCatch) {
            isValidEnclosingNode = isValidEnclosingNode || enclosingNode instanceof MethodReference || enclosingNode.getLocationInParent() == LambdaExpression.BODY_PROPERTY;
        }
        if (!isValidEnclosingNode) {
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotContain);
            break superCall;
        }
        if (!validSelectedNodes()) {
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_onlyStatements);
        }
        fLocals = LocalDeclarationAnalyzer.perform(enclosingNode, getSelection());
    }
    super.endVisit(node);
}
项目:che    文件:ScopeAnalyzer.java   
private boolean addLocalDeclarations(
    ASTNode node, int offset, int flags, IBindingRequestor requestor) {
  if (hasFlag(VARIABLES, flags) || hasFlag(TYPES, flags)) {
    BodyDeclaration declaration = ASTResolving.findParentBodyDeclaration(node);
    if (declaration instanceof MethodDeclaration
        || declaration instanceof Initializer
        || declaration instanceof FieldDeclaration) {
      ScopeAnalyzerVisitor visitor = new ScopeAnalyzerVisitor(offset, flags, requestor);
      declaration.accept(visitor);
      return visitor.fBreak;
    }
  }
  return false;
}
项目:che    文件:CodeStyleFix.java   
private void handleVariable(SimpleName node, IVariableBinding varbinding) {
  if (!varbinding.isField()) return;

  if (varbinding.isEnumConstant()) return;

  ITypeBinding declaringClass = varbinding.getDeclaringClass();
  if (Modifier.isStatic(varbinding.getModifiers())) {
    if (fFindUnqualifiedStaticAccesses) {
      Initializer initializer = (Initializer) ASTNodes.getParent(node, Initializer.class);
      // Do not qualify assignments to static final fields in static initializers (would result
      // in compile error)
      StructuralPropertyDescriptor parentDescription = node.getLocationInParent();
      if (initializer != null
          && Modifier.isStatic(initializer.getModifiers())
          && Modifier.isFinal(varbinding.getModifiers())
          && parentDescription == Assignment.LEFT_HAND_SIDE_PROPERTY) return;

      // Do not qualify static fields if defined inside an anonymous class
      if (declaringClass.isAnonymous()) return;

      fResult.add(new AddStaticQualifierOperation(declaringClass, node));
    }
  } else if (fFindUnqualifiedAccesses) {
    String qualifier = getThisExpressionQualifier(declaringClass, fImportRewrite, node);
    if (qualifier == null) return;

    if (qualifier.length() == 0) qualifier = null;

    fResult.add(new AddThisQualifierOperation(qualifier, node));
  }
}
项目:che    文件:ASTNodeSearchUtil.java   
public static Initializer getInitializerNode(IInitializer initializer, CompilationUnit cuNode)
    throws JavaModelException {
  ASTNode node = findNode(initializer.getSourceRange(), cuNode);
  if (node instanceof Initializer) return (Initializer) node;
  if (node instanceof Block && node.getParent() instanceof Initializer)
    return (Initializer) node.getParent();
  return null;
}
项目:che    文件:ConvertAnonymousToNestedRefactoring.java   
private void updateAndMoveBodyDeclarations(
    CompilationUnitRewrite rewriter,
    IVariableBinding[] bindings,
    String[] fieldNames,
    List<BodyDeclaration> newBodyDeclarations,
    MethodDeclaration newConstructorDecl) {
  final ASTRewrite astRewrite = rewriter.getASTRewrite();
  final AST ast = astRewrite.getAST();

  final boolean useThisAccess = useThisForFieldAccess();

  int fieldInsertIndex =
      newConstructorDecl != null
          ? newBodyDeclarations.lastIndexOf(newConstructorDecl)
          : newBodyDeclarations.size();

  for (Iterator<BodyDeclaration> iterator =
          fAnonymousInnerClassNode.bodyDeclarations().iterator();
      iterator.hasNext(); ) {
    BodyDeclaration body = iterator.next();

    for (int i = 0; i < bindings.length; i++) {
      SimpleName[] names = LinkedNodeFinder.findByBinding(body, bindings[i]);
      String fieldName = fieldNames[i];
      for (int k = 0; k < names.length; k++) {
        SimpleName newNode = ast.newSimpleName(fieldName);
        if (useThisAccess) {
          FieldAccess access = ast.newFieldAccess();
          access.setExpression(ast.newThisExpression());
          access.setName(newNode);
          astRewrite.replace(names[k], access, null);
        } else {
          astRewrite.replace(names[k], newNode, null);
        }
        addLinkedPosition(KEY_FIELD_NAME_EXT + i, newNode, astRewrite, false);
      }
    }
    if (body instanceof Initializer || body instanceof FieldDeclaration) {
      newBodyDeclarations.add(
          fieldInsertIndex++, (BodyDeclaration) astRewrite.createMoveTarget(body));
    } else {
      newBodyDeclarations.add((BodyDeclaration) astRewrite.createMoveTarget(body));
    }
  }

  if (newConstructorDecl != null) {
    // move initialization of existing fields to constructor if an outer is referenced
    List<Statement> bodyStatements = newConstructorDecl.getBody().statements();

    List<VariableDeclarationFragment> fieldsToInitializeInConstructor =
        getFieldsToInitializeInConstructor();
    for (Iterator<VariableDeclarationFragment> iter = fieldsToInitializeInConstructor.iterator();
        iter.hasNext(); ) {
      VariableDeclarationFragment fragment = iter.next();
      Expression initializer = fragment.getInitializer();
      Expression replacement =
          (Expression) astRewrite.get(fragment, VariableDeclarationFragment.INITIALIZER_PROPERTY);
      if (replacement == initializer) {
        replacement = (Expression) astRewrite.createMoveTarget(initializer);
      }
      astRewrite.remove(initializer, null);
      SimpleName fieldNameNode = ast.newSimpleName(fragment.getName().getIdentifier());
      bodyStatements.add(newFieldAssignment(ast, fieldNameNode, replacement, useThisAccess));
    }
  }
}
项目:che    文件:TargetProvider.java   
@Override
public void endVisit(Initializer node) {
  if (fCurrent.hasInvocations()) {
    result.put(node, fCurrent);
  }
  endVisitBodyDeclaration();
}
项目:che    文件:ExtractTempRefactoring.java   
private Block getEnclosingBodyNode() throws JavaModelException {
  ASTNode node = getSelectedExpression().getAssociatedNode();

  // expression must be in a method or initializer body
  // make sure it is not in method or parameter annotation
  StructuralPropertyDescriptor location = null;
  while (node != null && !(node instanceof BodyDeclaration)) {
    location = node.getLocationInParent();
    node = node.getParent();
  }
  if (location == MethodDeclaration.BODY_PROPERTY || location == Initializer.BODY_PROPERTY) {
    return (Block) node.getStructuralProperty(location);
  }
  return null;
}
项目:eclipsemembersort    文件:MemberComparator.java   
private Member _createMember(BodyDeclaration declaration) {
    List<String> modifiers = new ArrayList<>();

    for (Object modifier : declaration.modifiers()) {
        modifiers.add(modifier.toString());
    }

    StringBuilder sb = new StringBuilder();

    _getVisibility(sb, modifiers);
    _getModifiers(sb, modifiers);

    if (declaration instanceof FieldDeclaration) {
        return _getFieldType((FieldDeclaration)declaration, sb);
    }

    if (declaration instanceof MethodDeclaration) {
        return _getMethodType((MethodDeclaration)declaration, sb);
    }

    if (declaration instanceof TypeDeclaration) {
        return _getClassType((TypeDeclaration)declaration, sb);
    }

    if (declaration instanceof Initializer) {
        return _getInitializerType((Initializer)declaration, sb);
    }

    if (declaration instanceof EnumDeclaration) {
        return _getEnumType((EnumDeclaration)declaration, sb);
    }

    return new Member("-nodata", "-nodata");
}
项目:jdt2famix    文件:AstVisitor.java   
@Override
public boolean visit(Initializer node) {
    Method method = importer.ensureInitializerMethod();
    importer.pushOnContainerStack(method);
    importer.createSourceAnchor(method, node, (CompilationUnit) node.getRoot());
    importer.ensureCommentFromBodyDeclaration(method, node);
    return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTNodeSearchUtil.java   
public static Initializer getInitializerNode(IInitializer initializer, CompilationUnit cuNode) throws JavaModelException {
    ASTNode node= findNode(initializer.getSourceRange(), cuNode);
    if (node instanceof Initializer)
        return (Initializer) node;
    if (node instanceof Block && node.getParent() instanceof Initializer)
        return (Initializer) node.getParent();
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:TargetProvider.java   
@Override
public void endVisit(Initializer node) {
    if (fCurrent.hasInvocations()) {
        result.put(node, fCurrent);
    }
    endVisitBodyDeclaration();
}
项目:Eclipse-Postfix-Code-Completion    文件:ExtractTempRefactoring.java   
private Block getEnclosingBodyNode() throws JavaModelException {
    ASTNode node= getSelectedExpression().getAssociatedNode();

    // expression must be in a method or initializer body
    // make sure it is not in method or parameter annotation
    StructuralPropertyDescriptor location= null;
    while (node != null && !(node instanceof BodyDeclaration)) {
        location= node.getLocationInParent();
        node= node.getParent();
    }
    if (location == MethodDeclaration.BODY_PROPERTY || location == Initializer.BODY_PROPERTY) {
        return (Block) node.getStructuralProperty(location);
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:ExtractConstantRefactoring.java   
private void computeConstantDeclarationLocation() throws JavaModelException {
    if (isDeclarationLocationComputed())
        return;

    BodyDeclaration lastStaticDependency= null;
    Iterator<BodyDeclaration> decls= getContainingTypeDeclarationNode().bodyDeclarations().iterator();

    while (decls.hasNext()) {
        BodyDeclaration decl= decls.next();

        int modifiers;
        if (decl instanceof FieldDeclaration)
            modifiers= ((FieldDeclaration) decl).getModifiers();
        else if (decl instanceof Initializer)
            modifiers= ((Initializer) decl).getModifiers();
        else {
            continue; /* this declaration is not a field declaration
                          or initializer, so the placement of the constant
                          declaration relative to it does not matter */
        }

        if (Modifier.isStatic(modifiers) && depends(getSelectedExpression(), decl))
            lastStaticDependency= decl;
    }

    if(lastStaticDependency == null)
        fInsertFirst= true;
    else
        fToInsertAfter= lastStaticDependency;
}
项目:Eclipse-Postfix-Code-Completion    文件:SurroundWithAnalyzer.java   
@Override
public void endVisit(CompilationUnit node) {
    postProcessSelectedNodes(internalGetSelectedNodes());
    BodyDeclaration enclosingNode= null;
    superCall: {
        if (getStatus().hasFatalError())
            break superCall;
        if (!hasSelectedNodes()) {
            ASTNode coveringNode= getLastCoveringNode();
            if (coveringNode instanceof Block) {
                Block block= (Block)coveringNode;
                Message[] messages= ASTNodes.getMessages(block, ASTNodes.NODE_ONLY);
                if (messages.length > 0) {
                    invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_compile_errors,
                        JavaStatusContext.create(getCompilationUnit(), block));
                    break superCall;
                }
            }
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotCover);
            break superCall;
        }
        enclosingNode= (BodyDeclaration)ASTNodes.getParent(getFirstSelectedNode(), BodyDeclaration.class);
        if (!(enclosingNode instanceof MethodDeclaration) && !(enclosingNode instanceof Initializer)) {
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotContain);
            break superCall;
        }
        if (!onlyStatements()) {
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_onlyStatements);
        }
        fLocals= LocalDeclarationAnalyzer.perform(enclosingNode, getSelection());
    }
    super.endVisit(node);
}
项目:Eclipse-Postfix-Code-Completion    文件:ScopeAnalyzer.java   
private boolean addLocalDeclarations(ASTNode node, int offset, int flags, IBindingRequestor requestor) {
    if (hasFlag(VARIABLES, flags) || hasFlag(TYPES, flags)) {
        BodyDeclaration declaration= ASTResolving.findParentBodyDeclaration(node);
        if (declaration instanceof MethodDeclaration || declaration instanceof Initializer || declaration instanceof FieldDeclaration) {
            ScopeAnalyzerVisitor visitor= new ScopeAnalyzerVisitor(offset, flags, requestor);
            declaration.accept(visitor);
            return visitor.fBreak;
        }
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:LocalVariableIndex.java   
private static int internalPerform(BodyDeclaration methodOrInitializer) {
    // we have to find the outermost method/initializer/field declaration since a local or anonymous
    // type can reference final variables from the outer scope.
    BodyDeclaration target= methodOrInitializer;
    ASTNode parent= target.getParent();
    while (parent != null) {
        if (parent instanceof MethodDeclaration || parent instanceof Initializer || parent instanceof FieldDeclaration) {
            target= (BodyDeclaration)parent;
        }
        parent= parent.getParent();
    }

    return doPerform(target);
}
项目:Eclipse-Postfix-Code-Completion    文件:CodeStyleFix.java   
private void handleVariable(SimpleName node, IVariableBinding varbinding) {
    if (!varbinding.isField())
        return;

    if (varbinding.isEnumConstant())
        return;

    ITypeBinding declaringClass= varbinding.getDeclaringClass();
    if (Modifier.isStatic(varbinding.getModifiers())) {
        if (fFindUnqualifiedStaticAccesses) {
            Initializer initializer= (Initializer) ASTNodes.getParent(node, Initializer.class);
            //Do not qualify assignments to static final fields in static initializers (would result in compile error)
            StructuralPropertyDescriptor parentDescription= node.getLocationInParent();
            if (initializer != null && Modifier.isStatic(initializer.getModifiers())
                    && Modifier.isFinal(varbinding.getModifiers()) && parentDescription == Assignment.LEFT_HAND_SIDE_PROPERTY)
                return;

            //Do not qualify static fields if defined inside an anonymous class
            if (declaringClass.isAnonymous())
                return;

            fResult.add(new AddStaticQualifierOperation(declaringClass, node));
        }
    } else if (fFindUnqualifiedAccesses){
        String qualifier= getThisExpressionQualifier(declaringClass, fImportRewrite, node);
        if (qualifier == null)
            return;

        if (qualifier.length() == 0)
            qualifier= null;

        fResult.add(new AddThisQualifierOperation(qualifier, node));
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:LocalCorrectionsSubProcessor.java   
public static void addConstructorFromSuperclassProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
    ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
    if (selectedNode == null) {
        return;
    }

    TypeDeclaration typeDeclaration= null;
    if (selectedNode.getLocationInParent() == TypeDeclaration.NAME_PROPERTY) {
        typeDeclaration= (TypeDeclaration) selectedNode.getParent();
    } else {
        BodyDeclaration declaration= ASTResolving.findParentBodyDeclaration(selectedNode);
        if (declaration instanceof Initializer && problem.getProblemId() == IProblem.UnhandledExceptionInDefaultConstructor) {
            addUncaughtExceptionProposals(context, problem, proposals);
        }
        return;
    }

    ITypeBinding binding= typeDeclaration.resolveBinding();
    if (binding == null || binding.getSuperclass() == null) {
        return;
    }
    ICompilationUnit cu= context.getCompilationUnit();
    IMethodBinding[] methods= binding.getSuperclass().getDeclaredMethods();
    for (int i= 0; i < methods.length; i++) {
        IMethodBinding curr= methods[i];
        if (curr.isConstructor() && !Modifier.isPrivate(curr.getModifiers())) {
            proposals.add(new ConstructorFromSuperclassProposal(cu, typeDeclaration, curr, IProposalRelevance.ADD_CONSTRUCTOR_FROM_SUPER_CLASS));
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTResolving.java   
public static boolean isInStaticContext(ASTNode selectedNode) {
    BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode);
    if (decl instanceof MethodDeclaration) {
        if (isInsideConstructorInvocation((MethodDeclaration) decl, selectedNode)) {
            return true;
        }
        return Modifier.isStatic(decl.getModifiers());
    } else if (decl instanceof Initializer) {
        return Modifier.isStatic(((Initializer)decl).getModifiers());
    } else if (decl instanceof FieldDeclaration) {
        return Modifier.isStatic(((FieldDeclaration)decl).getModifiers());
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ASTNodeSearchUtil.java   
public static Initializer getInitializerNode(IInitializer initializer, CompilationUnit cuNode) throws JavaModelException {
    ASTNode node= findNode(initializer.getSourceRange(), cuNode);
    if (node instanceof Initializer)
        return (Initializer) node;
    if (node instanceof Block && node.getParent() instanceof Initializer)
        return (Initializer) node.getParent();
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RenameLocalVariableProcessor.java   
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
    initAST();
    if (fTempDeclarationNode == null || fTempDeclarationNode.resolveBinding() == null)
        return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.RenameTempRefactoring_must_select_local);
    if (! Checks.isDeclaredIn(fTempDeclarationNode, MethodDeclaration.class)
     && ! Checks.isDeclaredIn(fTempDeclarationNode, Initializer.class))
        return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.RenameTempRefactoring_only_in_methods_and_initializers);

    initNames();
    return new RefactoringStatus();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:TargetProvider.java   
@Override
public void endVisit(Initializer node) {
    if (fCurrent.hasInvocations()) {
        result.put(node, fCurrent);
    }
    endVisitBodyDeclaration();
}