blob: 83b665d5c7b4453d32326bed2d465f4729566c37 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
/*******************************************************************************
* Copyright (c) 2001, 2008 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Rational Software - initial implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.viewsupport;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IDeclaration;
import org.eclipse.cdt.core.model.IField;
import org.eclipse.cdt.core.model.IMember;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
/**
* Filter for the methods viewer.
* Changing a filter property does not trigger a refiltering of the viewer
*/
public class MemberFilter extends ViewerFilter{
public static final int FILTER_NONPUBLIC= 1;
public static final int FILTER_STATIC= 2;
public static final int FILTER_FIELDS= 4;
/** @deprecated Unsupported filter constant */
@Deprecated
public static final int FILTER_LOCALTYPES= 8;
private int fFilterProperties;
/**
* Modifies filter and add a property to filter for
*/
public final void addFilter(int filter) {
fFilterProperties |= filter;
}
/**
* Modifies filter and remove a property to filter for
*/
public final void removeFilter(int filter) {
fFilterProperties &= (-1 ^ filter);
}
/**
* Tests if a property is filtered
*/
public final boolean hasFilter(int filter) {
return (fFilterProperties & filter) != 0;
}
/*
* @see ViewerFilter@isFilterProperty
*/
public boolean isFilterProperty(Object element, Object property) {
return false;
}
/*
* @see ViewerFilter@select
*/
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if(element instanceof IDeclaration){
try {
IDeclaration declaration = (IDeclaration) element;
if (hasFilter(FILTER_STATIC) && (declaration.isStatic()) ) {
return false;
}
if (element instanceof IMember) {
IMember member= (IMember)element;
if (hasFilter(FILTER_NONPUBLIC) && (member.getVisibility() != ASTAccessVisibility.PUBLIC)) {
return false;
}
if (hasFilter(FILTER_FIELDS) && element instanceof IField) {
return false;
}
}
} catch (CModelException e) {
// ignore
}
}
return true;
}
}
|