本文整理汇总了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;
}
示例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()]);
}
示例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;
}