| 1 | /******************************************************************************* |
|---|---|
| 2 | * Copyright (c) 2013, 2014 IBM Corporation and others. |
| 3 | * |
| 4 | * This program and the accompanying materials |
| 5 | * are made available under the terms of the Eclipse Public License 2.0 |
| 6 | * which accompanies this distribution, and is available at |
| 7 | * https://www.eclipse.org/legal/epl-2.0/ |
| 8 | * |
| 9 | * SPDX-License-Identifier: EPL-2.0 |
| 10 | * |
| 11 | * Contributors: |
| 12 | * IBM Corporation - initial API and implementation |
| 13 | *******************************************************************************/ |
| 14 | package org.eclipse.jdt.core.dom; |
| 15 | |
| 16 | import java.util.List; |
| 17 | |
| 18 | /** |
| 19 | * Abstract base class of all AST node types that represent a method reference |
| 20 | * expression (added in JLS8 API). |
| 21 | * |
| 22 | * <pre> |
| 23 | * MethodReference: |
| 24 | * CreationReference |
| 25 | * ExpressionMethodReference |
| 26 | * SuperMethodReference |
| 27 | * TypeMethodReference |
| 28 | * </pre> |
| 29 | * <p> |
| 30 | * A method reference that is represented by a simple or qualified name, |
| 31 | * followed by <code>::</code>, followed by a simple name can be represented |
| 32 | * as {@link ExpressionMethodReference} or as {@link TypeMethodReference}. |
| 33 | * The ASTParser currently prefers the first form. |
| 34 | * </p> |
| 35 | * |
| 36 | * @see CreationReference |
| 37 | * @see ExpressionMethodReference |
| 38 | * @see SuperMethodReference |
| 39 | * @see TypeMethodReference |
| 40 | * @since 3.10 |
| 41 | */ |
| 42 | @SuppressWarnings({"rawtypes"}) |
| 43 | public abstract class MethodReference extends Expression { |
| 44 | |
| 45 | /** |
| 46 | * The type arguments (element type: {@link Type}). |
| 47 | * Defaults to an empty list (see constructor). |
| 48 | */ |
| 49 | ASTNode.NodeList typeArguments; |
| 50 | |
| 51 | /** |
| 52 | * Creates and returns a structural property descriptor for the "typeArguments" |
| 53 | * property declared on the given concrete node type (element type: {@link Type}). |
| 54 | * |
| 55 | * @return the property descriptor |
| 56 | */ |
| 57 | static final ChildListPropertyDescriptor internalTypeArgumentsFactory(Class nodeClass) { |
| 58 | return new ChildListPropertyDescriptor(nodeClass, "typeArguments", Type.class, NO_CYCLE_RISK); //$NON-NLS-1$ |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Returns the structural property descriptor for the "typeArguments" property |
| 63 | * of this node (element type: {@link Type}). |
| 64 | * |
| 65 | * @return the property descriptor |
| 66 | */ |
| 67 | abstract ChildListPropertyDescriptor internalTypeArgumentsProperty(); |
| 68 | |
| 69 | /** |
| 70 | * Returns the structural property descriptor for the "typeArguments" property |
| 71 | * of this node (element type: {@link Type}). |
| 72 | * |
| 73 | * @return the property descriptor |
| 74 | */ |
| 75 | public final ChildListPropertyDescriptor getTypeArgumentsProperty() { |
| 76 | return internalTypeArgumentsProperty(); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Creates a new AST node for a method reference owned by the given AST. |
| 81 | * <p> |
| 82 | * N.B. This constructor is package-private. |
| 83 | * </p> |
| 84 | * |
| 85 | * @param ast the AST that is to own this node |
| 86 | */ |
| 87 | MethodReference(AST ast) { |
| 88 | super(ast); |
| 89 | this.typeArguments = new ASTNode.NodeList(getTypeArgumentsProperty()); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Returns the live ordered list of type arguments of this method reference. |
| 94 | * |
| 95 | * @return the live list of type arguments |
| 96 | * (element type: {@link Type}) |
| 97 | */ |
| 98 | public List typeArguments() { |
| 99 | return this.typeArguments; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Resolves and returns the binding for the method referenced by this |
| 104 | * method reference expression. |
| 105 | * <p> |
| 106 | * Note that bindings are generally unavailable unless requested when the |
| 107 | * AST is being built. |
| 108 | * </p> |
| 109 | * |
| 110 | * @return the method binding, or <code>null</code> if the binding cannot |
| 111 | * be resolved |
| 112 | */ |
| 113 | public IMethodBinding resolveMethodBinding() { |
| 114 | return this.ast.getBindingResolver().resolveMethod(this); |
| 115 | } |
| 116 | } |
| 117 |
Members