Example usage for org.eclipse.jdt.internal.compiler.ast ReferenceExpression isMethodReference

List of usage examples for org.eclipse.jdt.internal.compiler.ast ReferenceExpression isMethodReference

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast ReferenceExpression isMethodReference.

Prototype

public boolean isMethodReference() 

Source Link

Usage

From source file:org.eclipse.che.jdt.internal.core.search.indexing.SourceIndexer.java

License:Open Source License

public void indexResolvedDocument() {
    try {//from w  ww .j a v  a2  s .c  om
        if (DEBUG)
            System.out.println(new String(this.cud.compilationResult.fileName) + ':');
        for (int i = 0, length = this.cud.functionalExpressionsCount; i < length; i++) {
            FunctionalExpression expression = this.cud.functionalExpressions[i];
            if (expression instanceof LambdaExpression) {
                LambdaExpression lambdaExpression = (LambdaExpression) expression;
                if (lambdaExpression.binding != null && lambdaExpression.binding.isValidBinding()) {
                    final char[] superinterface = lambdaExpression.resolvedType.sourceName();
                    if (DEBUG) {
                        System.out.println('\t' + new String(superinterface) + '.'
                                + new String(lambdaExpression.descriptor.selector) + "-> {}"); //$NON-NLS-1$
                    }
                    SourceIndexer.this.addIndexEntry(IIndexConstants.METHOD_DECL,
                            MethodPattern.createIndexKey(lambdaExpression.descriptor.selector,
                                    lambdaExpression.descriptor.parameters.length));

                    addClassDeclaration(0, // most entries are blank, that is fine, since lambda type/method cannot be searched.
                            CharOperation.NO_CHAR, // package name
                            ONE_ZERO, ONE_ZERO_CHAR, // enclosing types.
                            CharOperation.NO_CHAR, // super class
                            new char[][] { superinterface }, CharOperation.NO_CHAR_CHAR, true); // not primary.

                } else {
                    if (DEBUG)
                        System.out.println("\tnull/bad binding in lambda"); //$NON-NLS-1$
                }
            } else {
                ReferenceExpression referenceExpression = (ReferenceExpression) expression;
                if (referenceExpression.isArrayConstructorReference())
                    continue;
                MethodBinding binding = referenceExpression.getMethodBinding();
                if (binding != null && binding.isValidBinding()) {
                    if (DEBUG) {
                        System.out
                                .println('\t' + new String(referenceExpression.resolvedType.sourceName()) + "::" //$NON-NLS-1$
                                        + new String(referenceExpression.descriptor.selector) + " == "
                                        + new String(binding.declaringClass.sourceName()) + '.' + //$NON-NLS-1$
                                        new String(binding.selector));
                    }
                    if (referenceExpression.isMethodReference())
                        SourceIndexer.this.addMethodReference(binding.selector, binding.parameters.length);
                    else
                        SourceIndexer.this.addConstructorReference(binding.declaringClass.sourceName(),
                                binding.parameters.length);
                } else {
                    if (DEBUG)
                        System.out.println("\tnull/bad binding in reference expression"); //$NON-NLS-1$
                }
            }
        }
    } catch (Exception e) {
        if (JobManager.VERBOSE) {
            e.printStackTrace();
        }
    }
}

From source file:org.eclipse.che.jdt.internal.core.search.matching.ConstructorLocator.java

License:Open Source License

public int match(ReferenceExpression node, MatchingNodeSet nodeSet) {
    if (!this.pattern.findReferences || node.isMethodReference())
        return IMPOSSIBLE_MATCH;
    return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
}

From source file:org.summer.sdt.internal.formatter.CodeFormatterVisitor.java

License:Open Source License

/**
 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.ReferenceExpression, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
 *///w w  w .j  a  va 2 s .  c  om
public boolean visit(org.eclipse.jdt.internal.compiler.ast.ReferenceExpression referenceExpression,
        BlockScope blockScope) {
    referenceExpression.lhs.traverse(this, blockScope);
    this.scribe.printNextToken(TerminalTokens.TokenNameCOLON_COLON);

    TypeReference[] typeArguments = referenceExpression.typeArguments;
    if (typeArguments != null) {
        this.scribe.printNextToken(TerminalTokens.TokenNameLESS,
                this.preferences.insert_space_before_opening_angle_bracket_in_type_arguments);
        if (this.preferences.insert_space_after_opening_angle_bracket_in_type_arguments) {
            this.scribe.space();
        }
        int length = typeArguments.length;
        for (int i = 0; i < length - 1; i++) {
            typeArguments[i].traverse(this, blockScope);
            this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA,
                    this.preferences.insert_space_before_comma_in_type_arguments);
            if (this.preferences.insert_space_after_comma_in_type_arguments) {
                this.scribe.space();
            }
        }
        typeArguments[length - 1].traverse(this, blockScope);
        if (isClosingGenericToken()) {
            this.scribe.printNextToken(CLOSING_GENERICS_EXPECTEDTOKENS,
                    this.preferences.insert_space_before_closing_angle_bracket_in_type_arguments);
        }
        if (this.preferences.insert_space_after_closing_angle_bracket_in_type_arguments) {
            this.scribe.space();
        }
    }

    this.scribe.printNextToken(referenceExpression.isMethodReference() ? TerminalTokens.TokenNameIdentifier
            : TerminalTokens.TokenNamenew);
    return false;
}