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


Java EnhancedForStatement类代码示例

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


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

示例1: locationNeedsParentheses

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入依赖的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: getEnhancedForStatements

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入依赖的package包/类
private static Set<EnhancedForStatement> getEnhancedForStatements(IMethod method, IProgressMonitor pm)
		throws JavaModelException {
	ICompilationUnit iCompilationUnit = method.getCompilationUnit();

	// get the ASTParser of the method
	CompilationUnit compilationUnit = RefactoringASTParser.parseWithASTProvider(iCompilationUnit, true,
			new SubProgressMonitor(pm, 1));

	// get the method declaration ASTNode.
	MethodDeclaration methodDeclarationNode = ASTNodeSearchUtil.getMethodDeclarationNode(method, compilationUnit);

	final Set<EnhancedForStatement> statements = new LinkedHashSet<EnhancedForStatement>();
	// extract all enhanced for loop statements in the method.
	methodDeclarationNode.accept(new ASTVisitor() {

		@Override
		public boolean visit(EnhancedForStatement node) {
			statements.add(node);
			return super.visit(node);
		}
	});

	return statements;
}
 
开发者ID:mdarefin,项目名称:Convert-For-Each-Loop-to-Lambda-Expression-Eclipse-Plugin,代码行数:25,代码来源:ForeachLoopToLambdaRefactoring.java

示例3: endVisit

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入依赖的package包/类
@Override
public void endVisit(EnhancedForStatement node) {
	if (skipNode(node)) {
		return;
	}
	FlowInfo paramInfo = getFlowInfo(node.getParameter());
	FlowInfo expressionInfo = getFlowInfo(node.getExpression());
	FlowInfo actionInfo = getFlowInfo(node.getBody());
	EnhancedForFlowInfo forInfo = createEnhancedFor();
	setFlowInfo(node, forInfo);
	// If the for statement is the outermost loop then we only have to consider
	// the action. The parameter and expression are only evaluated once.
	if (node == fLoopNode) {
		forInfo.mergeAction(actionInfo, fFlowContext);
	} else {
		// Inner for loops are evaluated in the sequence expression, parameter,
		// action.
		forInfo.mergeExpression(expressionInfo, fFlowContext);
		forInfo.mergeParameter(paramInfo, fFlowContext);
		forInfo.mergeAction(actionInfo, fFlowContext);
	}
	forInfo.removeLabel(null);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:24,代码来源:InputFlowAnalyzer.java

示例4: getParentLoopBody

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入依赖的package包/类
private Statement getParentLoopBody(ASTNode node) {
	Statement stmt = null;
	ASTNode start = node;
	while (start != null && !(start instanceof ForStatement) && !(start instanceof DoStatement) && !(start instanceof WhileStatement) && !(start instanceof EnhancedForStatement) && !(start instanceof SwitchStatement)) {
		start = start.getParent();
	}
	if (start instanceof ForStatement) {
		stmt = ((ForStatement) start).getBody();
	} else if (start instanceof DoStatement) {
		stmt = ((DoStatement) start).getBody();
	} else if (start instanceof WhileStatement) {
		stmt = ((WhileStatement) start).getBody();
	} else if (start instanceof EnhancedForStatement) {
		stmt = ((EnhancedForStatement) start).getBody();
	}
	if (start != null && start.getParent() instanceof LabeledStatement) {
		LabeledStatement labeledStatement = (LabeledStatement) start.getParent();
		fEnclosingLoopLabel = labeledStatement.getLabel();
	}
	return stmt;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:ExtractMethodAnalyzer.java

示例5: addEnhancedForWithoutTypeProposals

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入依赖的package包/类
private static void addEnhancedForWithoutTypeProposals(ICompilationUnit cu, ASTNode selectedNode,
		Collection<CUCorrectionProposal> proposals) {
	if (selectedNode instanceof SimpleName && (selectedNode.getLocationInParent() == SimpleType.NAME_PROPERTY || selectedNode.getLocationInParent() == NameQualifiedType.NAME_PROPERTY)) {
		ASTNode type= selectedNode.getParent();
		if (type.getLocationInParent() == SingleVariableDeclaration.TYPE_PROPERTY) {
			SingleVariableDeclaration svd= (SingleVariableDeclaration) type.getParent();
			if (svd.getLocationInParent() == EnhancedForStatement.PARAMETER_PROPERTY) {
				if (svd.getName().getLength() == 0) {
					SimpleName simpleName= (SimpleName) selectedNode;
					String name= simpleName.getIdentifier();
					int relevance= StubUtility.hasLocalVariableName(cu.getJavaProject(), name) ? 10 : 7;
					String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_create_loop_variable_description, BasicElementLabels.getJavaElementName(name));

					proposals.add(new NewVariableCorrectionProposal(label, cu, NewVariableCorrectionProposal.LOCAL,
							simpleName, null, relevance));
				}
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:21,代码来源:UnresolvedElementsSubProcessor.java

示例6: locationNeedsParentheses

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入依赖的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

示例7: endVisit

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入依赖的package包/类
@Override
public void endVisit(EnhancedForStatement node) {
  if (skipNode(node)) return;
  FlowInfo paramInfo = getFlowInfo(node.getParameter());
  FlowInfo expressionInfo = getFlowInfo(node.getExpression());
  FlowInfo actionInfo = getFlowInfo(node.getBody());
  EnhancedForFlowInfo forInfo = createEnhancedFor();
  setFlowInfo(node, forInfo);
  // If the for statement is the outermost loop then we only have to consider
  // the action. The parameter and expression are only evaluated once.
  if (node == fLoopNode) {
    forInfo.mergeAction(actionInfo, fFlowContext);
  } else {
    // Inner for loops are evaluated in the sequence expression, parameter,
    // action.
    forInfo.mergeExpression(expressionInfo, fFlowContext);
    forInfo.mergeParameter(paramInfo, fFlowContext);
    forInfo.mergeAction(actionInfo, fFlowContext);
  }
  forInfo.removeLabel(null);
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:InputFlowAnalyzer.java

示例8: getParentLoopBody

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入依赖的package包/类
private Statement getParentLoopBody(ASTNode node) {
  Statement stmt = null;
  ASTNode start = node;
  while (start != null
      && !(start instanceof ForStatement)
      && !(start instanceof DoStatement)
      && !(start instanceof WhileStatement)
      && !(start instanceof EnhancedForStatement)
      && !(start instanceof SwitchStatement)) {
    start = start.getParent();
  }
  if (start instanceof ForStatement) {
    stmt = ((ForStatement) start).getBody();
  } else if (start instanceof DoStatement) {
    stmt = ((DoStatement) start).getBody();
  } else if (start instanceof WhileStatement) {
    stmt = ((WhileStatement) start).getBody();
  } else if (start instanceof EnhancedForStatement) {
    stmt = ((EnhancedForStatement) start).getBody();
  }
  if (start != null && start.getParent() instanceof LabeledStatement) {
    LabeledStatement labeledStatement = (LabeledStatement) start.getParent();
    fEnclosingLoopLabel = labeledStatement.getLabel();
  }
  return stmt;
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:ExtractMethodAnalyzer.java

示例9: checkFinalConditions

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入依赖的package包/类
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm)
		throws CoreException, OperationCanceledException {
	try {
		final RefactoringStatus status = new RefactoringStatus();
		for (IMethod method : methods) {
			Set<EnhancedForStatement> statements = getEnhancedForStatements(method, new SubProgressMonitor(pm, 1));

			IProgressMonitor subMonitor = new SubProgressMonitor(pm, statements.size());

			// check preconditions on each.
			statements.stream().forEach(s -> status.merge(checkEnhancedForStatement(s, method, subMonitor)));
			pm.worked(1);
		}
		return status;
	} finally {
		pm.done();
	}
}
 
开发者ID:mdarefin,项目名称:Convert-For-Each-Loop-to-Lambda-Expression-Eclipse-Plugin,代码行数:20,代码来源:ForeachLoopToLambdaRefactoring.java

示例10: preNext

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入依赖的package包/类
@Override
public boolean preNext(Statement curElement) {
	switch (curElement.getNodeType()) {
	case ASTNode.WHILE_STATEMENT:
		exportWhile((WhileStatement) curElement);
		break;
	case ASTNode.FOR_STATEMENT:
		exportFor((ForStatement) curElement);
		break;
	case ASTNode.ENHANCED_FOR_STATEMENT:
		exportForEach((EnhancedForStatement) curElement);
		break;
	case ASTNode.DO_STATEMENT:
		exportDoWhileStatement((DoStatement) curElement);
		break;
	}

	return true;
}
 
开发者ID:ELTE-Soft,项目名称:txtUML,代码行数:20,代码来源:LoopFragment.java

示例11: endVisit

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入依赖的package包/类
@Override
public void endVisit(EnhancedForStatement node) {
	if (skipNode(node))
		return;
	FlowInfo paramInfo= getFlowInfo(node.getParameter());
	FlowInfo expressionInfo= getFlowInfo(node.getExpression());
	FlowInfo actionInfo= getFlowInfo(node.getBody());
	EnhancedForFlowInfo forInfo= createEnhancedFor();
	setFlowInfo(node, forInfo);
	// If the for statement is the outermost loop then we only have to consider
	// the action. The parameter and expression are only evaluated once.
	if (node == fLoopNode) {
		forInfo.mergeAction(actionInfo, fFlowContext);
	} else {
		// Inner for loops are evaluated in the sequence expression, parameter,
		// action.
		forInfo.mergeExpression(expressionInfo, fFlowContext);
		forInfo.mergeParameter(paramInfo, fFlowContext);
		forInfo.mergeAction(actionInfo, fFlowContext);
	}
	forInfo.removeLabel(null);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:23,代码来源:InputFlowAnalyzer.java

示例12: getParentLoopBody

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入依赖的package包/类
private Statement getParentLoopBody(ASTNode node) {
	Statement stmt= null;
	ASTNode start= node;
	while (start != null
			&& !(start instanceof ForStatement)
			&& !(start instanceof DoStatement)
			&& !(start instanceof WhileStatement)
			&& !(start instanceof EnhancedForStatement)
			&& !(start instanceof SwitchStatement)) {
		start= start.getParent();
	}
	if (start instanceof ForStatement) {
		stmt= ((ForStatement)start).getBody();
	} else if (start instanceof DoStatement) {
		stmt= ((DoStatement)start).getBody();
	} else if (start instanceof WhileStatement) {
		stmt= ((WhileStatement)start).getBody();
	} else if (start instanceof EnhancedForStatement) {
		stmt= ((EnhancedForStatement)start).getBody();
	}
	if (start != null && start.getParent() instanceof LabeledStatement) {
		LabeledStatement labeledStatement= (LabeledStatement)start.getParent();
		fEnclosingLoopLabel= labeledStatement.getLabel();
	}
	return stmt;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:27,代码来源:ExtractMethodAnalyzer.java

示例13: addEnhancedForWithoutTypeProposals

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入依赖的package包/类
private static void addEnhancedForWithoutTypeProposals(ICompilationUnit cu, ASTNode selectedNode, Collection<ICommandAccess> proposals) {
	if (selectedNode instanceof SimpleName && (selectedNode.getLocationInParent() == SimpleType.NAME_PROPERTY || selectedNode.getLocationInParent() == NameQualifiedType.NAME_PROPERTY)) {
		ASTNode type= selectedNode.getParent();
		if (type.getLocationInParent() == SingleVariableDeclaration.TYPE_PROPERTY) {
			SingleVariableDeclaration svd= (SingleVariableDeclaration) type.getParent();
			if (svd.getLocationInParent() == EnhancedForStatement.PARAMETER_PROPERTY) {
				if (svd.getName().getLength() == 0) {
					SimpleName simpleName= (SimpleName) selectedNode;
					String name= simpleName.getIdentifier();
					int relevance= StubUtility.hasLocalVariableName(cu.getJavaProject(), name) ? 10 : 7;
					String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_create_loop_variable_description, BasicElementLabels.getJavaElementName(name));
					Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_LOCAL);
					
					proposals.add(new NewVariableCorrectionProposal(label, cu, NewVariableCorrectionProposal.LOCAL, simpleName, null, relevance, image));
				}
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:20,代码来源:UnresolvedElementsSubProcessor.java

示例14: isLastStatementInEnclosingMethodOrLambda

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入依赖的package包/类
private static boolean isLastStatementInEnclosingMethodOrLambda(Statement statement) {
	ASTNode currentStructure= statement;
	ASTNode currentParent= statement.getParent();
	while (!(currentParent instanceof MethodDeclaration || currentParent instanceof LambdaExpression)) {
		// should not be in a loop
		if (currentParent instanceof ForStatement || currentParent instanceof EnhancedForStatement
				|| currentParent instanceof WhileStatement || currentParent instanceof DoStatement) {
			return false;
		}
		if (currentParent instanceof Block) {
			Block parentBlock= (Block) currentParent;
			if (parentBlock.statements().indexOf(currentStructure) != parentBlock.statements().size() - 1) { // not last statement in the block
				return false;
			}
		}
		currentStructure= currentParent;
		currentParent= currentParent.getParent();
	}
	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:AdvancedQuickAssistProcessor.java

示例15: visit

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入依赖的package包/类
/**
 * 'for(' parameter ':' expression ') {' body '}'
 */
@Override
public boolean visit(final EnhancedForStatement node)
{
  final int lineNo = lineStart(node);
  // new dependence
  final IResolvedLine rd = createDependence(LK_ENHANCED_FOR, lineNo, mdg.parent());
  // add this definition
  rd.definitions().add(
      factory.resolveExpression(node.getParameter().getName(), node, null, false, true));
  // collect uses for this control predicate
  appendDependences(rd, node.getExpression(), null, false);
  // recursively append dependences
  appendRecursive(lineNo, rd, node.getBody());
  // do not visit children
  return false;
}
 
开发者ID:UBPL,项目名称:jive,代码行数:20,代码来源:StatementVisitor.java


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