Bug 539598 - 281 API tools junit failures with I20180927-0135 with Java
11 

Change-Id: Ife115211514fc83f908795b0dd92e35e48967292
Signed-off-by: Vikas Chandra <Vikas.Chandra@in.ibm.com>
diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/TypeStructureBuilder.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/TypeStructureBuilder.java
index e9dc97c..275ef86 100644
--- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/TypeStructureBuilder.java
+++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/TypeStructureBuilder.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2017 IBM Corporation and others.
+ * Copyright (c) 2007, 2018 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -14,6 +14,8 @@
 import java.io.ByteArrayInputStream;
 import java.io.DataInputStream;
 import java.io.IOException;
+import java.util.Arrays;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -21,6 +23,11 @@
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
+import org.eclipse.jdt.launching.AbstractVMInstall;
+import org.eclipse.jdt.launching.IVMInstall;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
+import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
 import org.eclipse.osgi.util.NLS;
 import org.eclipse.pde.api.tools.internal.model.StubArchiveApiTypeContainer.ArchiveApiTypeRoot;
 import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
@@ -47,6 +54,22 @@
 	/**
 	 * Builds a type structure for a class file. Note that if an API component
 	 * is not specified, then some operations on the resulting {@link IApiType}
+	 * will not be available (navigating super types, member types, etc). This
+	 * constructor uses ASM7_EXPERIMENTAL
+	 *
+	 * @param useExperimental
+	 * @param cv class file visitor
+	 * @param component originating API component or <code>null</code> if
+	 *            unknown
+	 */
+	TypeStructureBuilder(boolean useExperimental, ClassVisitor cv, IApiComponent component, IApiTypeRoot file) {
+		super(Opcodes.ASM7_EXPERIMENTAL, cv);
+		fComponent = component;
+		fFile = file;
+	}
+	/**
+	 * Builds a type structure for a class file. Note that if an API component
+	 * is not specified, then some operations on the resulting {@link IApiType}
 	 * will not be available (navigating super types, member types, etc).
 	 *
 	 * @param cv class file visitor
@@ -254,7 +277,45 @@
 	 * @return
 	 */
 	public static IApiType buildTypeStructure(byte[] bytes, IApiComponent component, IApiTypeRoot file) {
-		TypeStructureBuilder visitor = new TypeStructureBuilder(new ClassNode(), component, file);
+		boolean useExperimental = false;
+		try {
+			String[] executionEnvironments = component.getExecutionEnvironments();
+			if (executionEnvironments.length == 1) {
+				String string = executionEnvironments[0];
+				IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
+				IExecutionEnvironment env = manager.getEnvironment(string);
+				IVMInstall[] compatibleVMs = env.getCompatibleVMs();
+				Arrays.sort(compatibleVMs, new Comparator<IVMInstall>() {
+					@Override
+					public int compare(IVMInstall o1, IVMInstall o2) {
+						return o1.getName().compareTo(o2.getName());
+					}
+				});
+				for (int i = 0; i < compatibleVMs.length; i++) {
+					if (compatibleVMs[i] instanceof AbstractVMInstall) {
+						AbstractVMInstall ivmInstall = (AbstractVMInstall) compatibleVMs[i];
+						String javaVersion = ivmInstall.getJavaVersion();
+						if (i == 0) {
+							useExperimental = javaVersion.equals("11"); //$NON-NLS-1$
+						}
+						boolean strictlyCompatible = env.isStrictlyCompatible(ivmInstall);
+						// if strictly compatible, then take that value
+						if (strictlyCompatible) {
+							useExperimental = javaVersion.equals("11"); //$NON-NLS-1$
+							break;
+						}
+					}
+				}
+			}
+
+		} catch (Exception e1) {
+			// do nothing
+		}
+		// Till ASM7 is incorporated, use ASM7_EXPERIMENTAL to
+		// avoidOperationUnsupportedException if Java 11 is on build path. If
+		// not Java
+		// 11 then use ASM6
+		TypeStructureBuilder visitor = useExperimental ? new TypeStructureBuilder(useExperimental, new ClassNode(), component, file) : new TypeStructureBuilder(new ClassNode(), component, file);
 		try {
 			ClassReader classReader = new ClassReader(bytes);
 			classReader.accept(visitor, ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES);