本文整理汇总了Java中org.eclipse.jdt.core.dom.IfStatement.THEN_STATEMENT_PROPERTY属性的典型用法代码示例。如果您正苦于以下问题:Java IfStatement.THEN_STATEMENT_PROPERTY属性的具体用法?Java IfStatement.THEN_STATEMENT_PROPERTY怎么用?Java IfStatement.THEN_STATEMENT_PROPERTY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.eclipse.jdt.core.dom.IfStatement
的用法示例。
在下文中一共展示了IfStatement.THEN_STATEMENT_PROPERTY属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rewriteAST
/** {@inheritDoc} */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model)
throws CoreException {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
String label;
if (fBodyProperty == IfStatement.THEN_STATEMENT_PROPERTY) {
label = FixMessages.CodeStyleFix_ChangeIfToBlock_desription;
} else if (fBodyProperty == IfStatement.ELSE_STATEMENT_PROPERTY) {
label = FixMessages.CodeStyleFix_ChangeElseToBlock_description;
} else {
label = FixMessages.CodeStyleFix_ChangeControlToBlock_description;
}
TextEditGroup group = createTextEditGroup(label, cuRewrite);
ASTNode moveTarget = rewrite.createMoveTarget(fBody);
Block replacingBody = cuRewrite.getRoot().getAST().newBlock();
replacingBody.statements().add(moveTarget);
rewrite.set(fControlStatement, fBodyProperty, replacingBody, group);
}
示例2: needsBlockAroundDanglingIf
private boolean needsBlockAroundDanglingIf() {
/* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=169331
*
* Situation:
* boolean a, b;
* void toInline() {
* if (a)
* hashCode();
* }
* void m() {
* if (b)
* toInline();
* else
* toString();
* }
* => needs block around inlined "if (a)..." to avoid attaching else to wrong if.
*/
return fTargetNode.getLocationInParent() == IfStatement.THEN_STATEMENT_PROPERTY
&& fTargetNode.getParent().getStructuralProperty(IfStatement.ELSE_STATEMENT_PROPERTY)
!= null
&& fSourceProvider.isDangligIf();
}
示例3: needsBlockAroundDanglingIf
private boolean needsBlockAroundDanglingIf() {
/* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=169331
*
* Situation:
* boolean a, b;
* void toInline() {
* if (a)
* hashCode();
* }
* void m() {
* if (b)
* toInline();
* else
* toString();
* }
* => needs block around inlined "if (a)..." to avoid attaching else to wrong if.
*/
return fTargetNode.getLocationInParent() == IfStatement.THEN_STATEMENT_PROPERTY
&& fTargetNode.getParent().getStructuralProperty(IfStatement.ELSE_STATEMENT_PROPERTY) != null
&& fSourceProvider.isDangligIf();
}
示例4: rewriteAST
/**
* {@inheritDoc}
*/
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
ASTRewrite rewrite= cuRewrite.getASTRewrite();
String label;
if (fBodyProperty == IfStatement.THEN_STATEMENT_PROPERTY) {
label = FixMessages.CodeStyleFix_ChangeIfToBlock_desription;
} else if (fBodyProperty == IfStatement.ELSE_STATEMENT_PROPERTY) {
label = FixMessages.CodeStyleFix_ChangeElseToBlock_description;
} else {
label = FixMessages.CodeStyleFix_ChangeControlToBlock_description;
}
TextEditGroup group= createTextEditGroup(label, cuRewrite);
ASTNode moveTarget= rewrite.createMoveTarget(fBody);
Block replacingBody= cuRewrite.getRoot().getAST().newBlock();
replacingBody.statements().add(moveTarget);
rewrite.set(fControlStatement, fBodyProperty, replacingBody, group);
}
示例5: isControlStatementBody
/**
* Returns true if a node at a given location is a body of a control statement. Such body nodes are
* interesting as when replacing them, it has to be evaluates if a Block is needed instead.
* E.g. <code> if (x) do(); -> if (x) { do1(); do2() } </code>
*
* @param locationInParent Location of the body node
* @return Returns true if the location is a body node location of a control statement.
*/
public static boolean isControlStatementBody(StructuralPropertyDescriptor locationInParent) {
return locationInParent == IfStatement.THEN_STATEMENT_PROPERTY
|| locationInParent == IfStatement.ELSE_STATEMENT_PROPERTY
|| locationInParent == ForStatement.BODY_PROPERTY
|| locationInParent == EnhancedForStatement.BODY_PROPERTY
|| locationInParent == WhileStatement.BODY_PROPERTY
|| locationInParent == DoStatement.BODY_PROPERTY;
}
示例6: insertAt
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);
}
示例7: insertAt
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);
}
示例8: isControlStatementBody
/**
* Returns true if a node at a given location is a body of a control statement. Such body nodes are
* interesting as when replacing them, it has to be evaluates if a Block is needed instead.
* E.g. <code> if (x) do(); -> if (x) { do1(); do2() } </code>
*
* @param locationInParent Location of the body node
* @return Returns true if the location is a body node location of a control statement.
*/
public static boolean isControlStatementBody(StructuralPropertyDescriptor locationInParent) {
return locationInParent == IfStatement.THEN_STATEMENT_PROPERTY
|| locationInParent == IfStatement.ELSE_STATEMENT_PROPERTY
|| locationInParent == ForStatement.BODY_PROPERTY
|| locationInParent == EnhancedForStatement.BODY_PROPERTY
|| locationInParent == WhileStatement.BODY_PROPERTY
|| locationInParent == DoStatement.BODY_PROPERTY;
}