Fix for bug 507954 Type Hierarchy incomplete, misses some anonymous
subtypes

Change-Id: I7f4d66853bfcc763c46fbc38d5f8e0d03d6c620f
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java
index 227dd0e..a83c1de 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 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
@@ -2919,4 +2919,98 @@
 			deleteProject(prj);
 	}
 }
+public void testBug507954_0001() throws JavaModelException, CoreException {
+	IJavaProject javaProject = null; 
+	try {
+		String projectName = "507954";
+		javaProject = createJavaProject(projectName, new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5");
+		String packA = "/" + projectName + "/src/a/";
+		createFolder(packA);
+		String fileA = 				"package a;\n" +
+				"public abstract class A {\n"+
+				"  protected abstract void foo2();\n" +
+				"  public void baz2() {\n" +
+				"    foo2();\n" +
+			"}";
+		createFile(packA + "A.java", fileA);
+		createFile(
+				packA + "B.java",
+				"package a;\n" +
+				"public class B {\n" +
+				"  public void a() {\n" +
+				"    new A() {\n" +
+				"      @Override\n" +
+				"      protected void foo2() {}\n" +
+				"    }.baz2();\n" +
+				"  }\n" +
+				"}"
+				);
+		createFile(
+				packA + "C.java",
+				"package a;\n" +
+				"public abstract class C {\n" +
+				"  protected abstract void foo1();\n" +
+				"  public void baz1() {\n" +
+				"    foo1();\n" +
+				"  }\n" +
+				"}"
+				);
+		String packD = "/" + projectName + "/src/b/";
+		createFolder(packD);
+
+		String fileD = "package d;\n" +
+				"import a.A;\n" +
+				"import a.C;\n" +
+				"public final class D {\n" +
+				"\n" +
+				"	protected void c() {\n" +
+				"		new C() {\n" +
+				"			@Override\n" +
+				"			protected void foo1() {\n" +
+				"				a();\n" +
+				"				b();\n" +
+				"			}\n" +
+				"			private void a() {\n" +
+				"				new A() {\n" +
+				"					@Override\n" +
+				"					protected void foo2() {\n" +
+				"					}\n" +
+				"				}.baz2();\n" +
+				"			}\n" +
+				"			private void b() {\n" +
+				"				new A() {\n" +
+				"					@Override\n" +
+				"					protected void foo2() {\n" +
+				"					}\n" +
+				"				}.baz2();\n" +
+				"			}\n" +
+				"		}.baz1();\n" +
+				"	}\n" +
+				"\n" +
+				"}\n";
+
+		createFile(packA + "D.java", fileD);
+		
+		String classA = "A";
+		int start = fileA.indexOf(classA);
+		this.workingCopies = new ICompilationUnit[1];
+		this.workingCopies[0] = getWorkingCopy(packA + "A.java", fileA);
+
+		IJavaElement[] elements = this.workingCopies[0].codeSelect(start, classA.length());
+		assertEquals("Incorrect elements", 1, elements.length);
+		IType focus = (IType) elements[0];
+		ITypeHierarchy hierarchy = focus.newTypeHierarchy(this.workingCopies, null);
+		IType[] allSubTypes = hierarchy.getAllSubtypes(focus);
+		assertTypesEqual("Incorrect hierarchy",
+				"a.B$1\n" + 
+				"a.D$1$1\n" + 
+				"a.D$1$1\n",
+				allSubTypes,
+				true);
+	}
+	finally{
+		if (javaProject != null) deleteProject(javaProject);
+	}
+}
+
 }
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/DiskIndex.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/DiskIndex.java
index d7c78b7..b13ab07 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/DiskIndex.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/DiskIndex.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 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
@@ -46,7 +46,7 @@
 private int streamEnd; // used when writing data from the streamBuffer to the file
 char separator = Index.DEFAULT_SEPARATOR;
 
-public static final String SIGNATURE= "INDEX VERSION 1.129"; //$NON-NLS-1$
+public static final String SIGNATURE= "INDEX VERSION 1.130"; //$NON-NLS-1$
 private static final char[] SIGNATURE_CHARS = SIGNATURE.toCharArray();
 public static boolean DEBUG = false;
 
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java
index 8824b1d..4972e13 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 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
@@ -306,7 +306,10 @@
 	this.indexer.addMethodDeclaration(methodInfo.name, methodInfo.parameterTypes, methodInfo.returnType, methodInfo.exceptionTypes);
 	int argCount = methodInfo.parameterTypes == null ? 0 : methodInfo.parameterTypes.length;
 	char[] typeName = methodInfo.enclosingType != null ? methodInfo.enclosingType.name : null;
-	if (typeName == null || typeName.length == 0) return;
+	if (typeName == null || typeName.length == 0)  {
+		this.methodDepth++;
+		return;
+	}
 	this.indexer.addMethodDeclaration(
 			typeName,
 			getDeclaringQualification(methodInfo.enclosingType),