Java 类org.eclipse.jdt.core.dom.LambdaExpression 实例源码

项目:eclipse.jdt.ls    文件:ASTNodes.java   
/**
 * 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;
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
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;
}
项目:eclipse.jdt.ls    文件:ASTNodeFactory.java   
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$
}
项目:eclipse.jdt.ls    文件:ASTNodeFactory.java   
/**
 * 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$
}
项目:eclipse.jdt.ls    文件:ExtractMethodAnalyzer.java   
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;
}
项目:che    文件:ASTNodeFactory.java   
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$
}
项目:che    文件:ASTNodeFactory.java   
/**
 * 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$
}
项目:che    文件:LambdaExpressionsFix.java   
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});
}
项目:che    文件:ChangeSignatureProcessor.java   
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);
}
项目:che    文件:ChangeSignatureProcessor.java   
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())));
    }
  }
}
项目:che    文件:RenameLocalVariableProcessor.java   
@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();
}
项目:che    文件:ExtractMethodAnalyzer.java   
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;
}
项目:Eclipse-Postfix-Code-Completion    文件:ChangeSignatureProcessor.java   
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);
}
项目:Eclipse-Postfix-Code-Completion    文件:ChangeSignatureProcessor.java   
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())));
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameLocalVariableProcessor.java   
@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();
}
项目:Eclipse-Postfix-Code-Completion    文件:ExtractMethodAnalyzer.java   
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;
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTNodes.java   
/**
 * 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;
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTNodes.java   
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;
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTNodeFactory.java   
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$
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTNodeFactory.java   
/**
 * 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$
}
项目:Eclipse-Postfix-Code-Completion    文件:AdvancedQuickAssistProcessor.java   
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;
}
项目:codemodify    文件:LambdaConverterFix.java   
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);
        }
    }
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
/**
 * 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;
}
项目:eclipse.jdt.ls    文件:FlowAnalyzer.java   
@Override
public void endVisit(LambdaExpression node) {
    if (skipNode(node)) {
        return;
    }
    GenericSequentialFlowInfo info = createSequential(node);
    process(info, node.parameters());
    process(info, node.getBody());
    info.setNoReturn();
}
项目:eclipse.jdt.ls    文件:ExtractMethodAnalyzer.java   
@Override
public boolean visit(LambdaExpression node) {
    Selection selection = getSelection();
    int selectionStart = selection.getOffset();
    int selectionExclusiveEnd = selection.getExclusiveEnd();
    int lambdaStart = node.getStartPosition();
    int lambdaExclusiveEnd = lambdaStart + node.getLength();
    ASTNode body = node.getBody();
    int bodyStart = body.getStartPosition();
    int bodyExclusiveEnd = bodyStart + body.getLength();

    boolean isValidSelection = false;
    if ((body instanceof Block) && (bodyStart < selectionStart && selectionExclusiveEnd <= bodyExclusiveEnd)) {
        // if selection is inside lambda body's block
        isValidSelection = true;
    } else if (body instanceof Expression) {
        try {
            TokenScanner scanner = new TokenScanner(fCUnit);
            int arrowExclusiveEnd = scanner.getTokenEndOffset(ITerminalSymbols.TokenNameARROW, lambdaStart);
            if (selectionStart >= arrowExclusiveEnd) {
                isValidSelection = true;
            }
        } catch (CoreException e) {
            // ignore
        }
    }
    if (selectionStart <= lambdaStart && selectionExclusiveEnd >= lambdaExclusiveEnd) {
        // if selection covers the lambda node
        isValidSelection = true;
    }

    if (!isValidSelection) {
        return false;
    }
    return super.visit(node);
}
项目:eclipse.jdt.ls    文件:SurroundWithAnalyzer.java   
@Override
public void endVisit(CompilationUnit node) {
    postProcessSelectedNodes(internalGetSelectedNodes());
    ASTNode enclosingNode = null;
    superCall: {
        if (getStatus().hasFatalError()) {
            break superCall;
        }
        if (!hasSelectedNodes()) {
            ASTNode coveringNode = getLastCoveringNode();
            if (coveringNode instanceof Block) {
                Block block = (Block) coveringNode;
                Message[] messages = ASTNodes.getMessages(block, ASTNodes.NODE_ONLY);
                if (messages.length > 0) {
                    invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_compile_errors, JavaStatusContext.create(getCompilationUnit(), block));
                    break superCall;
                }
            }
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotCover);
            break superCall;
        }
        enclosingNode = getEnclosingNode(getFirstSelectedNode());
        boolean isValidEnclosingNode = enclosingNode instanceof MethodDeclaration || enclosingNode instanceof Initializer;
        if (fSurroundWithTryCatch) {
            isValidEnclosingNode = isValidEnclosingNode || enclosingNode instanceof MethodReference || enclosingNode.getLocationInParent() == LambdaExpression.BODY_PROPERTY;
        }
        if (!isValidEnclosingNode) {
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotContain);
            break superCall;
        }
        if (!validSelectedNodes()) {
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_onlyStatements);
        }
        fLocals = LocalDeclarationAnalyzer.perform(enclosingNode, getSelection());
    }
    super.endVisit(node);
}
项目:eclipse.jdt.ls    文件:SurroundWithAnalyzer.java   
private boolean validSelectedNodes() {
    ASTNode[] nodes = getSelectedNodes();
    for (int i = 0; i < nodes.length; i++) {
        ASTNode node = nodes[i];
        boolean isValidNode = node instanceof Statement;
        if (fSurroundWithTryCatch) { // allow method reference and lambda's expression body also
            isValidNode = isValidNode || node instanceof MethodReference || node.getLocationInParent() == LambdaExpression.BODY_PROPERTY;
        }
        if (!isValidNode) {
            return false;
        }
    }
    return true;
}
项目:eclipse.jdt.ls    文件:SurroundWithAnalyzer.java   
public static ASTNode getEnclosingNode(ASTNode firstSelectedNode) {
    ASTNode enclosingNode;
    if (firstSelectedNode instanceof MethodReference) {
        enclosingNode = firstSelectedNode;
    } else {
        enclosingNode = ASTResolving.findEnclosingLambdaExpression(firstSelectedNode);
        if (enclosingNode != null) {
            enclosingNode = ((LambdaExpression) enclosingNode).getBody();
        } else {
            enclosingNode = ASTNodes.getParent(firstSelectedNode, BodyDeclaration.class);
        }
    }
    return enclosingNode;
}
项目:che    文件:LambdaExpressionsFix.java   
@Override
public boolean visit(LambdaExpression node) {
  ITypeBinding typeBinding = node.resolveTypeBinding();
  if (typeBinding != null && typeBinding.getFunctionalInterfaceMethod() != null) {
    fNodes.add(node);
  }
  return true;
}
项目:che    文件:ChangeSignatureProcessor.java   
protected LambdaExpressionUpdate(
    LambdaExpression decl, CompilationUnitRewrite cuRewrite, RefactoringStatus result) {
  super(
      cuRewrite,
      cuRewrite.createGroupDescription(
          RefactoringCoreMessages.ChangeSignatureRefactoring_change_signature),
      result);
  fLambdaDecl = decl;
}
项目:che    文件:RefactoringAnalyzeUtil.java   
public static LambdaExpression getLambdaExpression(
    TextEdit edit, TextChange change, CompilationUnit cuNode) {
  ASTNode decl =
      RefactoringAnalyzeUtil.findSimpleNameNode(
          RefactoringAnalyzeUtil.getNewTextRange(edit, change), cuNode);
  return ((LambdaExpression) ASTNodes.getParent(decl, LambdaExpression.class));
}
项目:che    文件:ExtractMethodAnalyzer.java   
@Override
public boolean visit(LambdaExpression node) {
  Selection selection = getSelection();
  int selectionStart = selection.getOffset();
  int selectionExclusiveEnd = selection.getExclusiveEnd();
  int lambdaStart = node.getStartPosition();
  int lambdaExclusiveEnd = lambdaStart + node.getLength();
  ASTNode body = node.getBody();
  int bodyStart = body.getStartPosition();
  int bodyExclusiveEnd = bodyStart + body.getLength();

  boolean isValidSelection = false;
  if ((body instanceof Block)
      && (bodyStart < selectionStart && selectionExclusiveEnd <= bodyExclusiveEnd)) {
    // if selection is inside lambda body's block
    isValidSelection = true;
  } else if (body instanceof Expression) {
    try {
      TokenScanner scanner = new TokenScanner(fCUnit);
      int arrowExclusiveEnd =
          scanner.getTokenEndOffset(ITerminalSymbols.TokenNameARROW, lambdaStart);
      if (selectionStart >= arrowExclusiveEnd) {
        isValidSelection = true;
      }
    } catch (CoreException e) {
      // ignore
    }
  }
  if (selectionStart <= lambdaStart && selectionExclusiveEnd >= lambdaExclusiveEnd) {
    // if selection covers the lambda node
    isValidSelection = true;
  }

  if (!isValidSelection) {
    return false;
  }
  return super.visit(node);
}
项目:che    文件:ExceptionAnalyzer.java   
@Override
public boolean visit(LambdaExpression node) {
  /*
   * FIXME: Remove this method. It's just a workaround for bug 433426.
   * ExceptionAnalyzer forces clients to on the wrong enclosing node (BodyDeclaration instead of LambdaExpression's body).
   */
  return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:FlowAnalyzer.java   
@Override
public void endVisit(LambdaExpression node) {
    if (skipNode(node))
        return;
    GenericSequentialFlowInfo info= createSequential(node);
    process(info, node.parameters());
    process(info, node.getBody());
    info.setNoReturn();
}
项目:Eclipse-Postfix-Code-Completion    文件:ExtractMethodAnalyzer.java   
@Override
public boolean visit(LambdaExpression node) {
    Selection selection= getSelection();
    int selectionStart= selection.getOffset();
    int selectionExclusiveEnd= selection.getExclusiveEnd();
    int lambdaStart= node.getStartPosition();
    int lambdaExclusiveEnd= lambdaStart + node.getLength();
    ASTNode body= node.getBody();
    int bodyStart= body.getStartPosition();
    int bodyExclusiveEnd= bodyStart + body.getLength();

    boolean isValidSelection= false;
    if ((body instanceof Block) && (bodyStart < selectionStart && selectionExclusiveEnd <= bodyExclusiveEnd)) {
        // if selection is inside lambda body's block
        isValidSelection= true;
    } else if (body instanceof Expression) {
        try {
            TokenScanner scanner= new TokenScanner(fCUnit);
            int arrowExclusiveEnd= scanner.getTokenEndOffset(ITerminalSymbols.TokenNameARROW, lambdaStart);
            if (selectionStart >= arrowExclusiveEnd) {
                isValidSelection= true;
            }
        } catch (CoreException e) {
            // ignore
        }
    }
    if (selectionStart <= lambdaStart && selectionExclusiveEnd >= lambdaExclusiveEnd) {
        // if selection covers the lambda node
        isValidSelection= true;
    }

    if (!isValidSelection) {
        return false;
    }
    return super.visit(node);
}
项目:Eclipse-Postfix-Code-Completion    文件:ExceptionAnalyzer.java   
@Override
public boolean visit(LambdaExpression node) {
    /*
     * FIXME: Remove this method. It's just a workaround for bug 433426.
     * ExceptionAnalyzer forces clients to on the wrong enclosing node (BodyDeclaration instead of LambdaExpression's body).
     */
    return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTNodes.java   
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;
}
项目:Eclipse-Postfix-Code-Completion    文件:LambdaExpressionsFix.java   
@Override
public boolean visit(LambdaExpression node) {
    ITypeBinding typeBinding= node.resolveTypeBinding();
    if (typeBinding != null && typeBinding.getFunctionalInterfaceMethod() != null) {
        fNodes.add(node);
    }
    return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:LambdaExpressionsFix.java   
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 });
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTResolving.java   
/**
 * The node's enclosing method declaration or <code>null</code> if
 * the node is not inside a method and is not a method declaration itself.
 * 
 * @param node a node
 * @return the enclosing method declaration or <code>null</code>
 */
public static MethodDeclaration findParentMethodDeclaration(ASTNode node) {
    while (node != null) {
        if (node instanceof MethodDeclaration) {
            return (MethodDeclaration) node;
        } else if (node instanceof BodyDeclaration || node instanceof AnonymousClassDeclaration || node instanceof LambdaExpression) {
            return null;
        }
        node= node.getParent();
    }
    return null;
}