Bug 435109 - with apt in the loop, anchored type may leak an unwrapped
LocalVariableBinding

+ migrate adaptation from role into its base class
+ make org.eclipse.objectteams.otdt.apt an empty shell
diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationDiscoveryVisitor.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationDiscoveryVisitor.java
index a115f6e..dd726dc 100644
--- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationDiscoveryVisitor.java
+++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationDiscoveryVisitor.java
@@ -43,8 +43,15 @@
 import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding;
 import org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding;
 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
+import org.eclipse.jdt.internal.compiler.lookup.Scope;
 import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
+import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
 import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
+import org.eclipse.objectteams.otdt.internal.core.compiler.ast.AbstractMethodMappingDeclaration;
+import org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies;
+import org.eclipse.objectteams.otdt.internal.core.compiler.control.ITranslationStates;
+import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.DependentTypeBinding;
+import org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel;
 
 /**
  * This class is used to visit the JDT compiler internal AST to discover annotations,
@@ -68,14 +75,43 @@
 	@Override
 	public boolean visit(Argument argument, BlockScope scope) {
 		Annotation[] annotations = argument.annotations;
+//{ObjectTeams: handle cases of AbstractMethodDeclaration AND AbstractMethodMappingDeclaration
+		Argument[] sourceArguments = null;
+		MethodBinding binding = null;
+// orig
 		ReferenceContext referenceContext = scope.referenceContext();
 		if (referenceContext instanceof AbstractMethodDeclaration) {
+/* assign binding in both branches
 			MethodBinding binding = ((AbstractMethodDeclaration) referenceContext).binding;
+  :giro
+ */
+			binding = ((AbstractMethodDeclaration) referenceContext).binding;
+			sourceArguments = ((AbstractMethodDeclaration) referenceContext).arguments;
+		} else if (scope.kind == Scope.BINDING_SCOPE) {
+			AbstractMethodMappingDeclaration mapping = (AbstractMethodMappingDeclaration) scope.referenceContext();
+			sourceArguments = findSiblingArguments(mapping, argument);
+			if (sourceArguments != null) {
+				RoleModel roleModel = scope.referenceType().getRoleModel();
+				if (roleModel != null)
+					Dependencies.ensureRoleState(roleModel, ITranslationStates.STATE_METHODS_CREATED); // needed for accessing the method binding.
+				binding = mapping.getRoleMethod();
+			}
+		} // orig next "if" was inline "if (referenceContext instanceof AbstractMethodDeclaration)"
+// SH}
 			if (binding != null) {
 				TypeDeclaration typeDeclaration = scope.referenceType();
 				typeDeclaration.binding.resolveTypesFor(binding);
 				if (argument.binding != null) {
 					argument.binding = new AptSourceLocalVariableBinding(argument.binding, binding);
+//{ObjectTeams: update new LVB if needed:
+					if (sourceArguments != null) {
+						TypeBinding argType = argument.binding.type;
+						if (argType instanceof DependentTypeBinding) {
+							// avoid that an unreplaced LVB leaks past this point:
+							((DependentTypeBinding)argType).updateAnchor(sourceArguments);
+						}
+					}
+// SH}
 				}
 			}
 			if (annotations != null && argument.binding != null) {
@@ -84,10 +120,23 @@
 						annotations,
 						argument.binding);
 			}
+/*{ObjectTeams:
 		}
+ */
 		return false;
 	}
 
+//{ObjectTeams: helper for visit(Argument, BlockScope), answer the role argument array if it contains 'argument':
+	private Argument[] findSiblingArguments(AbstractMethodMappingDeclaration mapping, Argument argument) {
+		if (mapping.roleMethodSpec.arguments != null) {
+			for (Argument roleArg : mapping.roleMethodSpec.arguments)
+				if (roleArg == argument)
+					return mapping.roleMethodSpec.arguments;
+		}
+		return null;
+	}
+// SH}
+
 	@Override
 	public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope scope) {
 		Annotation[] annotations = constructorDeclaration.annotations;
@@ -258,8 +307,8 @@
 
 		Annotation[] annotations = module.annotations;
 		if (annotations != null) {
-			this.resolveAnnotations(module.scope, 
-					annotations, 
+			this.resolveAnnotations(module.scope,
+					annotations,
 					binding);
 		}
 		return true;
diff --git a/plugins/org.eclipse.objectteams.otdt.apt/META-INF/MANIFEST.MF b/plugins/org.eclipse.objectteams.otdt.apt/META-INF/MANIFEST.MF
index a09636b..f584945 100644
--- a/plugins/org.eclipse.objectteams.otdt.apt/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.objectteams.otdt.apt/META-INF/MANIFEST.MF
@@ -7,9 +7,4 @@
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
 Bundle-RequiredExecutionEnvironment: JavaSE-17
-Require-Bundle: org.eclipse.objectteams.otequinox;bundle-version="[2.5.0,3.0.0)",
- org.eclipse.osgi;bundle-version="[3.7.0,4.0.0)",
- org.eclipse.jdt.core;bundle-version="[3.34.0.OTDT_r282,4.0.0)"
-Import-Package: org.eclipse.jdt.internal.compiler.apt.dispatch
 Bundle-ActivationPolicy: lazy
-Export-Package: org.eclipse.objectteams.otdt.internal.apt;x-internal:=true
diff --git a/plugins/org.eclipse.objectteams.otdt.apt/plugin.xml b/plugins/org.eclipse.objectteams.otdt.apt/plugin.xml
index 720dc1e..5535690 100644
--- a/plugins/org.eclipse.objectteams.otdt.apt/plugin.xml
+++ b/plugins/org.eclipse.objectteams.otdt.apt/plugin.xml
@@ -1,23 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?eclipse version="3.4"?>
 <plugin>
-   <extension
-         point="org.eclipse.objectteams.otequinox.aspectBindings">
-      <aspectBinding
-            icon="platform:/plugin/org.eclipse.objectteams.otdt.ui/icons/ot/calloutbinding_obj.gif">
-         <basePlugin
-               icon="platform:/plugin/org.eclipse.pde.ui/icons/obj16/plugin_obj.png"
-               id="org.eclipse.jdt.core.compiler.batch">
-         </basePlugin>
-         <team
-               activation="ALL_THREADS"
-               class="org.eclipse.objectteams.otdt.internal.apt.VisitorsAdaptor"
-               icon="platform:/plugin/org.eclipse.objectteams.otdt.ui/icons/ot/team_obj.gif">
-            <superBase
-                  class="org.eclipse.jdt.internal.compiler.ASTVisitor">
-            </superBase>
-         </team>
-      </aspectBinding>
-   </extension>
 
 </plugin>
diff --git a/plugins/org.eclipse.objectteams.otdt.apt/src/org/eclipse/objectteams/otdt/internal/apt/VisitorsAdaptor.java b/plugins/org.eclipse.objectteams.otdt.apt/src/org/eclipse/objectteams/otdt/internal/apt/VisitorsAdaptor.java
deleted file mode 100644
index efc1e1a..0000000
--- a/plugins/org.eclipse.objectteams.otdt.apt/src/org/eclipse/objectteams/otdt/internal/apt/VisitorsAdaptor.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/**********************************************************************
- * This file is part of "Object Teams Development Tooling"-Software
- * 
- * Copyright 2009, 2014 Stephan Herrmann
- * 
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Please visit http://www.eclipse.org/objectteams for updates and contact.
- **********************************************************************/
-package org.eclipse.objectteams.otdt.internal.apt;
-
-import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.Annotation;
-import org.eclipse.jdt.internal.compiler.ast.Argument;
-import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
-import org.eclipse.jdt.internal.compiler.lookup.AptSourceLocalVariableBinding;
-import org.eclipse.jdt.internal.compiler.lookup.Binding;
-import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
-import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
-import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
-import org.eclipse.jdt.internal.compiler.lookup.Scope;
-import org.eclipse.objectteams.otdt.internal.core.compiler.ast.AbstractMethodMappingDeclaration;
-import org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies;
-import org.eclipse.objectteams.otdt.internal.core.compiler.control.ITranslationStates;
-import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.DependentTypeBinding;
-import org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel;
-
-import base org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationDiscoveryVisitor;
-
-/**
- * This class adapts visitors used in annotation processing that need to be aware of
- * OT extensions of the compiler ast - 
- * currently only {@link org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationDiscoveryVisitor}.
- * 
- * @author stephan
- * @since 1.2.7
- */
-@SuppressWarnings("restriction")
-public team class VisitorsAdaptor {
-	protected class AnnotationDiscoveryVisitor playedBy AnnotationDiscoveryVisitor {
-
-		@SuppressWarnings("decapsulation")
-		void resolveAnnotations(BlockScope arg0, Annotation[] arg1, Binding arg2)
-			-> void resolveAnnotations(BlockScope arg0, Annotation[] arg1, Binding arg2);
-
-
-		boolean visit(Argument argument, BlockScope scope) 
-			<- replace boolean visit(Argument argument, BlockScope scope);
-
-
-		@SuppressWarnings("basecall")
-		callin boolean visit(Argument argument, BlockScope scope) {
-			if (scope.kind == Scope.BINDING_SCOPE) { // don't blindly assume that we're inside a method
-				Annotation[] annotations = argument.annotations;
-				// the payload (orig uses cast to AbstractMethodDeclaration):
-				AbstractMethodMappingDeclaration mapping = (AbstractMethodMappingDeclaration) scope.referenceContext();
-				RoleModel roleModel = scope.referenceType().getRoleModel();
-				if (roleModel != null)
-					Dependencies.ensureRoleState(roleModel, ITranslationStates.STATE_METHODS_CREATED); // needed for accessing the method binding.
-				MethodBinding binding = mapping.getRoleMethod(); 
-				//
-				if (binding != null) {
-					TypeDeclaration typeDeclaration = scope.referenceType();
-					typeDeclaration.binding.resolveTypesFor(binding);
-					if (argument.binding != null) {
-						argument.binding = new AptSourceLocalVariableBinding(argument.binding, binding);
-					}
-				}
-				if (annotations != null) {
-					this.resolveAnnotations(
-							scope,
-							annotations,
-							argument.binding);
-				}
-				return false;
-			} else {
-				boolean result = base.visit(argument, scope);
-				if (argument.binding != null && argument.binding.type instanceof DependentTypeBinding) {
-					// avoid that an unreplaced LVB leaks past this point:
-					MethodScope methodScope = scope.methodScope();
-					if (methodScope != null) {
-						AbstractMethodDeclaration method = methodScope.referenceMethod();
-						if (method != null)
-							((DependentTypeBinding)argument.binding.type).updateAnchor(method.arguments);
-					}
-				}
-				return result;
-			}
-		}
-	}
-}