当前位置: 首页>>代码示例>>Java>>正文


Java ASTNodes.getBodyDeclarations方法代码示例

本文整理汇总了Java中org.eclipse.jdt.internal.corext.dom.ASTNodes.getBodyDeclarations方法的典型用法代码示例。如果您正苦于以下问题:Java ASTNodes.getBodyDeclarations方法的具体用法?Java ASTNodes.getBodyDeclarations怎么用?Java ASTNodes.getBodyDeclarations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.internal.corext.dom.ASTNodes的用法示例。


在下文中一共展示了ASTNodes.getBodyDeclarations方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addFieldDeclaration

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private VariableDeclarationFragment addFieldDeclaration(
    ASTRewrite rewrite, ASTNode newTypeDecl, int modifiers, Expression expression) {
  if (fExistingFragment != null) {
    return fExistingFragment;
  }

  ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
  List<BodyDeclaration> decls = ASTNodes.getBodyDeclarations(newTypeDecl);
  AST ast = newTypeDecl.getAST();
  String[] varNames = suggestFieldNames(fTypeBinding, expression, modifiers);
  for (int i = 0; i < varNames.length; i++) {
    addLinkedPositionProposal(KEY_NAME, varNames[i], null);
  }
  String varName = varNames[0];

  VariableDeclarationFragment newDeclFrag = ast.newVariableDeclarationFragment();
  newDeclFrag.setName(ast.newSimpleName(varName));

  FieldDeclaration newDecl = ast.newFieldDeclaration(newDeclFrag);

  Type type = evaluateType(ast);
  newDecl.setType(type);
  newDecl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, modifiers));

  ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(
      getLinkedProposalModel(), rewrite, newDecl.modifiers(), false);

  int insertIndex = findFieldInsertIndex(decls, fNodeToAssign.getStartPosition());
  rewrite.getListRewrite(newTypeDecl, property).insertAt(newDecl, insertIndex, null);

  return newDeclFrag;
}
 
开发者ID:eclipse,项目名称:che,代码行数:33,代码来源:AssignToVariableAssistProposal.java

示例2: getFieldDeclarations

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private FieldDeclaration[] getFieldDeclarations() {
  List<BodyDeclaration> bodyDeclarations =
      ASTNodes.getBodyDeclarations(getMethodDeclaration().getParent());
  List<FieldDeclaration> fields = new ArrayList<FieldDeclaration>(1);
  for (Iterator<BodyDeclaration> iter = bodyDeclarations.iterator(); iter.hasNext(); ) {
    Object each = iter.next();
    if (each instanceof FieldDeclaration) fields.add((FieldDeclaration) each);
  }
  return fields.toArray(new FieldDeclaration[fields.size()]);
}
 
开发者ID:eclipse,项目名称:che,代码行数:11,代码来源:PromoteTempToFieldRefactoring.java

示例3: getRewrite

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
@Override
protected ASTRewrite getRewrite() throws CoreException {
  CompilationUnit astRoot = ASTResolving.findParentCompilationUnit(fNode);
  ASTNode typeDecl = astRoot.findDeclaringNode(fSenderBinding);
  ASTNode newTypeDecl = null;
  boolean isInDifferentCU;
  if (typeDecl != null) {
    isInDifferentCU = false;
    newTypeDecl = typeDecl;
  } else {
    isInDifferentCU = true;
    astRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null);
    newTypeDecl = astRoot.findDeclaringNode(fSenderBinding.getKey());
  }
  createImportRewrite(astRoot);

  if (newTypeDecl != null) {
    ASTRewrite rewrite = ASTRewrite.create(astRoot.getAST());

    MethodDeclaration newStub = getStub(rewrite, newTypeDecl);

    ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
    List<BodyDeclaration> members = ASTNodes.getBodyDeclarations(newTypeDecl);

    int insertIndex;
    if (isConstructor()) {
      insertIndex = findConstructorInsertIndex(members);
    } else if (!isInDifferentCU) {
      insertIndex = findMethodInsertIndex(members, fNode.getStartPosition());
    } else {
      insertIndex = members.size();
    }
    ListRewrite listRewriter = rewrite.getListRewrite(newTypeDecl, property);
    listRewriter.insertAt(newStub, insertIndex, null);

    return rewrite;
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:40,代码来源:AbstractMethodCorrectionProposal.java


注:本文中的org.eclipse.jdt.internal.corext.dom.ASTNodes.getBodyDeclarations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。