1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.viewsupport;
13 import net.sourceforge.phpdt.core.Flags;
14 import net.sourceforge.phpdt.core.IField;
15 import net.sourceforge.phpdt.core.IJavaElement;
16 import net.sourceforge.phpdt.core.IMember;
17 import net.sourceforge.phpdt.core.IType;
18 import net.sourceforge.phpdt.core.JavaModelException;
20 import org.eclipse.jface.viewers.Viewer;
21 import org.eclipse.jface.viewers.ViewerFilter;
24 * Filter for the methods viewer. Changing a filter property does not trigger a
25 * refiltering of the viewer
27 public class MemberFilter extends ViewerFilter {
29 public static final int FILTER_NONPUBLIC = 1;
31 public static final int FILTER_STATIC = 2;
33 public static final int FILTER_FIELDS = 4;
35 private int fFilterProperties;
38 * Modifies filter and add a property to filter for
40 public final void addFilter(int filter) {
41 fFilterProperties |= filter;
45 * Modifies filter and remove a property to filter for
47 public final void removeFilter(int filter) {
48 fFilterProperties &= (-1 ^ filter);
52 * Tests if a property is filtered
54 public final boolean hasFilter(int filter) {
55 return (fFilterProperties & filter) != 0;
59 * @see ViewerFilter@isFilterProperty
61 // public boolean isFilterProperty(Object element, Object property) {
66 * @see ViewerFilter@select
68 public boolean select(Viewer viewer, Object parentElement, Object element) {
70 if (hasFilter(FILTER_FIELDS) && element instanceof IField) {
73 if (element instanceof IMember) {
74 IMember member = (IMember) element;
75 if (member.getElementName().startsWith("<")) { // filter out
80 int flags = member.getFlags();
81 if (hasFilter(FILTER_STATIC)
82 && (Flags.isStatic(flags) || isFieldInInterface(member))
83 && member.getElementType() != IJavaElement.TYPE) {
86 if (hasFilter(FILTER_NONPUBLIC) && !Flags.isPublic(flags)
87 && !isMemberInInterface(member)
88 && !isTopLevelType(member)) {
92 } catch (JavaModelException e) {
98 private boolean isMemberInInterface(IMember member)
99 throws JavaModelException {
100 IType parent = member.getDeclaringType();
101 return parent != null && parent.isInterface();
104 private boolean isFieldInInterface(IMember member)
105 throws JavaModelException {
106 return (member.getElementType() == IJavaElement.FIELD)
107 && member.getDeclaringType().isInterface();
110 private boolean isTopLevelType(IMember member) throws JavaModelException {
111 IType parent = member.getDeclaringType();
112 return parent == null;