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


Java IfStatement类代码示例

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


IfStatement类属于org.eclipse.jdt.core.dom包,在下文中一共展示了IfStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: locationNeedsParentheses

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

示例2: getBlockType

import org.eclipse.jdt.core.dom.IfStatement; //导入依赖的package包/类
private BlockInfo.Type getBlockType(ASTNode node) {
	if(node instanceof TypeDeclaration)
		return BlockInfo.Type.TYPE;

	else if(node instanceof MethodDeclaration)
		return BlockInfo.Type.METHOD;

	else if(node instanceof WhileStatement)
		return BlockInfo.Type.WHILE;

	else if(node instanceof ForStatement)
		return BlockInfo.Type.FOR;

	else if(node instanceof IfStatement)
		return BlockInfo.Type.IF;
	else
		return BlockInfo.Type.OTHER;
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:19,代码来源:VarParser.java

示例3: getStatementType

import org.eclipse.jdt.core.dom.IfStatement; //导入依赖的package包/类
/**
 * Method that check statement type.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param itStatement
 */
private void getStatementType(Object itStatement) {
	if (itStatement instanceof CatchClause){
		this.visitor.visit((CatchClause)itStatement);
	}else if (itStatement instanceof ForStatement){
		this.visitor.visit((ForStatement)itStatement);
	}else if (itStatement instanceof IfStatement){
		this.visitor.visit((IfStatement)itStatement);
	}else if (itStatement instanceof WhileStatement){
		this.visitor.visit((WhileStatement)itStatement);
	}else if (itStatement instanceof TryStatement){
		this.visitor.visit((TryStatement)itStatement);
	}else if (itStatement instanceof ConditionalExpression){
		this.visitor.visit((ConditionalExpression)itStatement);
	}else if (itStatement instanceof SwitchCase){
		this.visitor.visit((SwitchCase)itStatement);
	}else if (itStatement instanceof DoStatement){
		this.visitor.visit((DoStatement)itStatement);
	}else if (itStatement instanceof ExpressionStatement){
		this.visitor.visit((ExpressionStatement)itStatement);
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:28,代码来源:WeightMethodsPerClassVisitor.java

示例4: collectIfStatements

import org.eclipse.jdt.core.dom.IfStatement; //导入依赖的package包/类
private List<IfStatement> collectIfStatements(MethodDeclaration md) {
List<IfStatement> ifStatements = new ArrayList<IfStatement>();

Block body = md.getBody();

if (body == null) {
    return ifStatements;
}

for (Object statement : body.statements()) {
    if (statement instanceof Statement) {
	Statement st = (Statement) statement;
	ifStatements.addAll(collectIfStatements(st));
    }
}

return ifStatements;
   }
 
开发者ID:junit-tools-team,项目名称:junit-tools,代码行数:19,代码来源:MethodAnalyzer.java

示例5: locationNeedsParentheses

import org.eclipse.jdt.core.dom.IfStatement; //导入依赖的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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:28,代码来源:NecessaryParenthesesChecker.java

示例6: rewriteAST

import org.eclipse.jdt.core.dom.IfStatement; //导入依赖的package包/类
/** {@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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:ControlStatementsFix.java

示例7: isSingleControlStatementWithoutBlock

import org.eclipse.jdt.core.dom.IfStatement; //导入依赖的package包/类
private boolean isSingleControlStatementWithoutBlock() {
  List<Statement> statements = fDeclaration.getBody().statements();
  int size = statements.size();
  if (size != 1) return false;
  Statement statement = statements.get(size - 1);
  int nodeType = statement.getNodeType();
  if (nodeType == ASTNode.IF_STATEMENT) {
    IfStatement ifStatement = (IfStatement) statement;
    return !(ifStatement.getThenStatement() instanceof Block)
        && !(ifStatement.getElseStatement() instanceof Block);
  } else if (nodeType == ASTNode.FOR_STATEMENT) {
    return !(((ForStatement) statement).getBody() instanceof Block);
  } else if (nodeType == ASTNode.WHILE_STATEMENT) {
    return !(((WhileStatement) statement).getBody() instanceof Block);
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:SourceProvider.java

示例8: needsBlockAroundDanglingIf

import org.eclipse.jdt.core.dom.IfStatement; //导入依赖的package包/类
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();
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:CallInliner.java

示例9: insertIfStatement

import org.eclipse.jdt.core.dom.IfStatement; //导入依赖的package包/类
@Override
public void insertIfStatement(IfStatement ifStmt, Block thenBlock) {
  // when stmt declares a local variable (see RearrangeStrategy.create(..)) we need to move
  // all
  // subsequent statements into the then-block to ensure that the existing declared local is
  // visible:
  List<ASTNode> blockStmts = this.block.statements();
  int stmtIdx = blockStmts.indexOf(this.origStmt);
  int lastIdx = blockStmts.size() - 1;
  if (stmtIdx != -1 && stmtIdx < lastIdx) {
    thenBlock
        .statements()
        .add(
            this.blockRewrite.createMoveTarget(
                blockStmts.get(stmtIdx + 1), blockStmts.get(lastIdx), null, this.group));
  }
  super.insertIfStatement(ifStmt, thenBlock);
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:ExtractToNullCheckedLocalProposal.java

示例10: preNext

import org.eclipse.jdt.core.dom.IfStatement; //导入依赖的package包/类
@Override
public boolean preNext(IfStatement curElement) {

	Statement thenStatement = curElement.getThenStatement();
	Statement elseStatement = curElement.getElseStatement();
	Expression condition = curElement.getExpression();

	if (elseStatement == null) {
		compiler.println("opt " + condition.toString());
		return true;
	} else {
		compiler.println("alt " + condition.toString());
		thenStatement.accept(compiler);
		if (elseStatement instanceof IfStatement) {
			processAltStatement((IfStatement) elseStatement);
		} else {
			compiler.println("else");
			elseStatement.accept(compiler);
		}
		return false;
	}
}
 
开发者ID:ELTE-Soft,项目名称:txtUML,代码行数:23,代码来源:OptAltFragment.java

示例11: processAltStatement

import org.eclipse.jdt.core.dom.IfStatement; //导入依赖的package包/类
private void processAltStatement(IfStatement statement) {
	Statement thenStatement = statement.getThenStatement();
	Statement elseStatement = statement.getElseStatement();
	Expression condition = statement.getExpression();

	compiler.println("else " + condition.toString());
	thenStatement.accept(compiler);
	if (elseStatement != null) {
		if (elseStatement instanceof IfStatement) {
			processAltStatement((IfStatement) elseStatement);
		} else {
			compiler.println("else");
			elseStatement.accept(compiler);
		}
	}
}
 
开发者ID:ELTE-Soft,项目名称:txtUML,代码行数:17,代码来源:OptAltFragment.java

示例12: isSingleControlStatementWithoutBlock

import org.eclipse.jdt.core.dom.IfStatement; //导入依赖的package包/类
private boolean isSingleControlStatementWithoutBlock() {
	List<Statement> statements= fDeclaration.getBody().statements();
	int size= statements.size();
	if (size != 1)
		return false;
	Statement statement= statements.get(size - 1);
	int nodeType= statement.getNodeType();
	if (nodeType == ASTNode.IF_STATEMENT) {
		IfStatement ifStatement= (IfStatement) statement;
		return !(ifStatement.getThenStatement() instanceof Block)
			&& !(ifStatement.getElseStatement() instanceof Block);
	} else if (nodeType == ASTNode.FOR_STATEMENT) {
		return !(((ForStatement)statement).getBody() instanceof Block);
	} else if (nodeType == ASTNode.WHILE_STATEMENT) {
		return !(((WhileStatement)statement).getBody() instanceof Block);
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:SourceProvider.java

示例13: needsBlockAroundDanglingIf

import org.eclipse.jdt.core.dom.IfStatement; //导入依赖的package包/类
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();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:CallInliner.java

示例14: addMemberCheckNull

import org.eclipse.jdt.core.dom.IfStatement; //导入依赖的package包/类
@Override
protected void addMemberCheckNull(Object member, boolean addSeparator) {
	IfStatement ifStatement= fAst.newIfStatement();
	ifStatement.setExpression(createInfixExpression(createMemberAccessExpression(member, true, true), Operator.NOT_EQUALS, fAst.newNullLiteral()));
	Block thenBlock= fAst.newBlock();
	flushBuffer(null);
	String[] arrayString= getContext().getTemplateParser().getBody();
	for (int i= 0; i < arrayString.length; i++) {
		addElement(processElement(arrayString[i], member), thenBlock);
	}
	if (addSeparator)
		addElement(getContext().getTemplateParser().getSeparator(), thenBlock);
	flushBuffer(thenBlock);

	if (thenBlock.statements().size() == 1 && !getContext().isForceBlocks()) {
		ifStatement.setThenStatement((Statement)ASTNode.copySubtree(fAst, (ASTNode)thenBlock.statements().get(0)));
	} else {
		ifStatement.setThenStatement(thenBlock);
	}
	toStringMethod.getBody().statements().add(ifStatement);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:StringBuilderGenerator.java

示例15: addMemberCheckNull

import org.eclipse.jdt.core.dom.IfStatement; //导入依赖的package包/类
@Override
protected void addMemberCheckNull(Object member, boolean addSeparator) {
	IfStatement ifStatement= fAst.newIfStatement();
	ifStatement.setExpression(createInfixExpression(createMemberAccessExpression(member, true, true), Operator.NOT_EQUALS, fAst.newNullLiteral()));
	Block thenBlock= fAst.newBlock();
	flushTemporaryExpression();
	String[] arrayString= getContext().getTemplateParser().getBody();
	for (int i= 0; i < arrayString.length; i++) {
		addElement(processElement(arrayString[i], member), thenBlock);
	}
	if (addSeparator)
		addElement(getContext().getTemplateParser().getSeparator(), thenBlock);
	flushTemporaryExpression();

	if (thenBlock.statements().size() == 1 && !getContext().isForceBlocks()) {
		ifStatement.setThenStatement((Statement)ASTNode.copySubtree(fAst, (ASTNode)thenBlock.statements().get(0)));
	} else {
		ifStatement.setThenStatement(thenBlock);
	}
	toStringMethod.getBody().statements().add(ifStatement);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:StringBuilderChainGenerator.java


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