[393085] Tag files' Java content not indexed
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/search/JSPIndexManager.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/search/JSPIndexManager.java
index ddd050d..fcc7bf5 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/search/JSPIndexManager.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/search/JSPIndexManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 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
@@ -17,8 +17,6 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jst.jsp.core.internal.JSPCoreMessages;
@@ -42,11 +40,7 @@
public class JSPIndexManager extends AbstractIndexManager {
/** the singleton instance of the {@link JSPIndexManager} */
private static JSPIndexManager INSTANCE;
-
- /** the JSP {@link IContentType} */
- private static final IContentType JSP_CONTENT_TYPE =
- Platform.getContentTypeManager().getContentType(ContentTypeIdForJSP.ContentTypeID_JSP);
-
+
/** the location to store state */
private IPath fWorkingLocation;
@@ -69,10 +63,8 @@
*/
protected boolean isResourceToIndex(int type, IPath path) {
String name = path.lastSegment();
- return
- type == IResource.PROJECT ||
- (type == IResource.FOLDER && !name.equals("bin") && !name.startsWith(".")) || //$NON-NLS-1$ //$NON-NLS-2$
- JSP_CONTENT_TYPE.isAssociatedWith(path.lastSegment());
+
+ return type == IResource.PROJECT || (type == IResource.FOLDER && !name.equals("bin") && !name.startsWith(".")) || ContentTypeIdForJSP.indexOfJSPExtension(path.lastSegment()) >= 0;//$NON-NLS-1$ //$NON-NLS-2$
}
/**
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/provisional/contenttype/ContentTypeIdForJSP.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/provisional/contenttype/ContentTypeIdForJSP.java
index 0f246bc..b927d11 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/provisional/contenttype/ContentTypeIdForJSP.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/provisional/contenttype/ContentTypeIdForJSP.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 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
@@ -12,6 +12,12 @@
package org.eclipse.jst.jsp.core.internal.provisional.contenttype;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.content.IContentType;
+
/**
* This class, with its one field, is a convience to provide compile-time
* safety when refering to a contentType ID. The value of the contenttype id
@@ -39,6 +45,9 @@
*/
public final static String ContentTypeID_JSPTAG = getTagConstantString();
+ private static char[][] JSP_EXTENSIONS;
+ private static String JSP = "jsp";
+
/**
* Don't allow instantiation.
*/
@@ -58,4 +67,64 @@
return "org.eclipse.jst.jsp.core.tagsource"; //$NON-NLS-1$
}
+ /**
+ * @param fileName
+ * @return the first index within an array of filename extensions that
+ * denote the JSP content type or a subtype and match the
+ * extension of the given filename
+ */
+ public static int indexOfJSPExtension(String fileName) {
+ int fileNameLength = fileName.length();
+ char[][] jspExtensions = getJSPExtensions();
+ extensions: for (int i = 0, length = jspExtensions.length; i < length; i++) {
+ char[] extension = jspExtensions[i];
+ int extensionLength = extension.length;
+ int extensionStart = fileNameLength - extensionLength;
+ int dotIndex = extensionStart - 1;
+ if (dotIndex < 0) continue;
+ if (fileName.charAt(dotIndex) != '.') continue;
+ for (int j = 0; j < extensionLength; j++) {
+ if (fileName.charAt(extensionStart + j) != extension[j])
+ continue extensions;
+ }
+ return dotIndex;
+ }
+ return -1;
+ }
+
+ /**
+ * @return an array of all filename extensions that are of the JSP content
+ * type or one of its subtypes
+ */
+ public static char[][] getJSPExtensions() {
+ if (JSP_EXTENSIONS == null) {
+ IContentType jspContentType = Platform.getContentTypeManager().getContentType(getConstantString());
+ HashSet fileExtensions = new HashSet();
+ // content types derived from JSP content type should be included (https://bugs.eclipse.org/bugs/show_bug.cgi?id=121715)
+ IContentType[] contentTypes = Platform.getContentTypeManager().getAllContentTypes();
+ for (int i = 0, length = contentTypes.length; i < length; i++) {
+ if (contentTypes[i].isKindOf(jspContentType)) { // note that jspContentType.isKindOf(jspContentType) == true
+ String[] fileExtension = contentTypes[i].getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
+ for (int j = 0; j < fileExtension.length; j++) {
+ fileExtensions.add(fileExtension[j]);
+ }
+ }
+ }
+ int length = fileExtensions.size();
+ // note that file extensions contains "jsp"
+ char[][] extensions = new char[length][];
+ extensions[0] = JSP.toCharArray(); // ensure that "jsp" is first
+ int index = 1;
+ Iterator iterator = fileExtensions.iterator();
+ while (iterator.hasNext()) {
+ String fileExtension = (String) iterator.next();
+ if (JSP.equalsIgnoreCase(fileExtension))
+ continue;
+ extensions[index++] = fileExtension.toCharArray();
+ }
+ JSP_EXTENSIONS = extensions;
+ }
+ return JSP_EXTENSIONS;
+ }
+
}