| 1 | /******************************************************************************* |
|---|---|
| 2 | * Copyright (c) 2000, 2020 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 | * Stephan Herrmann - Contribution for |
| 14 | * Bug 429813 - [1.8][dom ast] IMethodBinding#getJavaElement() should return IMethod for lambda |
| 15 | *******************************************************************************/ |
| 16 | |
| 17 | package org.eclipse.jdt.core.dom; |
| 18 | |
| 19 | import org.eclipse.jdt.core.IJavaElement; |
| 20 | import org.eclipse.jdt.core.JavaCore; |
| 21 | import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
| 22 | import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; |
| 23 | import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; |
| 24 | import org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding; |
| 25 | import org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding; |
| 26 | import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; |
| 27 | import org.eclipse.jdt.internal.compiler.lookup.SyntheticMethodBinding; |
| 28 | import org.eclipse.jdt.internal.compiler.lookup.TagBits; |
| 29 | import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; |
| 30 | import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding; |
| 31 | import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; |
| 32 | import org.eclipse.jdt.internal.core.JavaElement; |
| 33 | import org.eclipse.jdt.internal.core.util.Util; |
| 34 | |
| 35 | /** |
| 36 | * Internal implementation of method bindings. |
| 37 | */ |
| 38 | class MethodBinding implements IMethodBinding { |
| 39 | |
| 40 | private static final int VALID_MODIFIERS = Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | |
| 41 | Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL | Modifier.SYNCHRONIZED | Modifier.NATIVE | |
| 42 | Modifier.STRICTFP | Modifier.DEFAULT; |
| 43 | private static final ITypeBinding[] NO_TYPE_BINDINGS = new ITypeBinding[0]; |
| 44 | static final IVariableBinding[] NO_VARIABLE_BINDINGS = new IVariableBinding[0]; |
| 45 | protected org.eclipse.jdt.internal.compiler.lookup.MethodBinding binding; |
| 46 | protected BindingResolver resolver; |
| 47 | private volatile ITypeBinding[] parameterTypes; |
| 48 | private volatile ITypeBinding[] exceptionTypes; |
| 49 | private volatile String name; |
| 50 | private volatile ITypeBinding declaringClass; |
| 51 | private volatile ITypeBinding returnType; |
| 52 | private volatile String key; |
| 53 | private volatile ITypeBinding[] typeParameters; |
| 54 | private volatile ITypeBinding[] typeArguments; |
| 55 | private volatile IAnnotationBinding[] annotations; |
| 56 | private volatile IAnnotationBinding[][] parameterAnnotations; |
| 57 | |
| 58 | MethodBinding(BindingResolver resolver, org.eclipse.jdt.internal.compiler.lookup.MethodBinding binding) { |
| 59 | this.resolver = resolver; |
| 60 | this.binding = binding; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public boolean isAnnotationMember() { |
| 65 | return getDeclaringClass().isAnnotation(); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @see IMethodBinding#isConstructor() |
| 70 | */ |
| 71 | @Override |
| 72 | public boolean isConstructor() { |
| 73 | return this.binding.isConstructor(); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @see IMethodBinding#isCompactConstructor() |
| 78 | */ |
| 79 | @Override |
| 80 | public boolean isCompactConstructor() { |
| 81 | return this.binding.isCompactConstructor(); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @see IMethodBinding#isCanonicalConstructor() |
| 86 | */ |
| 87 | @Override |
| 88 | public boolean isCanonicalConstructor() { |
| 89 | return this.binding.isCanonicalConstructor(); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @see IMethodBinding#isDefaultConstructor() |
| 94 | * @since 3.0 |
| 95 | */ |
| 96 | @Override |
| 97 | public boolean isDefaultConstructor() { |
| 98 | final ReferenceBinding declaringClassBinding = this.binding.declaringClass; |
| 99 | if (declaringClassBinding.isRawType()) { |
| 100 | RawTypeBinding rawTypeBinding = (RawTypeBinding) declaringClassBinding; |
| 101 | if (rawTypeBinding.genericType().isBinaryBinding()) { |
| 102 | return false; |
| 103 | } |
| 104 | return (this.binding.modifiers & ExtraCompilerModifiers.AccIsDefaultConstructor) != 0; |
| 105 | } |
| 106 | if (declaringClassBinding.isBinaryBinding()) { |
| 107 | return false; |
| 108 | } |
| 109 | return (this.binding.modifiers & ExtraCompilerModifiers.AccIsDefaultConstructor) != 0; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @see IBinding#getName() |
| 114 | */ |
| 115 | @Override |
| 116 | public String getName() { |
| 117 | if (this.name == null) { |
| 118 | if (this.binding.isConstructor()) { |
| 119 | this.name = getDeclaringClass().getName(); |
| 120 | } else { |
| 121 | this.name = new String(this.binding.selector); |
| 122 | } |
| 123 | } |
| 124 | return this.name; |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public IAnnotationBinding[] getAnnotations() { |
| 129 | if (this.annotations != null) { |
| 130 | return this.annotations; |
| 131 | } |
| 132 | org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] internalAnnotations = this.binding.getAnnotations(); |
| 133 | return this.annotations = filterTypeAnnotations(internalAnnotations); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * @see IMethodBinding#getDeclaringClass() |
| 138 | */ |
| 139 | @Override |
| 140 | public ITypeBinding getDeclaringClass() { |
| 141 | if (this.declaringClass == null) { |
| 142 | this.declaringClass = this.resolver.getTypeBinding(this.binding.declaringClass); |
| 143 | } |
| 144 | return this.declaringClass; |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public IBinding getDeclaringMember() { |
| 149 | return null; |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public IAnnotationBinding[] getParameterAnnotations(int index) { |
| 154 | if (getParameterTypes() == NO_TYPE_BINDINGS) { |
| 155 | return AnnotationBinding.NoAnnotations; |
| 156 | } |
| 157 | if (this.parameterAnnotations != null) { |
| 158 | return this.parameterAnnotations[index]; |
| 159 | } |
| 160 | org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[][] bindingAnnotations = this.binding.getParameterAnnotations(); |
| 161 | if (bindingAnnotations == null) return AnnotationBinding.NoAnnotations; |
| 162 | |
| 163 | int length = bindingAnnotations.length; |
| 164 | IAnnotationBinding[][] domAnnotations = new IAnnotationBinding[length][]; |
| 165 | for (int i = 0; i < length; i++) { |
| 166 | org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] paramBindingAnnotations = bindingAnnotations[i]; |
| 167 | int pLength = paramBindingAnnotations.length; |
| 168 | domAnnotations[i] = new AnnotationBinding[pLength]; |
| 169 | for (int j=0; j<pLength; j++) { |
| 170 | IAnnotationBinding domAnnotation = this.resolver.getAnnotationInstance(paramBindingAnnotations[j]); |
| 171 | if (domAnnotation == null) { |
| 172 | domAnnotations[i] = AnnotationBinding.NoAnnotations; |
| 173 | break; |
| 174 | } |
| 175 | domAnnotations[i][j] = domAnnotation; |
| 176 | } |
| 177 | } |
| 178 | this.parameterAnnotations = domAnnotations; |
| 179 | |
| 180 | return this.parameterAnnotations[index]; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * @see IMethodBinding#getParameterTypes() |
| 185 | */ |
| 186 | @Override |
| 187 | public ITypeBinding[] getParameterTypes() { |
| 188 | if (this.parameterTypes != null) { |
| 189 | return this.parameterTypes; |
| 190 | } |
| 191 | org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] parameters = this.binding.parameters; |
| 192 | int length = parameters == null ? 0 : parameters.length; |
| 193 | if (length == 0) { |
| 194 | return this.parameterTypes = NO_TYPE_BINDINGS; |
| 195 | } else { |
| 196 | ITypeBinding[] paramTypes = new ITypeBinding[length]; |
| 197 | for (int i = 0; i < length; i++) { |
| 198 | final TypeBinding parameterBinding = parameters[i]; |
| 199 | if (parameterBinding != null) { |
| 200 | ITypeBinding typeBinding = this.resolver.getTypeBinding(parameterBinding); |
| 201 | if (typeBinding == null) { |
| 202 | return this.parameterTypes = NO_TYPE_BINDINGS; |
| 203 | } |
| 204 | paramTypes[i] = typeBinding; |
| 205 | } else { |
| 206 | // log error |
| 207 | StringBuilder message = new StringBuilder("Report method binding where a parameter is null:\n"); //$NON-NLS-1$ |
| 208 | message.append(toString()); |
| 209 | Util.log(new IllegalArgumentException(), message.toString()); |
| 210 | // report no binding since one or more parameter has no binding |
| 211 | return this.parameterTypes = NO_TYPE_BINDINGS; |
| 212 | } |
| 213 | } |
| 214 | return this.parameterTypes = paramTypes; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * @see IMethodBinding#getDeclaredReceiverType() |
| 220 | */ |
| 221 | @Override |
| 222 | public ITypeBinding getDeclaredReceiverType() { |
| 223 | return this.resolver.getTypeBinding(this.binding.receiver); |
| 224 | } |
| 225 | /** |
| 226 | * @see IMethodBinding#getReturnType() |
| 227 | */ |
| 228 | @Override |
| 229 | public ITypeBinding getReturnType() { |
| 230 | if (this.returnType == null) { |
| 231 | this.returnType = this.resolver.getTypeBinding(this.binding.returnType); |
| 232 | } |
| 233 | return this.returnType; |
| 234 | } |
| 235 | |
| 236 | protected IAnnotationBinding[] filterTypeAnnotations(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] internalAnnotations) { |
| 237 | int length = internalAnnotations == null ? 0 : internalAnnotations.length; |
| 238 | if (length != 0) { |
| 239 | IAnnotationBinding[] tempAnnotations = new IAnnotationBinding[length]; |
| 240 | int convertedAnnotationCount = 0; |
| 241 | final boolean isConstructor = this.isConstructor(); |
| 242 | for (int i = 0; i < length; i++) { |
| 243 | org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding internalAnnotation = internalAnnotations[i]; |
| 244 | final ReferenceBinding annotationType = internalAnnotation.getAnnotationType(); |
| 245 | long metaTagBits = annotationType.getAnnotationTagBits(); |
| 246 | |
| 247 | // Exclude all other targets including TYPE_USE, even though TYPE_USE is accepted. |
| 248 | if (isConstructor && (metaTagBits & TagBits.AnnotationForConstructor) == 0 && |
| 249 | ((metaTagBits & TagBits.AnnotationTargetMASK) != 0)) { |
| 250 | continue; |
| 251 | } |
| 252 | |
| 253 | final IAnnotationBinding annotationInstance = this.resolver.getAnnotationInstance(internalAnnotation); |
| 254 | if (annotationInstance == null) { |
| 255 | continue; |
| 256 | } |
| 257 | tempAnnotations[convertedAnnotationCount++] = annotationInstance; |
| 258 | } |
| 259 | if (convertedAnnotationCount == length) return tempAnnotations; |
| 260 | if (convertedAnnotationCount == 0) return AnnotationBinding.NoAnnotations; |
| 261 | |
| 262 | System.arraycopy(tempAnnotations, 0, (tempAnnotations = new IAnnotationBinding[convertedAnnotationCount]), 0, convertedAnnotationCount); |
| 263 | return tempAnnotations; |
| 264 | } |
| 265 | return AnnotationBinding.NoAnnotations; |
| 266 | } |
| 267 | |
| 268 | @Override |
| 269 | public Object getDefaultValue() { |
| 270 | if (isAnnotationMember()) |
| 271 | return MemberValuePairBinding.buildDOMValue(this.binding.getDefaultValue(), this.resolver); |
| 272 | return null; |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * @see IMethodBinding#getExceptionTypes() |
| 277 | */ |
| 278 | @Override |
| 279 | public ITypeBinding[] getExceptionTypes() { |
| 280 | if (this.exceptionTypes != null) { |
| 281 | return this.exceptionTypes; |
| 282 | } |
| 283 | org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] exceptions = this.binding.thrownExceptions; |
| 284 | int length = exceptions == null ? 0 : exceptions.length; |
| 285 | if (length == 0) { |
| 286 | return this.exceptionTypes = NO_TYPE_BINDINGS; |
| 287 | } |
| 288 | ITypeBinding[] exTypes = new ITypeBinding[length]; |
| 289 | for (int i = 0; i < length; i++) { |
| 290 | ITypeBinding typeBinding = this.resolver.getTypeBinding(exceptions[i]); |
| 291 | if (typeBinding == null) { |
| 292 | return this.exceptionTypes = NO_TYPE_BINDINGS; |
| 293 | } |
| 294 | exTypes[i] = typeBinding; |
| 295 | } |
| 296 | return this.exceptionTypes = exTypes; |
| 297 | } |
| 298 | |
| 299 | @Override |
| 300 | public IJavaElement getJavaElement() { |
| 301 | JavaElement element = getUnresolvedJavaElement(); |
| 302 | if (element == null) |
| 303 | return null; |
| 304 | return element.resolved(this.binding); |
| 305 | } |
| 306 | |
| 307 | private JavaElement getUnresolvedJavaElement() { |
| 308 | if (JavaCore.getPlugin() == null) { |
| 309 | return null; |
| 310 | } |
| 311 | if (!(this.resolver instanceof DefaultBindingResolver)) return null; |
| 312 | |
| 313 | DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver; |
| 314 | if (!defaultBindingResolver.fromJavaProject) return null; |
| 315 | return Util.getUnresolvedJavaElement( |
| 316 | this.binding, |
| 317 | defaultBindingResolver.workingCopyOwner, |
| 318 | defaultBindingResolver.getBindingsToNodesMap()); |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * @see IBinding#getKind() |
| 323 | */ |
| 324 | @Override |
| 325 | public int getKind() { |
| 326 | return IBinding.METHOD; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * @see IBinding#getModifiers() |
| 331 | */ |
| 332 | @Override |
| 333 | public int getModifiers() { |
| 334 | return this.binding.getAccessFlags() & VALID_MODIFIERS; |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * @see IBinding#isDeprecated() |
| 339 | */ |
| 340 | @Override |
| 341 | public boolean isDeprecated() { |
| 342 | return this.binding.isDeprecated(); |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * @see IBinding#isRecovered() |
| 347 | */ |
| 348 | @Override |
| 349 | public boolean isRecovered() { |
| 350 | return false; |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * @see IBinding#isSynthetic() |
| 355 | */ |
| 356 | @Override |
| 357 | public boolean isSynthetic() { |
| 358 | return this.binding.isSynthetic(); |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * @see org.eclipse.jdt.core.dom.IMethodBinding#isVarargs() |
| 363 | * @since 3.1 |
| 364 | */ |
| 365 | @Override |
| 366 | public boolean isVarargs() { |
| 367 | return this.binding.isVarargs(); |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * @see IBinding#getKey() |
| 372 | */ |
| 373 | @Override |
| 374 | public String getKey() { |
| 375 | if (this.key == null) { |
| 376 | this.key = new String(this.binding.computeUniqueKey()); |
| 377 | } |
| 378 | return this.key; |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * @see IBinding#isEqualTo(IBinding) |
| 383 | * @since 3.1 |
| 384 | */ |
| 385 | @Override |
| 386 | public boolean isEqualTo(IBinding other) { |
| 387 | if (other == this) { |
| 388 | // identical binding - equal (key or no key) |
| 389 | return true; |
| 390 | } |
| 391 | if (other == null) { |
| 392 | // other binding missing |
| 393 | return false; |
| 394 | } |
| 395 | if (!(other instanceof MethodBinding)) { |
| 396 | return false; |
| 397 | } |
| 398 | org.eclipse.jdt.internal.compiler.lookup.MethodBinding otherBinding = ((MethodBinding) other).binding; |
| 399 | return BindingComparator.isEqual(this.binding, otherBinding); |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * @see org.eclipse.jdt.core.dom.IMethodBinding#getTypeParameters() |
| 404 | */ |
| 405 | @Override |
| 406 | public ITypeBinding[] getTypeParameters() { |
| 407 | if (this.typeParameters != null) { |
| 408 | return this.typeParameters; |
| 409 | } |
| 410 | TypeVariableBinding[] typeVariableBindings = this.binding.typeVariables(); |
| 411 | int typeVariableBindingsLength = typeVariableBindings == null ? 0 : typeVariableBindings.length; |
| 412 | if (typeVariableBindingsLength == 0) { |
| 413 | return this.typeParameters = NO_TYPE_BINDINGS; |
| 414 | } |
| 415 | ITypeBinding[] tParameters = new ITypeBinding[typeVariableBindingsLength]; |
| 416 | for (int i = 0; i < typeVariableBindingsLength; i++) { |
| 417 | ITypeBinding typeBinding = this.resolver.getTypeBinding(typeVariableBindings[i]); |
| 418 | if (typeBinding == null) { |
| 419 | return this.typeParameters = NO_TYPE_BINDINGS; |
| 420 | } |
| 421 | tParameters[i] = typeBinding; |
| 422 | } |
| 423 | return this.typeParameters = tParameters; |
| 424 | } |
| 425 | |
| 426 | /** |
| 427 | * @see org.eclipse.jdt.core.dom.IMethodBinding#isGenericMethod() |
| 428 | * @since 3.1 |
| 429 | */ |
| 430 | @Override |
| 431 | public boolean isGenericMethod() { |
| 432 | // equivalent to return getTypeParameters().length > 0; |
| 433 | if (this.typeParameters != null) { |
| 434 | return this.typeParameters.length > 0; |
| 435 | } |
| 436 | TypeVariableBinding[] typeVariableBindings = this.binding.typeVariables(); |
| 437 | return (typeVariableBindings != null && typeVariableBindings.length > 0); |
| 438 | } |
| 439 | |
| 440 | /** |
| 441 | * @see org.eclipse.jdt.core.dom.IMethodBinding#getTypeArguments() |
| 442 | */ |
| 443 | @Override |
| 444 | public ITypeBinding[] getTypeArguments() { |
| 445 | if (this.typeArguments != null) { |
| 446 | return this.typeArguments; |
| 447 | } |
| 448 | |
| 449 | if (this.binding instanceof ParameterizedGenericMethodBinding) { |
| 450 | ParameterizedGenericMethodBinding genericMethodBinding = (ParameterizedGenericMethodBinding) this.binding; |
| 451 | org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] typeArgumentsBindings = genericMethodBinding.typeArguments; |
| 452 | int typeArgumentsLength = typeArgumentsBindings == null ? 0 : typeArgumentsBindings.length; |
| 453 | if (typeArgumentsLength != 0) { |
| 454 | ITypeBinding[] tArguments = new ITypeBinding[typeArgumentsLength]; |
| 455 | for (int i = 0; i < typeArgumentsLength; i++) { |
| 456 | ITypeBinding typeBinding = this.resolver.getTypeBinding(typeArgumentsBindings[i]); |
| 457 | if (typeBinding == null) { |
| 458 | return this.typeArguments = NO_TYPE_BINDINGS; |
| 459 | } |
| 460 | tArguments[i] = typeBinding; |
| 461 | } |
| 462 | return this.typeArguments = tArguments; |
| 463 | } |
| 464 | } |
| 465 | return this.typeArguments = NO_TYPE_BINDINGS; |
| 466 | } |
| 467 | |
| 468 | /** |
| 469 | * @see org.eclipse.jdt.core.dom.IMethodBinding#isParameterizedMethod() |
| 470 | */ |
| 471 | @Override |
| 472 | public boolean isParameterizedMethod() { |
| 473 | return (this.binding instanceof ParameterizedGenericMethodBinding) |
| 474 | && !((ParameterizedGenericMethodBinding) this.binding).isRaw; |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * @see org.eclipse.jdt.core.dom.IMethodBinding#isRawMethod() |
| 479 | */ |
| 480 | @Override |
| 481 | public boolean isRawMethod() { |
| 482 | return (this.binding instanceof ParameterizedGenericMethodBinding) |
| 483 | && ((ParameterizedGenericMethodBinding) this.binding).isRaw; |
| 484 | } |
| 485 | |
| 486 | @Override |
| 487 | public boolean isSubsignature(IMethodBinding otherMethod) { |
| 488 | try { |
| 489 | LookupEnvironment lookupEnvironment = this.resolver.lookupEnvironment(); |
| 490 | return lookupEnvironment != null |
| 491 | && lookupEnvironment.methodVerifier().isMethodSubsignature(this.binding, ((MethodBinding) otherMethod).binding); |
| 492 | } catch (AbortCompilation e) { |
| 493 | // don't surface internal exception to clients |
| 494 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=143013 |
| 495 | return false; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | /** |
| 500 | * @see org.eclipse.jdt.core.dom.IMethodBinding#getMethodDeclaration() |
| 501 | */ |
| 502 | @Override |
| 503 | public IMethodBinding getMethodDeclaration() { |
| 504 | return this.resolver.getMethodBinding(this.binding.original()); |
| 505 | } |
| 506 | |
| 507 | /** |
| 508 | * @see IMethodBinding#overrides(IMethodBinding) |
| 509 | */ |
| 510 | @Override |
| 511 | public boolean overrides(IMethodBinding otherMethod) { |
| 512 | LookupEnvironment lookupEnvironment = this.resolver.lookupEnvironment(); |
| 513 | return lookupEnvironment != null |
| 514 | && lookupEnvironment.methodVerifier().doesMethodOverride(this.binding, ((MethodBinding) otherMethod).binding); |
| 515 | } |
| 516 | |
| 517 | /** |
| 518 | * For debugging purpose only. |
| 519 | * @see java.lang.Object#toString() |
| 520 | */ |
| 521 | @Override |
| 522 | public String toString() { |
| 523 | return this.binding.toString(); |
| 524 | } |
| 525 | |
| 526 | /* |
| 527 | * Method binding representing a lambda expression. |
| 528 | * Most properties are read from the SAM descriptor, |
| 529 | * but key, parameter types, and annotations are taken from the lambda implementation. |
| 530 | * Additionally we store the declaring member (see #getDeclaringMember()). |
| 531 | */ |
| 532 | static class LambdaMethod extends MethodBinding { |
| 533 | |
| 534 | private MethodBinding implementation; |
| 535 | private IBinding declaringMember; |
| 536 | private IVariableBinding[] syntheticOuterLocalVariables; |
| 537 | |
| 538 | public LambdaMethod(DefaultBindingResolver resolver, |
| 539 | org.eclipse.jdt.internal.compiler.lookup.MethodBinding lambdaDescriptor, |
| 540 | org.eclipse.jdt.internal.compiler.lookup.MethodBinding implementation, |
| 541 | IBinding declaringMember) |
| 542 | { |
| 543 | super(resolver, lambdaDescriptor); |
| 544 | this.implementation = new MethodBinding(resolver, implementation); |
| 545 | this.declaringMember = declaringMember; |
| 546 | } |
| 547 | |
| 548 | /** |
| 549 | * @see IBinding#getModifiers() |
| 550 | */ |
| 551 | @Override |
| 552 | public int getModifiers() { |
| 553 | return super.getModifiers() & ~ClassFileConstants.AccAbstract; |
| 554 | } |
| 555 | |
| 556 | /** |
| 557 | * @see IBinding#getKey() |
| 558 | */ |
| 559 | @Override |
| 560 | public String getKey() { |
| 561 | return this.implementation.getKey(); |
| 562 | } |
| 563 | |
| 564 | @Override |
| 565 | public ITypeBinding[] getParameterTypes() { |
| 566 | return this.implementation.getParameterTypes(); |
| 567 | } |
| 568 | |
| 569 | @Override |
| 570 | public IAnnotationBinding[] getParameterAnnotations(int paramIndex) { |
| 571 | return this.implementation.getParameterAnnotations(paramIndex); |
| 572 | } |
| 573 | |
| 574 | @Override |
| 575 | public IAnnotationBinding[] getAnnotations() { |
| 576 | return this.implementation.getAnnotations(); |
| 577 | } |
| 578 | |
| 579 | @Override |
| 580 | public IBinding getDeclaringMember() { |
| 581 | return this.declaringMember; |
| 582 | } |
| 583 | |
| 584 | @Override |
| 585 | public IMethodBinding getMethodDeclaration() { |
| 586 | return this.resolver.getMethodBinding(this.binding); |
| 587 | } |
| 588 | |
| 589 | @Override |
| 590 | public String toString() { |
| 591 | return super.toString().replace("public abstract ", "public "); //$NON-NLS-1$//$NON-NLS-2$ |
| 592 | } |
| 593 | |
| 594 | @Override |
| 595 | public IVariableBinding[] getSyntheticOuterLocals() { |
| 596 | if (this.syntheticOuterLocalVariables != null) { |
| 597 | return this.syntheticOuterLocalVariables; |
| 598 | } |
| 599 | return NO_VARIABLE_BINDINGS; |
| 600 | } |
| 601 | |
| 602 | public void setSyntheticOuterLocals(IVariableBinding[] syntheticOuterLocalVariables) { |
| 603 | this.syntheticOuterLocalVariables = syntheticOuterLocalVariables; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | @Override |
| 608 | public IVariableBinding[] getSyntheticOuterLocals() { |
| 609 | return NO_VARIABLE_BINDINGS; |
| 610 | } |
| 611 | |
| 612 | @Override |
| 613 | public boolean isSyntheticRecordMethod() { |
| 614 | return ((getDeclaringClass().isRecord()) && |
| 615 | (this.binding instanceof SyntheticMethodBinding)); |
| 616 | } |
| 617 | } |
| 618 |
Members