本文整理汇总了Java中org.eclipse.jdt.core.dom.ChildListPropertyDescriptor类的典型用法代码示例。如果您正苦于以下问题:Java ChildListPropertyDescriptor类的具体用法?Java ChildListPropertyDescriptor怎么用?Java ChildListPropertyDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChildListPropertyDescriptor类属于org.eclipse.jdt.core.dom包,在下文中一共展示了ChildListPropertyDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: locationNeedsParentheses
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; //导入依赖的package包/类
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
// e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
return false;
}
if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
|| locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY
|| locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
|| locationInParent == ForStatement.EXPRESSION_PROPERTY
|| locationInParent == WhileStatement.EXPRESSION_PROPERTY
|| locationInParent == DoStatement.EXPRESSION_PROPERTY
|| locationInParent == AssertStatement.EXPRESSION_PROPERTY
|| locationInParent == AssertStatement.MESSAGE_PROPERTY
|| locationInParent == IfStatement.EXPRESSION_PROPERTY
|| locationInParent == SwitchStatement.EXPRESSION_PROPERTY
|| locationInParent == SwitchCase.EXPRESSION_PROPERTY
|| locationInParent == ArrayAccess.INDEX_PROPERTY
|| locationInParent == ThrowStatement.EXPRESSION_PROPERTY
|| locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
|| locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
return false;
}
return true;
}
示例2: getArgumentsProperty
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; //导入依赖的package包/类
public static ChildListPropertyDescriptor getArgumentsProperty(ASTNode invocation) {
switch (invocation.getNodeType()) {
case ASTNode.METHOD_INVOCATION:
return MethodInvocation.ARGUMENTS_PROPERTY;
case ASTNode.SUPER_METHOD_INVOCATION:
return SuperMethodInvocation.ARGUMENTS_PROPERTY;
case ASTNode.CONSTRUCTOR_INVOCATION:
return ConstructorInvocation.ARGUMENTS_PROPERTY;
case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
return SuperConstructorInvocation.ARGUMENTS_PROPERTY;
case ASTNode.CLASS_INSTANCE_CREATION:
return ClassInstanceCreation.ARGUMENTS_PROPERTY;
case ASTNode.ENUM_CONSTANT_DECLARATION:
return EnumConstantDeclaration.ARGUMENTS_PROPERTY;
default:
throw new IllegalArgumentException(invocation.toString());
}
}
示例3: handleManyMany
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; //导入依赖的package包/类
protected void handleManyMany(ASTNode[] replacements, TextEditGroup description) {
ListRewrite container= fRewrite.getListRewrite(fToReplace[0].getParent(), (ChildListPropertyDescriptor)fDescriptor);
if (fToReplace.length == replacements.length) {
for (int i= 0; i < fToReplace.length; i++) {
container.replace(fToReplace[i], replacements[i], description);
}
} else if (fToReplace.length < replacements.length) {
for (int i= 0; i < fToReplace.length; i++) {
container.replace(fToReplace[i], replacements[i], description);
}
for (int i= fToReplace.length; i < replacements.length; i++) {
container.insertAfter(replacements[i], replacements[i - 1], description);
}
} else if (fToReplace.length > replacements.length) {
int delta= fToReplace.length - replacements.length;
for(int i= 0; i < delta; i++) {
container.remove(fToReplace[i], description);
}
for (int i= delta, r= 0; i < fToReplace.length; i++, r++) {
container.replace(fToReplace[i], replacements[r], description);
}
}
}
示例4: handleOneMany
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; //导入依赖的package包/类
@Override
protected void handleOneMany(ASTNode[] replacements, TextEditGroup description) {
AST ast= fToReplace[0].getAST();
// to replace == 1, but more than one replacement. Have to check if we
// need to insert a block to not change structure
if (ASTNodes.isControlStatementBody(fDescriptor)) {
Block block= ast.newBlock();
ListRewrite statements= fRewrite.getListRewrite(block, Block.STATEMENTS_PROPERTY);
for (int i= 0; i < replacements.length; i++) {
statements.insertLast(replacements[i], description);
}
fRewrite.replace(fToReplace[0], block, description);
} else {
ListRewrite container= fRewrite.getListRewrite(fToReplace[0].getParent(), (ChildListPropertyDescriptor)fDescriptor);
container.replace(fToReplace[0], replacements[0], description);
for (int i= 1; i < replacements.length; i++) {
container.insertAfter(replacements[i], replacements[i - 1], description);
}
}
}
示例5: removePureTypeAnnotations
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; //导入依赖的package包/类
/**
* Removes all {@link Annotation} whose only {@link Target} is {@link ElementType#TYPE_USE} from
* <code>node</code>'s <code>childListProperty</code>.
* <p>
* In a combination of {@link ElementType#TYPE_USE} and {@link ElementType#TYPE_PARAMETER}
* the latter is ignored, because this is implied by the former and creates no ambiguity.</p>
*
* @param node ASTNode
* @param childListProperty child list property
* @param rewrite rewrite that removes the nodes
* @param editGroup the edit group in which to collect the corresponding text edits, or null if
* ungrouped
*/
public static void removePureTypeAnnotations(ASTNode node, ChildListPropertyDescriptor childListProperty, ASTRewrite rewrite, TextEditGroup editGroup) {
CompilationUnit root= (CompilationUnit) node.getRoot();
if (!JavaModelUtil.is18OrHigher(root.getJavaElement().getJavaProject())) {
return;
}
ListRewrite listRewrite= rewrite.getListRewrite(node, childListProperty);
@SuppressWarnings("unchecked")
List<? extends ASTNode> children= (List<? extends ASTNode>) node.getStructuralProperty(childListProperty);
for (ASTNode child : children) {
if (child instanceof Annotation) {
Annotation annotation= (Annotation) child;
if (isPureTypeAnnotation(annotation)) {
listRewrite.remove(child, editGroup);
}
}
}
}
示例6: splitUpDeclarations
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; //导入依赖的package包/类
private void splitUpDeclarations(ASTRewrite rewrite, TextEditGroup group, VariableDeclarationFragment frag, VariableDeclarationStatement originalStatement, List<Expression> sideEffects) {
if (sideEffects.size() > 0) {
ListRewrite statementRewrite= rewrite.getListRewrite(originalStatement.getParent(), (ChildListPropertyDescriptor) originalStatement.getLocationInParent());
Statement previousStatement= originalStatement;
for (int i= 0; i < sideEffects.size(); i++) {
Expression sideEffect= sideEffects.get(i);
Expression movedInit= (Expression) rewrite.createMoveTarget(sideEffect);
ExpressionStatement wrapped= rewrite.getAST().newExpressionStatement(movedInit);
statementRewrite.insertAfter(wrapped, previousStatement, group);
previousStatement= wrapped;
}
VariableDeclarationStatement newDeclaration= null;
List<VariableDeclarationFragment> fragments= originalStatement.fragments();
int fragIndex= fragments.indexOf(frag);
ListIterator<VariableDeclarationFragment> fragmentIterator= fragments.listIterator(fragIndex+1);
while (fragmentIterator.hasNext()) {
VariableDeclarationFragment currentFragment= fragmentIterator.next();
VariableDeclarationFragment movedFragment= (VariableDeclarationFragment) rewrite.createMoveTarget(currentFragment);
if (newDeclaration == null) {
newDeclaration= rewrite.getAST().newVariableDeclarationStatement(movedFragment);
Type copiedType= (Type) rewrite.createCopyTarget(originalStatement.getType());
newDeclaration.setType(copiedType);
} else {
newDeclaration.fragments().add(movedFragment);
}
}
if (newDeclaration != null){
statementRewrite.insertAfter(newDeclaration, previousStatement, group);
if (originalStatement.fragments().size() == newDeclaration.fragments().size() + 1){
rewrite.remove(originalStatement, group);
}
}
}
}
示例7: handleManyMany
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; //导入依赖的package包/类
protected void handleManyMany(ASTNode[] replacements, TextEditGroup description) {
ListRewrite container =
fRewrite.getListRewrite(
fToReplace[0].getParent(), (ChildListPropertyDescriptor) fDescriptor);
if (fToReplace.length == replacements.length) {
for (int i = 0; i < fToReplace.length; i++) {
container.replace(fToReplace[i], replacements[i], description);
}
} else if (fToReplace.length < replacements.length) {
for (int i = 0; i < fToReplace.length; i++) {
container.replace(fToReplace[i], replacements[i], description);
}
for (int i = fToReplace.length; i < replacements.length; i++) {
container.insertAfter(replacements[i], replacements[i - 1], description);
}
} else if (fToReplace.length > replacements.length) {
int delta = fToReplace.length - replacements.length;
for (int i = 0; i < delta; i++) {
container.remove(fToReplace[i], description);
}
for (int i = delta, r = 0; i < fToReplace.length; i++, r++) {
container.replace(fToReplace[i], replacements[r], description);
}
}
}
示例8: handleOneMany
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; //导入依赖的package包/类
@Override
protected void handleOneMany(ASTNode[] replacements, TextEditGroup description) {
AST ast = fToReplace[0].getAST();
// to replace == 1, but more than one replacement. Have to check if we
// need to insert a block to not change structure
if (ASTNodes.isControlStatementBody(fDescriptor)) {
Block block = ast.newBlock();
ListRewrite statements = fRewrite.getListRewrite(block, Block.STATEMENTS_PROPERTY);
for (int i = 0; i < replacements.length; i++) {
statements.insertLast(replacements[i], description);
}
fRewrite.replace(fToReplace[0], block, description);
} else {
ListRewrite container =
fRewrite.getListRewrite(
fToReplace[0].getParent(), (ChildListPropertyDescriptor) fDescriptor);
container.replace(fToReplace[0], replacements[0], description);
for (int i = 1; i < replacements.length; i++) {
container.insertAfter(replacements[i], replacements[i - 1], description);
}
}
}
示例9: locationNeedsParentheses
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; //导入依赖的package包/类
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
if (locationInParent instanceof ChildListPropertyDescriptor
&& locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
// e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation
// ...
return false;
}
if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
|| locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY
|| locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
|| locationInParent == ForStatement.EXPRESSION_PROPERTY
|| locationInParent == WhileStatement.EXPRESSION_PROPERTY
|| locationInParent == DoStatement.EXPRESSION_PROPERTY
|| locationInParent == AssertStatement.EXPRESSION_PROPERTY
|| locationInParent == AssertStatement.MESSAGE_PROPERTY
|| locationInParent == IfStatement.EXPRESSION_PROPERTY
|| locationInParent == SwitchStatement.EXPRESSION_PROPERTY
|| locationInParent == SwitchCase.EXPRESSION_PROPERTY
|| locationInParent == ArrayAccess.INDEX_PROPERTY
|| locationInParent == ThrowStatement.EXPRESSION_PROPERTY
|| locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
|| locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
return false;
}
return true;
}
示例10: getRewrite
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; //导入依赖的package包/类
@Override
protected ASTRewrite getRewrite() {
AST ast = fCallerNode.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
ChildListPropertyDescriptor property = getProperty();
for (int i = 0; i < fInsertIndexes.length; i++) {
int idx = fInsertIndexes[i];
String key = "newarg_" + i; // $NON-NLS-1$
Expression newArg = evaluateArgumentExpressions(ast, fParamTypes[idx], key);
ListRewrite listRewriter = rewrite.getListRewrite(fCallerNode, property);
listRewriter.insertAt(newArg, idx, null);
addLinkedPosition(rewrite.track(newArg), i == 0, key);
}
return rewrite;
}
示例11: doAddField
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; //导入依赖的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;
}
示例12: addFieldDeclaration
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; //导入依赖的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;
}
示例13: getRewrite
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; //导入依赖的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;
}
示例14: getArgumentsProperty
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; //导入依赖的package包/类
public static ChildListPropertyDescriptor getArgumentsProperty(ASTNode invocation) {
switch (invocation.getNodeType()) {
case ASTNode.METHOD_INVOCATION:
return MethodInvocation.ARGUMENTS_PROPERTY;
case ASTNode.SUPER_METHOD_INVOCATION:
return SuperMethodInvocation.ARGUMENTS_PROPERTY;
case ASTNode.CONSTRUCTOR_INVOCATION:
return ConstructorInvocation.ARGUMENTS_PROPERTY;
case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
return SuperConstructorInvocation.ARGUMENTS_PROPERTY;
case ASTNode.CLASS_INSTANCE_CREATION:
return ClassInstanceCreation.ARGUMENTS_PROPERTY;
case ASTNode.ENUM_CONSTANT_DECLARATION:
return EnumConstantDeclaration.ARGUMENTS_PROPERTY;
default:
throw new IllegalArgumentException(invocation.toString());
}
}
示例15: splitUpDeclarations
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; //导入依赖的package包/类
private void splitUpDeclarations(ASTRewrite rewrite, TextEditGroup group, VariableDeclarationFragment frag, VariableDeclarationStatement originalStatement, List<Expression> sideEffects) {
if (sideEffects.size() > 0) {
ListRewrite statementRewrite= rewrite.getListRewrite(originalStatement.getParent(), (ChildListPropertyDescriptor) originalStatement.getLocationInParent());
Statement previousStatement= originalStatement;
for (int i= 0; i < sideEffects.size(); i++) {
Expression sideEffect= sideEffects.get(i);
Expression movedInit= (Expression) rewrite.createMoveTarget(sideEffect);
ExpressionStatement wrapped= rewrite.getAST().newExpressionStatement(movedInit);
statementRewrite.insertAfter(wrapped, previousStatement, group);
previousStatement= wrapped;
}
VariableDeclarationStatement newDeclaration= null;
List<VariableDeclarationFragment> fragments= originalStatement.fragments();
int fragIndex= fragments.indexOf(frag);
ListIterator<VariableDeclarationFragment> fragmentIterator= fragments.listIterator(fragIndex+1);
while (fragmentIterator.hasNext()) {
VariableDeclarationFragment currentFragment= fragmentIterator.next();
VariableDeclarationFragment movedFragment= (VariableDeclarationFragment) rewrite.createMoveTarget(currentFragment);
if (newDeclaration == null) {
newDeclaration= rewrite.getAST().newVariableDeclarationStatement(movedFragment);
Type copiedType= (Type) rewrite.createCopyTarget(originalStatement.getType());
newDeclaration.setType(copiedType);
} else {
newDeclaration.fragments().add(movedFragment);
}
}
if (newDeclaration != null){
statementRewrite.insertAfter(newDeclaration, previousStatement, group);
if (originalStatement.fragments().size() == newDeclaration.fragments().size() + 1){
rewrite.remove(originalStatement, group);
}
}
}
}