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


Java LambdaExpression.parameters方法代码示例

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


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

示例1: prepareLambdaParameters

import org.eclipse.jdt.core.dom.LambdaExpression; //导入方法依赖的package包/类
private void prepareLambdaParameters(AST ast, ASTRewrite rewriter, List<SingleVariableDeclaration> methodParameters,
		boolean createExplicitlyTypedParameters, LambdaExpression lambdaExpression) {
	List<VariableDeclaration> lambdaParameters = lambdaExpression.parameters();
	lambdaExpression.setParentheses(createExplicitlyTypedParameters || methodParameters.size() != 1);
	for (SingleVariableDeclaration methodParameter : methodParameters) {
		if (createExplicitlyTypedParameters) {
			lambdaParameters.add((SingleVariableDeclaration) rewriter.createCopyTarget(methodParameter));
			// TODO(fap): handle import
		} else {
			VariableDeclarationFragment lambdaParameter = ast.newVariableDeclarationFragment();
			SimpleName name = (SimpleName) rewriter.createCopyTarget(methodParameter.getName());
			lambdaParameter.setName(name);
			lambdaParameters.add(lambdaParameter);
		}
	}
}
 
开发者ID:vogellacompany,项目名称:codemodify,代码行数:17,代码来源:LambdaConverterFix.java

示例2: isExplicitlyTypedLambda

import org.eclipse.jdt.core.dom.LambdaExpression; //导入方法依赖的package包/类
/**
 * Checks whether the given expression is a lambda expression with explicitly typed parameters.
 *
 * @param expression the expression to check
 * @return <code>true</code> if the expression is a lambda expression with explicitly typed
 *         parameters or no parameters, <code>false</code> otherwise
 */
public static boolean isExplicitlyTypedLambda(Expression expression) {
	if (!(expression instanceof LambdaExpression)) {
		return false;
	}
	LambdaExpression lambda= (LambdaExpression) expression;
	List<VariableDeclaration> parameters= lambda.parameters();
	if (parameters.isEmpty()) {
		return true;
	}
	return parameters.get(0) instanceof SingleVariableDeclaration;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:19,代码来源:ASTNodes.java

示例3: isExplicitlyTypedLambda

import org.eclipse.jdt.core.dom.LambdaExpression; //导入方法依赖的package包/类
private static boolean isExplicitlyTypedLambda(Expression expression) {
	if (!(expression instanceof LambdaExpression))
		return false;
	LambdaExpression lambda= (LambdaExpression) expression;
	List<VariableDeclaration> parameters= lambda.parameters();
	if (parameters.isEmpty())
		return true;
	return parameters.get(0) instanceof SingleVariableDeclaration;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:10,代码来源:ASTNodes.java

示例4: rewriteAST

import org.eclipse.jdt.core.dom.LambdaExpression; //导入方法依赖的package包/类
/**
		 * {@inheritDoc}
		 */
		@Override
		public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {

			ASTRewrite rewrite= cuRewrite.getASTRewrite();
			ImportRemover importRemover= cuRewrite.getImportRemover();
			AST ast= rewrite.getAST();

			HashMap<ClassInstanceCreation, HashSet<String>> cicToNewNames= new HashMap<ClassInstanceCreation, HashSet<String>>();
			for (int i= 0; i < fExpressions.size(); i++) {
				ClassInstanceCreation classInstanceCreation= fExpressions.get(i);
				TextEditGroup group= createTextEditGroup(FixMessages.LambdaExpressionsFix_convert_to_lambda_expression, cuRewrite);

				AnonymousClassDeclaration anonymTypeDecl= classInstanceCreation.getAnonymousClassDeclaration();
				List<BodyDeclaration> bodyDeclarations= anonymTypeDecl.bodyDeclarations();

				Object object= bodyDeclarations.get(0);
				if (!(object instanceof MethodDeclaration))
					continue;
				MethodDeclaration methodDeclaration= (MethodDeclaration) object;
				HashSet<String> excludedNames= new HashSet<String>();
				if (i != 0) {
					for (ClassInstanceCreation convertedCic : fExpressions.subList(0, i)) {
						if (ASTNodes.isParent(classInstanceCreation, convertedCic)) {
							excludedNames.addAll(cicToNewNames.get(convertedCic));
						}
					}
				}
				HashSet<String> newNames= makeNamesUnique(excludedNames, methodDeclaration, rewrite, group);
				cicToNewNames.put(classInstanceCreation, new HashSet<String>(newNames));
				List<SingleVariableDeclaration> methodParameters= methodDeclaration.parameters();

				// use short form with inferred parameter types and without parentheses if possible
				LambdaExpression lambdaExpression= ast.newLambdaExpression();
				List<VariableDeclaration> lambdaParameters= lambdaExpression.parameters();
				lambdaExpression.setParentheses(methodParameters.size() != 1);
				for (SingleVariableDeclaration methodParameter : methodParameters) {
					VariableDeclarationFragment lambdaParameter= ast.newVariableDeclarationFragment();
					lambdaParameter.setName((SimpleName) rewrite.createCopyTarget(methodParameter.getName()));
					lambdaParameters.add(lambdaParameter);
				}
				
				Block body= methodDeclaration.getBody();
				List<Statement> statements= body.statements();
				ASTNode lambdaBody= body;
				if (statements.size() == 1) {
					// use short form with just an expression body if possible
					Statement statement= statements.get(0);
					if (statement instanceof ExpressionStatement) {
						lambdaBody= ((ExpressionStatement) statement).getExpression();
					} else if (statement instanceof ReturnStatement) {
						Expression returnExpression= ((ReturnStatement) statement).getExpression();
						if (returnExpression != null) {
							lambdaBody= returnExpression;
						}
					}
				}
				//TODO: Bug 421479: [1.8][clean up][quick assist] convert anonymous to lambda must consider lost scope of interface
//				lambdaBody.accept(new InterfaceAccessQualifier(rewrite, classInstanceCreation.getType().resolveBinding())); //TODO: maybe need a separate ASTRewrite and string placeholder
				
				lambdaExpression.setBody(rewrite.createCopyTarget(lambdaBody));
				Expression replacement= lambdaExpression;
				if (ASTNodes.isTargetAmbiguous(classInstanceCreation, lambdaParameters.isEmpty())) {
					CastExpression cast= ast.newCastExpression();
					cast.setExpression(lambdaExpression);
					ImportRewrite importRewrite= cuRewrite.getImportRewrite();
					ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(classInstanceCreation, importRewrite);
					Type castType= importRewrite.addImport(classInstanceCreation.getType().resolveBinding(), ast, importRewriteContext);
					cast.setType(castType);
					importRemover.registerAddedImports(castType);
					replacement= cast;
				}
				rewrite.replace(classInstanceCreation, replacement, group);

				importRemover.registerRemovedNode(classInstanceCreation);
				importRemover.registerRetainedNode(lambdaBody);
			}
		}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:81,代码来源:LambdaExpressionsFix.java


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