001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2008 Sun Microsystems, Inc.
038: */
039:
040: package org.netbeans.modules.cnd.gotodeclaration.element.providers;
041:
042: import org.netbeans.modules.cnd.api.model.CsmDeclaration;
043: import org.netbeans.modules.cnd.api.model.CsmFunction;
044: import org.netbeans.modules.cnd.api.model.CsmFunctionDefinition;
045: import org.netbeans.modules.cnd.api.model.CsmNamespace;
046: import org.netbeans.modules.cnd.api.model.CsmProject;
047: import org.netbeans.modules.cnd.api.model.CsmVariable;
048: import org.netbeans.modules.cnd.gotodeclaration.element.spi.ElementProvider;
049: import org.netbeans.modules.cnd.gotodeclaration.util.NameMatcher;
050: import org.openide.util.NbBundle;
051:
052: /**
053: *
054: * @author vk155633
055: */
056: public class FuncVarElementProvider extends BaseProvider implements
057: ElementProvider {
058:
059: private static class FuncVarDelegate extends ProviderDelegate {
060:
061: public String name() {
062: return "C/C++ Functions and Variables"; // NOI18N
063: }
064:
065: public String getDisplayName() {
066: return NbBundle.getMessage(FuncVarElementProvider.class,
067: "FUNCVAR_PROVIDER_DISPLAY_NAME"); // NOI18N
068: }
069:
070: protected void processProject(CsmProject project,
071: ResultSet result, NameMatcher comparator) {
072: if (TRACE)
073: System.err.printf(
074: "FuncVarElementProvider.processProject %s\n",
075: project.getName());
076: processNamespace(project.getGlobalNamespace(), result,
077: comparator);
078: }
079:
080: private void processNamespace(CsmNamespace nsp,
081: ResultSet result, NameMatcher comparator) {
082: if (TRACE)
083: System.err.printf("processNamespace %s\n", nsp
084: .getQualifiedName());
085: for (CsmDeclaration declaration : nsp.getDeclarations()) {
086: if (isCancelled()) {
087: return;
088: }
089: processDeclaration(declaration, result, comparator);
090: }
091: for (CsmNamespace child : nsp.getNestedNamespaces()) {
092: if (isCancelled()) {
093: return;
094: }
095: processNamespace(child, result, comparator);
096: }
097: }
098:
099: private void processDeclaration(CsmDeclaration decl,
100: ResultSet result, NameMatcher comparator) {
101: switch (decl.getKind()) {
102: case FUNCTION_DEFINITION:
103: if (comparator.matches(decl.getName().toString())) {
104: CsmFunctionDefinition fdef = (CsmFunctionDefinition) decl;
105: // CsmFunction fdecl = fdef.getDeclaration();
106: // if( fdecl == null || fdecl == fdef) {
107: result.add(new FunctionElementDescriptor(fdef));
108: // }
109: }
110: break;
111: case FUNCTION:
112: if (comparator.matches(decl.getName().toString())) {
113: CsmFunction fdecl = (CsmFunction) decl;
114: CsmFunctionDefinition fdef = fdecl.getDefinition();
115: if (fdef == null || fdef.equals(fdecl)) {
116: result.add(new FunctionElementDescriptor(
117: (CsmFunction) decl));
118: }
119: }
120: break;
121: case VARIABLE:
122: if (comparator.matches(decl.getName().toString())) {
123: result.add(new VariableElementDescriptor(
124: (CsmVariable) decl));
125: }
126: break;
127: case CLASS:
128: case UNION:
129: case STRUCT:
130: case ENUM:
131: case TYPEDEF:
132: case BUILT_IN:
133: case ENUMERATOR:
134: case MACRO:
135: case VARIABLE_DEFINITION:
136: case TEMPLATE_SPECIALIZATION:
137: case ASM:
138: case TEMPLATE_DECLARATION:
139: case NAMESPACE_DEFINITION:
140: case NAMESPACE_ALIAS:
141: case USING_DIRECTIVE:
142: case USING_DECLARATION:
143: case CLASS_FORWARD_DECLARATION:
144: case CLASS_FRIEND_DECLARATION:
145: break;
146: }
147: }
148:
149: }
150:
151: @Override
152: protected ProviderDelegate createDelegate() {
153: return new FuncVarDelegate();
154: }
155:
156: public String getDisplayName() {
157: return NbBundle.getMessage(FuncVarElementProvider.class,
158: "FUNCVAR_PROVIDER_DISPLAY_NAME"); // NOI18N
159: }
160:
161: public String name() {
162: return "C/C++ Functions and Variables"; // NOI18N
163: }
164:
165: }
|