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


Java ASTNodes.getBodyDeclarationsProperty方法代码示例

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


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

示例1: doAddField

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private ASTRewrite doAddField(CompilationUnit astRoot) {
  SimpleName node = fOriginalNode;
  boolean isInDifferentCU = false;

  ASTNode newTypeDecl = astRoot.findDeclaringNode(fSenderBinding);
  if (newTypeDecl == null) {
    astRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null);
    newTypeDecl = astRoot.findDeclaringNode(fSenderBinding.getKey());
    isInDifferentCU = true;
  }
  ImportRewrite imports = createImportRewrite(astRoot);
  ImportRewriteContext importRewriteContext =
      new ContextSensitiveImportRewriteContext(
          ASTResolving.findParentBodyDeclaration(node), imports);

  if (newTypeDecl != null) {
    AST ast = newTypeDecl.getAST();

    ASTRewrite rewrite = ASTRewrite.create(ast);

    VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
    fragment.setName(ast.newSimpleName(node.getIdentifier()));

    Type type = evaluateVariableType(ast, imports, importRewriteContext, fSenderBinding);

    FieldDeclaration newDecl = ast.newFieldDeclaration(fragment);
    newDecl.setType(type);
    newDecl
        .modifiers()
        .addAll(ASTNodeFactory.newModifiers(ast, evaluateFieldModifiers(newTypeDecl)));

    if (fSenderBinding.isInterface() || fVariableKind == CONST_FIELD) {
      fragment.setInitializer(ASTNodeFactory.newDefaultExpression(ast, type, 0));
    }

    ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
    List<BodyDeclaration> decls =
        ASTNodes.<BodyDeclaration>getChildListProperty(newTypeDecl, property);

    int maxOffset = isInDifferentCU ? -1 : node.getStartPosition();

    int insertIndex = findFieldInsertIndex(decls, newDecl, maxOffset);

    ListRewrite listRewriter = rewrite.getListRewrite(newTypeDecl, property);
    listRewriter.insertAt(newDecl, insertIndex, null);

    ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(
        getLinkedProposalModel(), rewrite, newDecl.modifiers(), fSenderBinding.isInterface());

    addLinkedPosition(rewrite.track(newDecl.getType()), false, KEY_TYPE);
    if (!isInDifferentCU) {
      addLinkedPosition(rewrite.track(node), true, KEY_NAME);
    }
    addLinkedPosition(rewrite.track(fragment.getName()), false, KEY_NAME);

    if (fragment.getInitializer() != null) {
      addLinkedPosition(rewrite.track(fragment.getInitializer()), false, KEY_INITIALIZER);
    }
    return rewrite;
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:63,代码来源:NewVariableCorrectionProposal.java

示例2: 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

示例3: getRewrite

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
@Override
protected ASTRewrite getRewrite() {
  CompilationUnit targetAstRoot = ASTResolving.createQuickFixAST(
      getCompilationUnit(), null);
  createImportRewrite(targetAstRoot);

  // Find the target type declaration
  TypeDeclaration typeDecl = JavaASTUtils.findTypeDeclaration(targetAstRoot,
      targetQualifiedTypeName);
  if (typeDecl == null) {
    return null;
  }

  ASTRewrite rewrite = ASTRewrite.create(targetAstRoot.getAST());

  // Generate the new method declaration
  MethodDeclaration methodDecl = createMethodDeclaration(rewrite.getAST());

  // Add the new method declaration to the interface
  ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(typeDecl);
  ListRewrite listRewriter = rewrite.getListRewrite(typeDecl, property);
  listRewriter.insertLast(methodDecl, null);

  return rewrite;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:26,代码来源:AbstractCreateMethodProposal.java

示例4: addFieldDeclaration

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private void addFieldDeclaration(ASTRewrite rewrite) {
  FieldDeclaration[] fields = getFieldDeclarations();
  ASTNode parent = getMethodDeclaration().getParent();
  ChildListPropertyDescriptor descriptor = ASTNodes.getBodyDeclarationsProperty(parent);
  int insertIndex;
  if (fields.length == 0) insertIndex = 0;
  else insertIndex = ASTNodes.getBodyDeclarations(parent).indexOf(fields[fields.length - 1]) + 1;

  final FieldDeclaration declaration = createNewFieldDeclaration(rewrite);
  rewrite.getListRewrite(parent, descriptor).insertAt(declaration, insertIndex, null);
}
 
开发者ID:eclipse,项目名称:che,代码行数:12,代码来源:PromoteTempToFieldRefactoring.java

示例5: 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

示例6: run

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
public void run(IProgressMonitor monitor) throws CoreException {
  ICompilationUnit icu = clientBundle.getCompilationUnit();
  CompilationUnit cu = JavaASTUtils.parseCompilationUnit(icu);
  ImportRewrite importRewrite = StubUtility.createImportRewrite(cu, true);

  // Find the target type declaration
  TypeDeclaration typeDecl = JavaASTUtils.findTypeDeclaration(cu,
      clientBundle.getFullyQualifiedName());
  if (typeDecl == null) {
    throw new CoreException(
        StatusUtilities.newErrorStatus("Missing ClientBundle type "
            + clientBundle.getFullyQualifiedName(), GWTPlugin.PLUGIN_ID));
  }

  // We need to rewrite the AST of the ClientBundle type declaration
  ASTRewrite astRewrite = ASTRewrite.create(cu.getAST());
  ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(typeDecl);
  ListRewrite listRewriter = astRewrite.getListRewrite(typeDecl, property);

  // Add the new resource methods
  boolean addComments = StubUtility.doAddComments(icu.getJavaProject());
  for (ClientBundleResource resource : resources) {
    listRewriter.insertLast(resource.createMethodDeclaration(clientBundle,
        astRewrite, importRewrite, addComments), null);
  }

  // Create the edit to add the methods and update the imports
  TextEdit rootEdit = new MultiTextEdit();
  rootEdit.addChild(astRewrite.rewriteAST());
  rootEdit.addChild(importRewrite.rewriteImports(null));

  // Apply the change to the compilation unit
  CompilationUnitChange cuChange = new CompilationUnitChange(
      "Update ClientBundle", icu);
  cuChange.setSaveMode(TextFileChange.KEEP_SAVE_STATE);
  cuChange.setEdit(rootEdit);
  cuChange.perform(new NullProgressMonitor());
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:39,代码来源:AddResourcesToClientBundleAction.java


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