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


Java ASTRewrite.createMoveTarget方法代码示例

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


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

示例1: splitUpDeclarations

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的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);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:37,代码来源:UnusedCodeFix.java

示例2: removeVariableWithInitializer

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的package包/类
private void removeVariableWithInitializer(ASTRewrite rewrite, ASTNode initializerNode, ASTNode statementNode, TextEditGroup group) {
	boolean performRemove= fForceRemove;
	if (!performRemove) {
		ArrayList<Expression> sideEffectNodes= new ArrayList<>();
		initializerNode.accept(new SideEffectFinder(sideEffectNodes));
		performRemove= sideEffectNodes.isEmpty();
	}
	if (performRemove) {
		removeStatement(rewrite, statementNode, group);
		fRemovedAssignmentsCount++;
	} else {
		ASTNode initNode = rewrite.createMoveTarget(initializerNode);
		ExpressionStatement statement = rewrite.getAST().newExpressionStatement((Expression) initNode);
		rewrite.replace(statementNode, statement, null);
		fAlteredAssignmentsCount++;
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:UnusedCodeFix.java

示例3: replaceCast

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的package包/类
private static void replaceCast(CastExpression castExpression, Expression replacement, ASTRewrite rewrite, TextEditGroup group) {
	boolean castEnclosedInNecessaryParentheses= castExpression.getParent() instanceof ParenthesizedExpression
			&& NecessaryParenthesesChecker.needsParentheses(castExpression, castExpression.getParent().getParent(), castExpression.getParent().getLocationInParent());

	ASTNode toReplace= castEnclosedInNecessaryParentheses ? castExpression.getParent() : castExpression;
	ASTNode move;
	if (NecessaryParenthesesChecker.needsParentheses(replacement, toReplace.getParent(), toReplace.getLocationInParent())) {
		if (replacement.getParent() instanceof ParenthesizedExpression) {
			move= rewrite.createMoveTarget(replacement.getParent());
		} else if (castEnclosedInNecessaryParentheses) {
			toReplace= castExpression;
			move= rewrite.createMoveTarget(replacement);
		} else {
			ParenthesizedExpression parentheses= replacement.getAST().newParenthesizedExpression();
			parentheses.setExpression((Expression) rewrite.createMoveTarget(replacement));
			move= parentheses;
		}
	} else {
		move= rewrite.createMoveTarget(replacement);
	}
	rewrite.replace(toReplace, move, group);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:UnusedCodeFix.java

示例4: changeLambdaBodyToBlock

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的package包/类
public static void changeLambdaBodyToBlock(LambdaExpression lambda, AST ast, ASTRewrite rewrite) {
	Expression bodyExpr = (Expression) rewrite.createMoveTarget(lambda.getBody());
	Block blockBody = getBlockBodyForLambda(bodyExpr, lambda.resolveMethodBinding().getReturnType(), ast);
	rewrite.set(lambda, LambdaExpression.BODY_PROPERTY, blockBody, null);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:6,代码来源:QuickAssistProcessor.java

示例5: createMoveTarget

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的package包/类
/**
 * Type-safe variant of {@link ASTRewrite#createMoveTarget(ASTNode)}.
 *
 * @param rewrite ASTRewrite for the given node
 * @param node the node to create a move placeholder for
 * @return the new placeholder node
 * @throws IllegalArgumentException if the node is null, or if the node
 * is not part of the rewrite's AST
 */
@SuppressWarnings("unchecked")
public static <T extends ASTNode> T createMoveTarget(ASTRewrite rewrite, T node) {
	return (T) rewrite.createMoveTarget(node);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:14,代码来源:ASTNodes.java


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