From 823faf719ab3456b43490e887d59921c0a4b11b5 Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Mon, 14 Jan 2019 23:30:04 -0600 Subject: [PATCH] Retain original method linkage for generated methods from default params GroovyCompUnitDecl maps MethodNode -> AbstractMethodDeclaration MethodScope.createMethod maps AbstractMethodDeclaration -> MethodBinding JDTClassNode.methodBindingToMethodNode maps MethodBinding -> MethodNode --- .../org/codehaus/groovy/ast/ClassNode.java | 7 ++-- .../org/codehaus/groovy/ast/ClassNode.java | 7 ++-- .../org/codehaus/groovy/ast/ClassNode.java | 7 ++-- .../compiler/ast/GroovyClassScope.java | 4 +-- .../internal/compiler/ast/JDTClassNode.java | 18 +++++++++- .../requestor/CodeSelectRequestor.java | 7 ++-- .../lookup/DelegateMethodBinding.java | 33 +++++++++++++++++++ .../internal/compiler/lookup/MethodScope.java | 28 ++++++++++++++-- .../lookup/DelegateMethodBinding.java | 33 +++++++++++++++++++ .../internal/compiler/lookup/MethodScope.java | 28 ++++++++++++++-- .../lookup/DelegateMethodBinding.java | 33 +++++++++++++++++++ .../internal/compiler/lookup/MethodScope.java | 28 ++++++++++++++-- .../lookup/DelegateMethodBinding.java | 33 +++++++++++++++++++ .../internal/compiler/lookup/MethodScope.java | 28 ++++++++++++++-- .../lookup/DelegateMethodBinding.java | 33 +++++++++++++++++++ .../internal/compiler/lookup/MethodScope.java | 28 ++++++++++++++-- 16 files changed, 329 insertions(+), 26 deletions(-) create mode 100644 jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java create mode 100644 jdt-patch/e411/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java create mode 100644 jdt-patch/e47/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java create mode 100644 jdt-patch/e48/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java create mode 100644 jdt-patch/e49/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java diff --git a/base/org.codehaus.groovy24/src/org/codehaus/groovy/ast/ClassNode.java b/base/org.codehaus.groovy24/src/org/codehaus/groovy/ast/ClassNode.java index bba6df496c..e8bc9887e2 100644 --- a/base/org.codehaus.groovy24/src/org/codehaus/groovy/ast/ClassNode.java +++ b/base/org.codehaus.groovy24/src/org/codehaus/groovy/ast/ClassNode.java @@ -105,8 +105,8 @@ * @see org.codehaus.groovy.ast.ClassHelper */ public class ClassNode extends AnnotatedNode implements Opcodes { - // GRECLIPSE private->package - static class MapOfLists { + // GRECLIPSE private->protected + protected static class MapOfLists { // GRECLIPSE private->protected protected Map> map; @@ -147,7 +147,8 @@ public void remove(Object key, MethodNode value) { private boolean syntheticPublic; private ClassNode[] interfaces; private MixinNode[] mixins; - private List constructors; + // GRECLIPSE private->protected + protected List constructors; private List objectInitializers; // GRECLIPSE private->protected protected MapOfLists methods; diff --git a/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/ClassNode.java b/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/ClassNode.java index 52202d2bc3..8e2c765e1b 100644 --- a/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/ClassNode.java +++ b/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/ClassNode.java @@ -104,8 +104,8 @@ * @see org.codehaus.groovy.ast.ClassHelper */ public class ClassNode extends AnnotatedNode implements Opcodes { - // GRECLIPSE private->package - static class MapOfLists { + // GRECLIPSE private->protected + protected static class MapOfLists { // GRECLIPSE private->protected protected Map> map; @@ -146,7 +146,8 @@ public void remove(Object key, MethodNode value) { private boolean syntheticPublic; private ClassNode[] interfaces; private MixinNode[] mixins; - private List constructors; + // GRECLIPSE private->protected + protected List constructors; private List objectInitializers; // GRECLIPSE private->protected protected MapOfLists methods; diff --git a/base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/ClassNode.java b/base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/ClassNode.java index 0dbffe512f..c026ade900 100644 --- a/base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/ClassNode.java +++ b/base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/ClassNode.java @@ -104,8 +104,8 @@ * @see org.codehaus.groovy.ast.ClassHelper */ public class ClassNode extends AnnotatedNode implements Opcodes { - // GRECLIPSE private->package - static class MapOfLists { + // GRECLIPSE private->protected + protected static class MapOfLists { // GRECLIPSE private->protected protected Map> map; @@ -146,7 +146,8 @@ public void remove(Object key, MethodNode value) { private boolean syntheticPublic; private ClassNode[] interfaces; private MixinNode[] mixins; - private List constructors; + // GRECLIPSE private->protected + protected List constructors; private List objectInitializers; // GRECLIPSE private->protected protected MapOfLists methods; diff --git a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/GroovyClassScope.java b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/GroovyClassScope.java index 929a2d8826..efba05e7ea 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/GroovyClassScope.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/GroovyClassScope.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2018 the original author or authors. + * Copyright 2009-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -83,7 +83,7 @@ protected MethodBinding[] augmentMethodBindings(MethodBinding[] methodBindings) return methodBindings; } - ReferenceBinding[] superInterfaces = (typeBinding.superInterfaces != null ? typeBinding.superInterfaces : Binding.NO_SUPERINTERFACES); + ReferenceBinding[] superInterfaces = Optional.ofNullable(typeBinding.superInterfaces).orElse(Binding.NO_SUPERINTERFACES); boolean implementsGroovyLangObject = false; for (ReferenceBinding face : superInterfaces) { diff --git a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTClassNode.java b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTClassNode.java index e0806eb431..ea69e62c0a 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTClassNode.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTClassNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2018 the original author or authors. + * Copyright 2009-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,6 +66,7 @@ import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.ClassScope; import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; +import org.eclipse.jdt.internal.compiler.lookup.DelegateMethodBinding; import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; import org.eclipse.jdt.internal.compiler.lookup.LazilyResolvedMethodBinding; import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; @@ -328,6 +329,7 @@ private MethodNode methodBindingToMethodNode(MethodBinding methodBinding) { MethodNode methodNode = new JDTMethodNode(methodBinding, resolver, String.valueOf(methodBinding.selector), modifiers, returnType, parameters, exceptions, null); methodNode.setGenericsTypes(new JDTClassNodeBuilder(resolver).configureTypeVariables(methodBinding.typeVariables())); methodNode.setSynthetic(methodBinding instanceof LazilyResolvedMethodBinding); // see GroovyClassScope + populateOriginal(methodBinding, methodNode); return methodNode; } catch (AbortCompilation e) { throw e; @@ -353,6 +355,8 @@ private ConstructorNode constructorBindingToConstructorNode(MethodBinding method ctorNode.addAnnotation(new JDTAnnotationNode(annotationBinding, resolver)); } ctorNode.setGenericsTypes(new JDTClassNodeBuilder(resolver).configureTypeVariables(methodBinding.typeVariables())); + ctorNode.putNodeMetaData("JdtBinding", methodBinding); + populateOriginal(methodBinding, ctorNode); return ctorNode; } @@ -450,6 +454,18 @@ private Parameter[] makeParameters(TypeBinding[] parameterTypes, char[][] parame return parameters; } + private void populateOriginal(MethodBinding methodBinding, MethodNode methodNode) { + if (methodBinding instanceof DelegateMethodBinding) { + MethodBinding target = ((DelegateMethodBinding) methodBinding).delegateMethod.binding; + for (MethodNode candidate : methodNode instanceof ConstructorNode ? constructors : methods.getNotNull(methodNode.getName())) { + Binding binding = methodNode instanceof JDTNode ? ((JDTNode) candidate).getJdtBinding() : candidate.getNodeMetaData("JdtBinding"); + if (binding == target) { + methodNode.setOriginal(candidate); + } + } + } + } + //-------------------------------------------------------------------------- @Override diff --git a/ide/org.codehaus.groovy.eclipse.codebrowsing/src/org/codehaus/groovy/eclipse/codebrowsing/requestor/CodeSelectRequestor.java b/ide/org.codehaus.groovy.eclipse.codebrowsing/src/org/codehaus/groovy/eclipse/codebrowsing/requestor/CodeSelectRequestor.java index 709cad959c..f9fa1382d6 100644 --- a/ide/org.codehaus.groovy.eclipse.codebrowsing/src/org/codehaus/groovy/eclipse/codebrowsing/requestor/CodeSelectRequestor.java +++ b/ide/org.codehaus.groovy.eclipse.codebrowsing/src/org/codehaus/groovy/eclipse/codebrowsing/requestor/CodeSelectRequestor.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2018 the original author or authors. + * Copyright 2009-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -655,14 +655,13 @@ private void appendUniqueKeyForMethod(StringBuilder sb, MethodNode node, ClassNo Parameter[] parameters = node.getOriginal().getParameters(); if (parameters != null) { for (Parameter param : parameters) { - ClassNode paramType = param.getType(); - appendUniqueKeyForClass(sb, paramType, resolvedDeclaringType); + appendUniqueKeyForClass(sb, param.getType(), resolvedDeclaringType); } } sb.append(Signature.C_PARAM_END); // return type - appendUniqueKeyForClass(sb, node.getOriginal().getReturnType(), resolvedDeclaringType); + appendUniqueKeyForClass(sb, node.getReturnType(), resolvedDeclaringType); // generic type resolution if (generics.length > 0) { diff --git a/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java b/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java new file mode 100644 index 0000000000..650954c0cb --- /dev/null +++ b/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java @@ -0,0 +1,33 @@ +/* + * Copyright 2009-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.eclipse.jdt.internal.compiler.lookup; + +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; + +public class DelegateMethodBinding extends MethodBinding { + + public final AbstractMethodDeclaration delegateMethod; + + public DelegateMethodBinding(int modifiers, ReferenceBinding declaringClass, AbstractMethodDeclaration delegateMethod) { + super(modifiers, null, null, declaringClass); + this.delegateMethod = delegateMethod; + } + + public DelegateMethodBinding(int modifiers, char[] selector, ReferenceBinding declaringClass, AbstractMethodDeclaration delegateMethod) { + super(modifiers, selector, null, null, null, declaringClass); + this.delegateMethod = delegateMethod; + } +} diff --git a/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java b/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java index 8f727d1d49..0260fbb962 100644 --- a/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java +++ b/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java @@ -375,6 +375,18 @@ MethodBinding createMethod(AbstractMethodDeclaration method) { if (method.isConstructor()) { if (method.isDefaultConstructor()) modifiers |= ExtraCompilerModifiers.AccIsDefaultConstructor; + // GROOVY add + if (method.sourceStart > 0 && method.declarationSourceStart <= 0) { + TypeDeclaration type = enclosingClassScope().referenceContext; + for (AbstractMethodDeclaration m : type.methods) { + if (m != method && m.sourceStart == method.sourceStart) { + method.binding = new DelegateMethodBinding(modifiers, declaringClass, m); + break; + } + } + } + if (method.binding == null) + // GROOVY end method.binding = new MethodBinding(modifiers, null, null, declaringClass); checkAndSetModifiersForConstructor(method.binding); } else { @@ -387,6 +399,18 @@ MethodBinding createMethod(AbstractMethodDeclaration method) { modifiers |= ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract; } } + // GROOVY add + if (method.sourceStart > 0 && method.declarationSourceStart <= 0) { + TypeDeclaration type = enclosingClassScope().referenceContext; + for (AbstractMethodDeclaration m : type.methods) { + if (m != method && m.sourceStart == method.sourceStart) { + method.binding = new DelegateMethodBinding(modifiers, method.selector, declaringClass, m); + break; + } + } + } + if (method.binding == null) + // GROOVY end method.binding = new MethodBinding(modifiers, method.selector, null, null, null, declaringClass); checkAndSetModifiersForMethod(method.binding); @@ -431,8 +455,8 @@ MethodBinding createMethod(AbstractMethodDeclaration method) { TypeParameter[] typeParameters = method.typeParameters(); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, If they exist at all, process type parameters irrespective of source level. - if (typeParameters == null || typeParameters.length == 0) { - method.binding.typeVariables = Binding.NO_TYPE_VARIABLES; + if (typeParameters == null || typeParameters.length == 0) { + method.binding.typeVariables = Binding.NO_TYPE_VARIABLES; } else { method.binding.typeVariables = createTypeVariables(typeParameters, method.binding); method.binding.modifiers |= ExtraCompilerModifiers.AccGenericSignature; diff --git a/jdt-patch/e411/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java b/jdt-patch/e411/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java new file mode 100644 index 0000000000..650954c0cb --- /dev/null +++ b/jdt-patch/e411/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java @@ -0,0 +1,33 @@ +/* + * Copyright 2009-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.eclipse.jdt.internal.compiler.lookup; + +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; + +public class DelegateMethodBinding extends MethodBinding { + + public final AbstractMethodDeclaration delegateMethod; + + public DelegateMethodBinding(int modifiers, ReferenceBinding declaringClass, AbstractMethodDeclaration delegateMethod) { + super(modifiers, null, null, declaringClass); + this.delegateMethod = delegateMethod; + } + + public DelegateMethodBinding(int modifiers, char[] selector, ReferenceBinding declaringClass, AbstractMethodDeclaration delegateMethod) { + super(modifiers, selector, null, null, null, declaringClass); + this.delegateMethod = delegateMethod; + } +} diff --git a/jdt-patch/e411/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java b/jdt-patch/e411/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java index 8f727d1d49..0260fbb962 100644 --- a/jdt-patch/e411/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java +++ b/jdt-patch/e411/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java @@ -375,6 +375,18 @@ MethodBinding createMethod(AbstractMethodDeclaration method) { if (method.isConstructor()) { if (method.isDefaultConstructor()) modifiers |= ExtraCompilerModifiers.AccIsDefaultConstructor; + // GROOVY add + if (method.sourceStart > 0 && method.declarationSourceStart <= 0) { + TypeDeclaration type = enclosingClassScope().referenceContext; + for (AbstractMethodDeclaration m : type.methods) { + if (m != method && m.sourceStart == method.sourceStart) { + method.binding = new DelegateMethodBinding(modifiers, declaringClass, m); + break; + } + } + } + if (method.binding == null) + // GROOVY end method.binding = new MethodBinding(modifiers, null, null, declaringClass); checkAndSetModifiersForConstructor(method.binding); } else { @@ -387,6 +399,18 @@ MethodBinding createMethod(AbstractMethodDeclaration method) { modifiers |= ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract; } } + // GROOVY add + if (method.sourceStart > 0 && method.declarationSourceStart <= 0) { + TypeDeclaration type = enclosingClassScope().referenceContext; + for (AbstractMethodDeclaration m : type.methods) { + if (m != method && m.sourceStart == method.sourceStart) { + method.binding = new DelegateMethodBinding(modifiers, method.selector, declaringClass, m); + break; + } + } + } + if (method.binding == null) + // GROOVY end method.binding = new MethodBinding(modifiers, method.selector, null, null, null, declaringClass); checkAndSetModifiersForMethod(method.binding); @@ -431,8 +455,8 @@ MethodBinding createMethod(AbstractMethodDeclaration method) { TypeParameter[] typeParameters = method.typeParameters(); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, If they exist at all, process type parameters irrespective of source level. - if (typeParameters == null || typeParameters.length == 0) { - method.binding.typeVariables = Binding.NO_TYPE_VARIABLES; + if (typeParameters == null || typeParameters.length == 0) { + method.binding.typeVariables = Binding.NO_TYPE_VARIABLES; } else { method.binding.typeVariables = createTypeVariables(typeParameters, method.binding); method.binding.modifiers |= ExtraCompilerModifiers.AccGenericSignature; diff --git a/jdt-patch/e47/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java b/jdt-patch/e47/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java new file mode 100644 index 0000000000..650954c0cb --- /dev/null +++ b/jdt-patch/e47/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java @@ -0,0 +1,33 @@ +/* + * Copyright 2009-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.eclipse.jdt.internal.compiler.lookup; + +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; + +public class DelegateMethodBinding extends MethodBinding { + + public final AbstractMethodDeclaration delegateMethod; + + public DelegateMethodBinding(int modifiers, ReferenceBinding declaringClass, AbstractMethodDeclaration delegateMethod) { + super(modifiers, null, null, declaringClass); + this.delegateMethod = delegateMethod; + } + + public DelegateMethodBinding(int modifiers, char[] selector, ReferenceBinding declaringClass, AbstractMethodDeclaration delegateMethod) { + super(modifiers, selector, null, null, null, declaringClass); + this.delegateMethod = delegateMethod; + } +} diff --git a/jdt-patch/e47/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java b/jdt-patch/e47/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java index b1667e8516..4b81998b46 100644 --- a/jdt-patch/e47/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java +++ b/jdt-patch/e47/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java @@ -371,6 +371,18 @@ MethodBinding createMethod(AbstractMethodDeclaration method) { if (method.isConstructor()) { if (method.isDefaultConstructor()) modifiers |= ExtraCompilerModifiers.AccIsDefaultConstructor; + // GROOVY add + if (method.sourceStart > 0 && method.declarationSourceStart <= 0) { + TypeDeclaration type = enclosingClassScope().referenceContext; + for (AbstractMethodDeclaration m : type.methods) { + if (m != method && m.sourceStart == method.sourceStart) { + method.binding = new DelegateMethodBinding(modifiers, declaringClass, m); + break; + } + } + } + if (method.binding == null) + // GROOVY end method.binding = new MethodBinding(modifiers, null, null, declaringClass); checkAndSetModifiersForConstructor(method.binding); } else { @@ -383,6 +395,18 @@ MethodBinding createMethod(AbstractMethodDeclaration method) { modifiers |= ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract; } } + // GROOVY add + if (method.sourceStart > 0 && method.declarationSourceStart <= 0) { + TypeDeclaration type = enclosingClassScope().referenceContext; + for (AbstractMethodDeclaration m : type.methods) { + if (m != method && m.sourceStart == method.sourceStart) { + method.binding = new DelegateMethodBinding(modifiers, method.selector, declaringClass, m); + break; + } + } + } + if (method.binding == null) + // GROOVY end method.binding = new MethodBinding(modifiers, method.selector, null, null, null, declaringClass); checkAndSetModifiersForMethod(method.binding); @@ -427,8 +451,8 @@ MethodBinding createMethod(AbstractMethodDeclaration method) { TypeParameter[] typeParameters = method.typeParameters(); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, If they exist at all, process type parameters irrespective of source level. - if (typeParameters == null || typeParameters.length == 0) { - method.binding.typeVariables = Binding.NO_TYPE_VARIABLES; + if (typeParameters == null || typeParameters.length == 0) { + method.binding.typeVariables = Binding.NO_TYPE_VARIABLES; } else { method.binding.typeVariables = createTypeVariables(typeParameters, method.binding); method.binding.modifiers |= ExtraCompilerModifiers.AccGenericSignature; diff --git a/jdt-patch/e48/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java b/jdt-patch/e48/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java new file mode 100644 index 0000000000..650954c0cb --- /dev/null +++ b/jdt-patch/e48/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java @@ -0,0 +1,33 @@ +/* + * Copyright 2009-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.eclipse.jdt.internal.compiler.lookup; + +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; + +public class DelegateMethodBinding extends MethodBinding { + + public final AbstractMethodDeclaration delegateMethod; + + public DelegateMethodBinding(int modifiers, ReferenceBinding declaringClass, AbstractMethodDeclaration delegateMethod) { + super(modifiers, null, null, declaringClass); + this.delegateMethod = delegateMethod; + } + + public DelegateMethodBinding(int modifiers, char[] selector, ReferenceBinding declaringClass, AbstractMethodDeclaration delegateMethod) { + super(modifiers, selector, null, null, null, declaringClass); + this.delegateMethod = delegateMethod; + } +} diff --git a/jdt-patch/e48/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java b/jdt-patch/e48/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java index a488cb151b..a1ffdaba33 100644 --- a/jdt-patch/e48/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java +++ b/jdt-patch/e48/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java @@ -372,6 +372,18 @@ MethodBinding createMethod(AbstractMethodDeclaration method) { if (method.isConstructor()) { if (method.isDefaultConstructor()) modifiers |= ExtraCompilerModifiers.AccIsDefaultConstructor; + // GROOVY add + if (method.sourceStart > 0 && method.declarationSourceStart <= 0) { + TypeDeclaration type = enclosingClassScope().referenceContext; + for (AbstractMethodDeclaration m : type.methods) { + if (m != method && m.sourceStart == method.sourceStart) { + method.binding = new DelegateMethodBinding(modifiers, declaringClass, m); + break; + } + } + } + if (method.binding == null) + // GROOVY end method.binding = new MethodBinding(modifiers, null, null, declaringClass); checkAndSetModifiersForConstructor(method.binding); } else { @@ -384,6 +396,18 @@ MethodBinding createMethod(AbstractMethodDeclaration method) { modifiers |= ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract; } } + // GROOVY add + if (method.sourceStart > 0 && method.declarationSourceStart <= 0) { + TypeDeclaration type = enclosingClassScope().referenceContext; + for (AbstractMethodDeclaration m : type.methods) { + if (m != method && m.sourceStart == method.sourceStart) { + method.binding = new DelegateMethodBinding(modifiers, method.selector, declaringClass, m); + break; + } + } + } + if (method.binding == null) + // GROOVY end method.binding = new MethodBinding(modifiers, method.selector, null, null, null, declaringClass); checkAndSetModifiersForMethod(method.binding); @@ -428,8 +452,8 @@ MethodBinding createMethod(AbstractMethodDeclaration method) { TypeParameter[] typeParameters = method.typeParameters(); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, If they exist at all, process type parameters irrespective of source level. - if (typeParameters == null || typeParameters.length == 0) { - method.binding.typeVariables = Binding.NO_TYPE_VARIABLES; + if (typeParameters == null || typeParameters.length == 0) { + method.binding.typeVariables = Binding.NO_TYPE_VARIABLES; } else { method.binding.typeVariables = createTypeVariables(typeParameters, method.binding); method.binding.modifiers |= ExtraCompilerModifiers.AccGenericSignature; diff --git a/jdt-patch/e49/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java b/jdt-patch/e49/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java new file mode 100644 index 0000000000..650954c0cb --- /dev/null +++ b/jdt-patch/e49/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/DelegateMethodBinding.java @@ -0,0 +1,33 @@ +/* + * Copyright 2009-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.eclipse.jdt.internal.compiler.lookup; + +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; + +public class DelegateMethodBinding extends MethodBinding { + + public final AbstractMethodDeclaration delegateMethod; + + public DelegateMethodBinding(int modifiers, ReferenceBinding declaringClass, AbstractMethodDeclaration delegateMethod) { + super(modifiers, null, null, declaringClass); + this.delegateMethod = delegateMethod; + } + + public DelegateMethodBinding(int modifiers, char[] selector, ReferenceBinding declaringClass, AbstractMethodDeclaration delegateMethod) { + super(modifiers, selector, null, null, null, declaringClass); + this.delegateMethod = delegateMethod; + } +} diff --git a/jdt-patch/e49/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java b/jdt-patch/e49/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java index 8f727d1d49..0260fbb962 100644 --- a/jdt-patch/e49/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java +++ b/jdt-patch/e49/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java @@ -375,6 +375,18 @@ MethodBinding createMethod(AbstractMethodDeclaration method) { if (method.isConstructor()) { if (method.isDefaultConstructor()) modifiers |= ExtraCompilerModifiers.AccIsDefaultConstructor; + // GROOVY add + if (method.sourceStart > 0 && method.declarationSourceStart <= 0) { + TypeDeclaration type = enclosingClassScope().referenceContext; + for (AbstractMethodDeclaration m : type.methods) { + if (m != method && m.sourceStart == method.sourceStart) { + method.binding = new DelegateMethodBinding(modifiers, declaringClass, m); + break; + } + } + } + if (method.binding == null) + // GROOVY end method.binding = new MethodBinding(modifiers, null, null, declaringClass); checkAndSetModifiersForConstructor(method.binding); } else { @@ -387,6 +399,18 @@ MethodBinding createMethod(AbstractMethodDeclaration method) { modifiers |= ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract; } } + // GROOVY add + if (method.sourceStart > 0 && method.declarationSourceStart <= 0) { + TypeDeclaration type = enclosingClassScope().referenceContext; + for (AbstractMethodDeclaration m : type.methods) { + if (m != method && m.sourceStart == method.sourceStart) { + method.binding = new DelegateMethodBinding(modifiers, method.selector, declaringClass, m); + break; + } + } + } + if (method.binding == null) + // GROOVY end method.binding = new MethodBinding(modifiers, method.selector, null, null, null, declaringClass); checkAndSetModifiersForMethod(method.binding); @@ -431,8 +455,8 @@ MethodBinding createMethod(AbstractMethodDeclaration method) { TypeParameter[] typeParameters = method.typeParameters(); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, If they exist at all, process type parameters irrespective of source level. - if (typeParameters == null || typeParameters.length == 0) { - method.binding.typeVariables = Binding.NO_TYPE_VARIABLES; + if (typeParameters == null || typeParameters.length == 0) { + method.binding.typeVariables = Binding.NO_TYPE_VARIABLES; } else { method.binding.typeVariables = createTypeVariables(typeParameters, method.binding); method.binding.modifiers |= ExtraCompilerModifiers.AccGenericSignature;