类org.eclipse.jdt.core.dom.ChildListPropertyDescriptor源码实例Demo

下面列出了怎么用org.eclipse.jdt.core.dom.ChildListPropertyDescriptor的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: eclipse.jdt.ls   文件: ReplaceRewrite.java
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);
		}
	}
}
 
源代码2 项目: eclipse.jdt.ls   文件: StatementRewrite.java
@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);
		}
	}
}
 
源代码3 项目: eclipse.jdt.ls   文件: TypeAnnotationRewrite.java
/**
 * 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);
			}
		}
	}
}
 
@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;
}
 
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());
	}
}
 
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);
		}
	}
}
 
@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);
		}
	}
}
 
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;
}
 
@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;
}
 
源代码10 项目: eclipse.jdt.ls   文件: ReplaceRewrite.java
protected ReplaceRewrite(ASTRewrite rewrite, ASTNode[] nodes) {
	Assert.isNotNull(rewrite);
	Assert.isNotNull(nodes);
	Assert.isTrue(nodes.length > 0);
	fRewrite= rewrite;
	fToReplace= nodes;
	fDescriptor= fToReplace[0].getLocationInParent();
	if (nodes.length > 1) {
		Assert.isTrue(fDescriptor instanceof ChildListPropertyDescriptor);
	}
}
 
源代码11 项目: eclipse.jdt.ls   文件: DimensionRewrite.java
/**
 * Removes all children in <code>node</code>'s <code>childListProperty</code>.
 *
 * @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 removeAllChildren(ASTNode node, ChildListPropertyDescriptor childListProperty, ASTRewrite rewrite, TextEditGroup editGroup) {
	ListRewrite listRewrite= rewrite.getListRewrite(node, childListProperty);
	@SuppressWarnings("unchecked")
	List<? extends ASTNode> children= (List<? extends ASTNode>) node.getStructuralProperty(childListProperty);
	for (ASTNode child : children) {
		listRewrite.remove(child, editGroup);
	}
}
 
源代码12 项目: eclipse.jdt.ls   文件: DelegateCreator.java
private ChildListPropertyDescriptor getTypeBodyDeclarationsProperty() {
	ASTNode parent= fDeclaration.getParent();

	if (parent instanceof AbstractTypeDeclaration) {
		return ((AbstractTypeDeclaration) parent).getBodyDeclarationsProperty();
	} else if (parent instanceof AnonymousClassDeclaration) {
		return AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY;
	}

	Assert.isTrue(false);
	return null;
}
 
源代码13 项目: eclipse.jdt.ls   文件: ExtractFieldRefactoring.java
private void addFieldDeclaration() throws CoreException {
	FieldDeclaration[] fields = getFieldDeclarations();
	ASTNode parent = getEnclosingTypeDeclaration();
	ChildListPropertyDescriptor descriptor = ASTNodes.getBodyDeclarationsProperty(parent);
	int insertIndex;
	if (fields.length == 0) {
		insertIndex = 0;
	} else {
		insertIndex = ASTNodes.getBodyDeclarations(parent).indexOf(fields[fields.length - 1]) + 1;
	}

	ASTRewrite rewrite = fCURewrite.getASTRewrite();
	final FieldDeclaration declaration = createNewFieldDeclaration(rewrite);
	rewrite.getListRewrite(parent, descriptor).insertAt(declaration, insertIndex, null);
}
 
private ChildListPropertyDescriptor getBodyDeclarationsProperty(ASTNode declaration) {
	if (declaration instanceof AnonymousClassDeclaration) {
		return AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY;
	} else if (declaration instanceof AbstractTypeDeclaration) {
		return ((AbstractTypeDeclaration) declaration).getBodyDeclarationsProperty();
	}
	Assert.isTrue(false);
	return null;
}
 
@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);
	}
	return rewrite;
}
 
private ChildListPropertyDescriptor getProperty() {
	List<StructuralPropertyDescriptor> list= fCallerNode.structuralPropertiesForType();
	for (int i= 0; i < list.size(); i++) {
		StructuralPropertyDescriptor curr= list.get(i);
		if (curr.isChildListProperty() && "arguments".equals(curr.getId())) { //$NON-NLS-1$
			return (ChildListPropertyDescriptor) curr;
		}
	}
	return null;

}
 
private VariableDeclarationFragment addFieldDeclaration(ASTRewrite rewrite, ASTNode newTypeDecl, int modifiers, Expression expression, ASTNode nodeToAssign, ITypeBinding typeBinding,
		int index) {
	if (fExistingFragment != null) {
		return fExistingFragment;
	}

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

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

	FieldDeclaration newDecl= ast.newFieldDeclaration(newDeclFrag);

	Type type= evaluateType(ast, nodeToAssign, typeBinding, KEY_TYPE + index, TypeLocation.FIELD);
	newDecl.setType(type);
	newDecl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, modifiers));

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

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

	return newDeclFrag;
}
 
@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;
}
 
源代码19 项目: xtext-xtend   文件: ASTFlattenerUtils.java
public List<ASTNode> genericChildListProperty(final ASTNode node, final String propertyName) {
  final Function1<ChildListPropertyDescriptor, Boolean> _function = (ChildListPropertyDescriptor it) -> {
    String _id = it.getId();
    return Boolean.valueOf(Objects.equal(propertyName, _id));
  };
  final ChildListPropertyDescriptor property = IterableExtensions.<ChildListPropertyDescriptor>head(IterableExtensions.<ChildListPropertyDescriptor>filter(Iterables.<ChildListPropertyDescriptor>filter(node.structuralPropertiesForType(), ChildListPropertyDescriptor.class), _function));
  if ((property != null)) {
    Object _structuralProperty = node.getStructuralProperty(property);
    return ((List<ASTNode>) _structuralProperty);
  }
  return null;
}
 
源代码20 项目: gwt-eclipse-plugin   文件: ClientBundleResource.java
public MethodDeclaration createMethodDeclaration(IType clientBundle, ASTRewrite astRewrite,
    ImportRewrite importRewrite, boolean addComments) throws CoreException {
  AST ast = astRewrite.getAST();
  MethodDeclaration methodDecl = ast.newMethodDeclaration();

  // Method is named after the resource it accesses
  methodDecl.setName(ast.newSimpleName(getMethodName()));

  // Method return type is a ResourcePrototype subtype
  ITypeBinding resourceTypeBinding = JavaASTUtils.resolveType(clientBundle.getJavaProject(), getReturnTypeName());
  Type resourceType = importRewrite.addImport(resourceTypeBinding, ast);
  methodDecl.setReturnType2(resourceType);

  // Add @Source annotation if necessary
  String sourceAnnotationValue = getSourceAnnotationValue(clientBundle);
  if (sourceAnnotationValue != null) {
    // Build the annotation
    SingleMemberAnnotation sourceAnnotation = ast.newSingleMemberAnnotation();
    sourceAnnotation.setTypeName(ast.newName("Source"));
    StringLiteral annotationValue = ast.newStringLiteral();
    annotationValue.setLiteralValue(sourceAnnotationValue);
    sourceAnnotation.setValue(annotationValue);

    // Add the annotation to the method
    ChildListPropertyDescriptor modifiers = methodDecl.getModifiersProperty();
    ListRewrite modifiersRewriter = astRewrite.getListRewrite(methodDecl, modifiers);
    modifiersRewriter.insertFirst(sourceAnnotation, null);
  }

  return methodDecl;
}
 
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());
}
 
private ChildListPropertyDescriptor getTypeBodyDeclarationsProperty() {
	ASTNode parent= fDeclaration.getParent();

	if (parent instanceof AbstractTypeDeclaration)
		return ((AbstractTypeDeclaration) parent).getBodyDeclarationsProperty();
	else if (parent instanceof AnonymousClassDeclaration)
		return AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY;

	Assert.isTrue(false);
	return null;
}
 
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);
  }
 
private void insertAt(ASTNode target, Statement declaration) {
	ASTRewrite rewrite= fCURewrite.getASTRewrite();
	TextEditGroup groupDescription= fCURewrite.createGroupDescription(RefactoringCoreMessages.ExtractTempRefactoring_declare_local_variable);

	ASTNode parent= target.getParent();
	StructuralPropertyDescriptor locationInParent= target.getLocationInParent();
	while (locationInParent != Block.STATEMENTS_PROPERTY && locationInParent != SwitchStatement.STATEMENTS_PROPERTY) {
		if (locationInParent == IfStatement.THEN_STATEMENT_PROPERTY
				|| locationInParent == IfStatement.ELSE_STATEMENT_PROPERTY
				|| locationInParent == ForStatement.BODY_PROPERTY
				|| locationInParent == EnhancedForStatement.BODY_PROPERTY
				|| locationInParent == DoStatement.BODY_PROPERTY
				|| locationInParent == WhileStatement.BODY_PROPERTY) {
			// create intermediate block if target was the body property of a control statement:
			Block replacement= rewrite.getAST().newBlock();
			ListRewrite replacementRewrite= rewrite.getListRewrite(replacement, Block.STATEMENTS_PROPERTY);
			replacementRewrite.insertFirst(declaration, null);
			replacementRewrite.insertLast(rewrite.createMoveTarget(target), null);
			rewrite.replace(target, replacement, groupDescription);
			return;
		}
		target= parent;
		parent= parent.getParent();
		locationInParent= target.getLocationInParent();
	}
	ListRewrite listRewrite= rewrite.getListRewrite(parent, (ChildListPropertyDescriptor)locationInParent);
	listRewrite.insertBefore(declaration, target, groupDescription);
}
 
private ChildListPropertyDescriptor typeToBodyDeclarationProperty(IType type, CompilationUnit root) throws JavaModelException {
	ASTNode typeDeclaration= typeToDeclaration(type, root);
	if (typeDeclaration instanceof AbstractTypeDeclaration)
		return ((AbstractTypeDeclaration) typeDeclaration).getBodyDeclarationsProperty();
	else if (typeDeclaration instanceof AnonymousClassDeclaration)
		return AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY;

	Assert.isTrue(false);
	return null;
}
 
private ChildListPropertyDescriptor getBodyDeclarationsProperty(ASTNode declaration) {
	if (declaration instanceof AnonymousClassDeclaration)
		return AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY;
	else if (declaration instanceof AbstractTypeDeclaration)
		return ((AbstractTypeDeclaration) declaration).getBodyDeclarationsProperty();
	Assert.isTrue(false);
	return null;
}
 
protected ReplaceRewrite(ASTRewrite rewrite, ASTNode[] nodes) {
	Assert.isNotNull(rewrite);
	Assert.isNotNull(nodes);
	Assert.isTrue(nodes.length > 0);
	fRewrite= rewrite;
	fToReplace= nodes;
	fDescriptor= fToReplace[0].getLocationInParent();
	if (nodes.length > 1) {
		Assert.isTrue(fDescriptor instanceof ChildListPropertyDescriptor);
	}
}
 
源代码28 项目: Eclipse-Postfix-Code-Completion   文件: ASTNodes.java
/**
 * Returns the list that contains the given ASTNode. If the node
 * isn't part of any list, <code>null</code> is returned.
 *
 * @param node the node in question
 * @return the list that contains the node or <code>null</code>
 */
public static List<? extends ASTNode> getContainingList(ASTNode node) {
	StructuralPropertyDescriptor locationInParent= node.getLocationInParent();
	if (locationInParent != null && locationInParent.isChildListProperty()) {
		return getChildListProperty(node.getParent(), (ChildListPropertyDescriptor) locationInParent);
	}
	return null;
}
 
源代码29 项目: Eclipse-Postfix-Code-Completion   文件: ASTNodes.java
/**
 * Returns the structural property descriptor for the "bodyDeclarations" property
 * of this node (element type: {@link BodyDeclaration}).
 * 
 * @param node the node, either an {@link AbstractTypeDeclaration} or an {@link AnonymousClassDeclaration}
 * @return the property descriptor
 */
public static ChildListPropertyDescriptor getBodyDeclarationsProperty(ASTNode node) {
	if (node instanceof AbstractTypeDeclaration) {
		return ((AbstractTypeDeclaration)node).getBodyDeclarationsProperty();
	} else if (node instanceof AnonymousClassDeclaration) {
		return AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY;
	}
	// should not happen.
	Assert.isTrue(false);
	return null;
}
 
/**
 * Removes all children in <code>node</code>'s <code>childListProperty</code>.
 * 
 * @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 removeAllChildren(ASTNode node, ChildListPropertyDescriptor childListProperty, ASTRewrite rewrite, TextEditGroup editGroup) {
	ListRewrite listRewrite= rewrite.getListRewrite(node, childListProperty);
	@SuppressWarnings("unchecked")
	List<? extends ASTNode> children= (List<? extends ASTNode>) node.getStructuralProperty(childListProperty);
	for (ASTNode child : children) {
		listRewrite.remove(child, editGroup);
	}
}
 
 类所在包
 类方法
 同包方法