Bug 392135: [open type] Open type does not respect access restriction filters

UI follow-up to bug 218487
diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/TypeFilter.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/TypeFilter.java
index 0c5ab32..400915e 100644
--- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/TypeFilter.java
+++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/TypeFilter.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 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
@@ -15,7 +15,9 @@
 import org.eclipse.jface.util.IPropertyChangeListener;
 import org.eclipse.jface.util.PropertyChangeEvent;
 
+import org.eclipse.jdt.core.IAccessRule;
 import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.core.search.TypeNameMatch;
 
 import org.eclipse.jdt.ui.PreferenceConstants;
@@ -53,7 +55,19 @@
 	}
 
 	public static boolean isFiltered(TypeNameMatch match) {
-		return getDefault().filter(match.getFullyQualifiedName());
+		boolean filteredByPattern= getDefault().filter(match.getFullyQualifiedName());
+		if (filteredByPattern)
+			return true;
+		
+		int accessibility= match.getAccessibility();
+		switch (accessibility) {
+			case IAccessRule.K_NON_ACCESSIBLE:
+				return JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK));
+			case IAccessRule.K_DISCOURAGED:
+				return JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_DISCOURAGED_REFERENCE_CHECK));
+			default:
+				return false;
+		}
 	}
 
 	private StringMatcher[] fStringMatchers;
@@ -93,6 +107,10 @@
 		return getStringMatchers().length > 0;
 	}
 
+	/**
+	 * @param fullTypeName fully-qualified type name
+	 * @return <code>true</code> iff the given type is filtered out
+	 */
 	public boolean filter(String fullTypeName) {
 		StringMatcher[] matchers= getStringMatchers();
 		for (int i= 0; i < matchers.length; i++) {
diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/TypeNameMatchCollector.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/TypeNameMatchCollector.java
index 3589c73..7dec9cc 100644
--- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/TypeNameMatchCollector.java
+++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/TypeNameMatchCollector.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 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
@@ -14,8 +14,6 @@
 
 import org.eclipse.core.runtime.Assert;
 
-import org.eclipse.jdt.core.IAccessRule;
-import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.core.search.TypeNameMatch;
 import org.eclipse.jdt.core.search.TypeNameMatchRequestor;
 
@@ -29,18 +27,7 @@
 	}
 
 	private boolean inScope(TypeNameMatch match) {
-		if (TypeFilter.isFiltered(match))
-			return false;
-		
-		int accessibility= match.getAccessibility();
-		switch (accessibility) {
-			case IAccessRule.K_NON_ACCESSIBLE:
-				return JavaCore.DISABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK));
-			case IAccessRule.K_DISCOURAGED:
-				return JavaCore.DISABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_DISCOURAGED_REFERENCE_CHECK));
-			default:
-				return true;
-		}
+		return ! TypeFilter.isFiltered(match);
 	}
 
 	/* (non-Javadoc)