本文整理汇总了Java中org.eclipse.jdt.core.dom.LambdaExpression类的典型用法代码示例。如果您正苦于以下问题:Java LambdaExpression类的具体用法?Java LambdaExpression怎么用?Java LambdaExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LambdaExpression类属于org.eclipse.jdt.core.dom包,在下文中一共展示了LambdaExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getType
import org.eclipse.jdt.core.dom.LambdaExpression; //导入依赖的package包/类
/**
* Returns the type node for the given declaration.
*
* @param declaration the declaration
* @return the type node or <code>null</code> if the given declaration represents a type
* inferred parameter in lambda expression
*/
public static Type getType(VariableDeclaration declaration) {
if (declaration instanceof SingleVariableDeclaration) {
return ((SingleVariableDeclaration)declaration).getType();
} else if (declaration instanceof VariableDeclarationFragment) {
ASTNode parent= ((VariableDeclarationFragment)declaration).getParent();
if (parent instanceof VariableDeclarationExpression) {
return ((VariableDeclarationExpression)parent).getType();
} else if (parent instanceof VariableDeclarationStatement) {
return ((VariableDeclarationStatement)parent).getType();
} else if (parent instanceof FieldDeclaration) {
return ((FieldDeclaration)parent).getType();
} else if (parent instanceof LambdaExpression) {
return null;
}
}
Assert.isTrue(false, "Unknown VariableDeclaration"); //$NON-NLS-1$
return null;
}
示例2: getDimensions
import org.eclipse.jdt.core.dom.LambdaExpression; //导入依赖的package包/类
public static int getDimensions(VariableDeclaration declaration) {
int dim= declaration.getExtraDimensions();
if (declaration instanceof VariableDeclarationFragment && declaration.getParent() instanceof LambdaExpression) {
LambdaExpression lambda= (LambdaExpression) declaration.getParent();
IMethodBinding methodBinding= lambda.resolveMethodBinding();
if (methodBinding != null) {
ITypeBinding[] parameterTypes= methodBinding.getParameterTypes();
int index= lambda.parameters().indexOf(declaration);
ITypeBinding typeBinding= parameterTypes[index];
return typeBinding.getDimensions();
}
} else {
Type type= getType(declaration);
if (type instanceof ArrayType) {
dim+= ((ArrayType) type).getDimensions();
}
}
return dim;
}
示例3: newType
import org.eclipse.jdt.core.dom.LambdaExpression; //导入依赖的package包/类
private static Type newType(LambdaExpression lambdaExpression, VariableDeclarationFragment declaration, AST ast, ImportRewrite importRewrite, ImportRewriteContext context) {
IMethodBinding method= lambdaExpression.resolveMethodBinding();
if (method != null) {
ITypeBinding[] parameterTypes= method.getParameterTypes();
int index= lambdaExpression.parameters().indexOf(declaration);
ITypeBinding typeBinding= parameterTypes[index];
if (importRewrite != null) {
return importRewrite.addImport(typeBinding, ast, context);
} else {
String qualifiedName= typeBinding.getQualifiedName();
if (qualifiedName.length() > 0) {
return newType(ast, qualifiedName);
}
}
}
// fall-back
return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
示例4: newReturnType
import org.eclipse.jdt.core.dom.LambdaExpression; //导入依赖的package包/类
/**
* Returns the new type node representing the return type of <code>lambdaExpression</code>
* including the extra dimensions.
*
* @param lambdaExpression the lambda expression
* @param ast the AST to create the return type with
* @param importRewrite the import rewrite to use, or <code>null</code>
* @param context the import rewrite context, or <code>null</code>
* @return a new type node created with the given AST representing the return type of
* <code>lambdaExpression</code>
*
* @since 3.10
*/
public static Type newReturnType(LambdaExpression lambdaExpression, AST ast, ImportRewrite importRewrite, ImportRewriteContext context) {
IMethodBinding method= lambdaExpression.resolveMethodBinding();
if (method != null) {
ITypeBinding returnTypeBinding= method.getReturnType();
if (importRewrite != null) {
return importRewrite.addImport(returnTypeBinding, ast);
} else {
String qualifiedName= returnTypeBinding.getQualifiedName();
if (qualifiedName.length() > 0) {
return newType(ast, qualifiedName);
}
}
}
// fall-back
return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
示例5: isVoidMethod
import org.eclipse.jdt.core.dom.LambdaExpression; //导入依赖的package包/类
private boolean isVoidMethod() {
ITypeBinding binding = null;
LambdaExpression enclosingLambdaExpr = ASTResolving.findEnclosingLambdaExpression(getFirstSelectedNode());
if (enclosingLambdaExpr != null) {
IMethodBinding methodBinding = enclosingLambdaExpr.resolveMethodBinding();
if (methodBinding != null) {
binding = methodBinding.getReturnType();
}
} else {
// if we have an initializer
if (fEnclosingMethodBinding == null) {
return true;
}
binding = fEnclosingMethodBinding.getReturnType();
}
if (fEnclosingBodyDeclaration.getAST().resolveWellKnownType("void").equals(binding)) {
return true;
}
return false;
}
示例6: newType
import org.eclipse.jdt.core.dom.LambdaExpression; //导入依赖的package包/类
private static Type newType(
LambdaExpression lambdaExpression,
VariableDeclarationFragment declaration,
AST ast,
ImportRewrite importRewrite,
ImportRewriteContext context) {
IMethodBinding method = lambdaExpression.resolveMethodBinding();
if (method != null) {
ITypeBinding[] parameterTypes = method.getParameterTypes();
int index = lambdaExpression.parameters().indexOf(declaration);
ITypeBinding typeBinding = parameterTypes[index];
if (importRewrite != null) {
return importRewrite.addImport(typeBinding, ast, context);
} else {
String qualifiedName = typeBinding.getQualifiedName();
if (qualifiedName.length() > 0) {
return newType(ast, qualifiedName);
}
}
}
// fall-back
return ast.newSimpleType(ast.newSimpleName("Object")); // $NON-NLS-1$
}
示例7: newReturnType
import org.eclipse.jdt.core.dom.LambdaExpression; //导入依赖的package包/类
/**
* Returns the new type node representing the return type of <code>lambdaExpression</code>
* including the extra dimensions.
*
* @param lambdaExpression the lambda expression
* @param ast the AST to create the return type with
* @param importRewrite the import rewrite to use, or <code>null</code>
* @param context the import rewrite context, or <code>null</code>
* @return a new type node created with the given AST representing the return type of <code>
* lambdaExpression</code>
* @since 3.10
*/
public static Type newReturnType(
LambdaExpression lambdaExpression,
AST ast,
ImportRewrite importRewrite,
ImportRewriteContext context) {
IMethodBinding method = lambdaExpression.resolveMethodBinding();
if (method != null) {
ITypeBinding returnTypeBinding = method.getReturnType();
if (importRewrite != null) {
return importRewrite.addImport(returnTypeBinding, ast);
} else {
String qualifiedName = returnTypeBinding.getQualifiedName();
if (qualifiedName.length() > 0) {
return newType(ast, qualifiedName);
}
}
}
// fall-back
return ast.newSimpleType(ast.newSimpleName("Object")); // $NON-NLS-1$
}
示例8: createConvertToAnonymousClassCreationsFix
import org.eclipse.jdt.core.dom.LambdaExpression; //导入依赖的package包/类
public static IProposableFix createConvertToAnonymousClassCreationsFix(LambdaExpression lambda) {
// offer the quick assist at pre 1.8 levels as well to get rid of the compilation error (TODO:
// offer this as a quick fix in that
// case)
if (lambda.resolveTypeBinding() == null
|| lambda.resolveTypeBinding().getFunctionalInterfaceMethod() == null) return null;
CreateAnonymousClassCreationOperation op =
new CreateAnonymousClassCreationOperation(Collections.singletonList(lambda));
CompilationUnit root = (CompilationUnit) lambda.getRoot();
return new LambdaExpressionsFix(
FixMessages.LambdaExpressionsFix_convert_to_anonymous_class_creation,
root,
new CompilationUnitRewriteOperation[] {op});
}
示例9: createOccurrenceUpdate
import org.eclipse.jdt.core.dom.LambdaExpression; //导入依赖的package包/类
private OccurrenceUpdate<? extends ASTNode> createOccurrenceUpdate(
ASTNode node, CompilationUnitRewrite cuRewrite, RefactoringStatus result) {
if (BUG_89686
&& node instanceof SimpleName
&& node.getParent() instanceof EnumConstantDeclaration) node = node.getParent();
if (Invocations.isInvocationWithArguments(node))
return new ReferenceUpdate(node, cuRewrite, result);
else if (node instanceof SimpleName && node.getParent() instanceof MethodDeclaration)
return new DeclarationUpdate((MethodDeclaration) node.getParent(), cuRewrite, result);
else if (node instanceof MemberRef || node instanceof MethodRef)
return new DocReferenceUpdate(node, cuRewrite, result);
else if (ASTNodes.getParent(node, ImportDeclaration.class) != null)
return new StaticImportUpdate(
(ImportDeclaration) ASTNodes.getParent(node, ImportDeclaration.class), cuRewrite, result);
else if (node instanceof LambdaExpression)
return new LambdaExpressionUpdate((LambdaExpression) node, cuRewrite, result);
else if (node.getLocationInParent() == ExpressionMethodReference.NAME_PROPERTY)
return new ExpressionMethodRefUpdate(
(ExpressionMethodReference) node.getParent(), cuRewrite, result);
else return new NullOccurrenceUpdate(node, cuRewrite, result);
}
示例10: getFullTypeName
import org.eclipse.jdt.core.dom.LambdaExpression; //导入依赖的package包/类
protected String getFullTypeName() {
ASTNode node = getNode();
while (true) {
node = node.getParent();
if (node instanceof AbstractTypeDeclaration) {
String typeName = ((AbstractTypeDeclaration) node).getName().getIdentifier();
if (getNode() instanceof LambdaExpression) {
return Messages.format(
RefactoringCoreMessages.ChangeSignatureRefactoring_lambda_expression, typeName);
}
return typeName;
} else if (node instanceof ClassInstanceCreation) {
ClassInstanceCreation cic = (ClassInstanceCreation) node;
return Messages.format(
RefactoringCoreMessages.ChangeSignatureRefactoring_anonymous_subclass,
BasicElementLabels.getJavaElementName(ASTNodes.asString(cic.getType())));
} else if (node instanceof EnumConstantDeclaration) {
EnumDeclaration ed = (EnumDeclaration) node.getParent();
return Messages.format(
RefactoringCoreMessages.ChangeSignatureRefactoring_anonymous_subclass,
BasicElementLabels.getJavaElementName(ASTNodes.asString(ed.getName())));
}
}
}
示例11: checkInitialConditions
import org.eclipse.jdt.core.dom.LambdaExpression; //导入依赖的package包/类
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
initAST();
if (fTempDeclarationNode == null || fTempDeclarationNode.resolveBinding() == null)
return RefactoringStatus.createFatalErrorStatus(
RefactoringCoreMessages.RenameTempRefactoring_must_select_local);
if (!Checks.isDeclaredIn(fTempDeclarationNode, MethodDeclaration.class)
&& !Checks.isDeclaredIn(fTempDeclarationNode, Initializer.class)
&& !Checks.isDeclaredIn(fTempDeclarationNode, LambdaExpression.class)) {
if (JavaModelUtil.is18OrHigher(fCu.getJavaProject()))
return RefactoringStatus.createFatalErrorStatus(
RefactoringCoreMessages.RenameTempRefactoring_only_in_methods_initializers_and_lambda);
return RefactoringStatus.createFatalErrorStatus(
RefactoringCoreMessages.RenameTempRefactoring_only_in_methods_and_initializers);
}
initNames();
return new RefactoringStatus();
}
示例12: isVoidMethod
import org.eclipse.jdt.core.dom.LambdaExpression; //导入依赖的package包/类
private boolean isVoidMethod() {
ITypeBinding binding = null;
LambdaExpression enclosingLambdaExpr =
ASTResolving.findEnclosingLambdaExpression(getFirstSelectedNode());
if (enclosingLambdaExpr != null) {
IMethodBinding methodBinding = enclosingLambdaExpr.resolveMethodBinding();
if (methodBinding != null) {
binding = methodBinding.getReturnType();
}
} else {
// if we have an initializer
if (fEnclosingMethodBinding == null) return true;
binding = fEnclosingMethodBinding.getReturnType();
}
if (fEnclosingBodyDeclaration
.getAST()
.resolveWellKnownType("void")
.equals(binding)) // $NON-NLS-1$
return true;
return false;
}
示例13: createOccurrenceUpdate
import org.eclipse.jdt.core.dom.LambdaExpression; //导入依赖的package包/类
private OccurrenceUpdate<? extends ASTNode> createOccurrenceUpdate(ASTNode node, CompilationUnitRewrite cuRewrite, RefactoringStatus result) {
if (BUG_89686 && node instanceof SimpleName && node.getParent() instanceof EnumConstantDeclaration)
node= node.getParent();
if (Invocations.isInvocationWithArguments(node))
return new ReferenceUpdate(node, cuRewrite, result);
else if (node instanceof SimpleName && node.getParent() instanceof MethodDeclaration)
return new DeclarationUpdate((MethodDeclaration) node.getParent(), cuRewrite, result);
else if (node instanceof MemberRef || node instanceof MethodRef)
return new DocReferenceUpdate(node, cuRewrite, result);
else if (ASTNodes.getParent(node, ImportDeclaration.class) != null)
return new StaticImportUpdate((ImportDeclaration) ASTNodes.getParent(node, ImportDeclaration.class), cuRewrite, result);
else if (node instanceof LambdaExpression)
return new LambdaExpressionUpdate((LambdaExpression) node, cuRewrite, result);
else if (node.getLocationInParent() == ExpressionMethodReference.NAME_PROPERTY)
return new ExpressionMethodRefUpdate((ExpressionMethodReference) node.getParent(), cuRewrite, result);
else
return new NullOccurrenceUpdate(node, cuRewrite, result);
}
示例14: getFullTypeName
import org.eclipse.jdt.core.dom.LambdaExpression; //导入依赖的package包/类
protected String getFullTypeName() {
ASTNode node= getNode();
while (true) {
node= node.getParent();
if (node instanceof AbstractTypeDeclaration) {
String typeName= ((AbstractTypeDeclaration) node).getName().getIdentifier();
if (getNode() instanceof LambdaExpression) {
return Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_lambda_expression, typeName);
}
return typeName;
} else if (node instanceof ClassInstanceCreation) {
ClassInstanceCreation cic= (ClassInstanceCreation) node;
return Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_anonymous_subclass, BasicElementLabels.getJavaElementName(ASTNodes.asString(cic.getType())));
} else if (node instanceof EnumConstantDeclaration) {
EnumDeclaration ed= (EnumDeclaration) node.getParent();
return Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_anonymous_subclass, BasicElementLabels.getJavaElementName(ASTNodes.asString(ed.getName())));
}
}
}
示例15: checkInitialConditions
import org.eclipse.jdt.core.dom.LambdaExpression; //导入依赖的package包/类
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
initAST();
if (fTempDeclarationNode == null || fTempDeclarationNode.resolveBinding() == null)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.RenameTempRefactoring_must_select_local);
if (!Checks.isDeclaredIn(fTempDeclarationNode, MethodDeclaration.class)
&& !Checks.isDeclaredIn(fTempDeclarationNode, Initializer.class)
&& !Checks.isDeclaredIn(fTempDeclarationNode, LambdaExpression.class)) {
if (JavaModelUtil.is18OrHigher(fCu.getJavaProject()))
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.RenameTempRefactoring_only_in_methods_initializers_and_lambda);
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.RenameTempRefactoring_only_in_methods_and_initializers);
}
initNames();
return new RefactoringStatus();
}