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: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.cnd.api.model.xref;
043:
044: import java.util.Collection;
045: import java.util.Collections;
046: import java.util.EnumSet;
047: import java.util.Map;
048: import org.netbeans.modules.cnd.api.model.CsmFile;
049: import org.netbeans.modules.cnd.api.model.CsmObject;
050: import org.netbeans.modules.cnd.api.model.CsmProject;
051: import org.openide.util.Lookup;
052:
053: /**
054: * entry point to search references of model object in projects
055: * @author Vladimir Voskresensky
056: */
057: public abstract class CsmReferenceRepository {
058: /** A dummy Repository that never returns any results.
059: */
060: private static final CsmReferenceRepository EMPTY = new Empty();
061:
062: /** default instance */
063: private static CsmReferenceRepository defaultRepository;
064:
065: protected CsmReferenceRepository() {
066: }
067:
068: /** Static method to obtain the Repository.
069: * @return the Repository
070: */
071: public static synchronized CsmReferenceRepository getDefault() {
072: if (defaultRepository != null) {
073: return defaultRepository;
074: }
075: defaultRepository = (CsmReferenceRepository) Lookup
076: .getDefault().lookup(CsmReferenceRepository.class);
077: return defaultRepository == null ? EMPTY : defaultRepository;
078: }
079:
080: /**
081: * look for references of target object in project
082: * @param target target object to find references
083: * @param project project as scope where to search
084: * @param kinds flag indicating wether or not to include
085: * self declaration object in collection
086: * @return references for target object, empty collection if not found
087: */
088: public abstract Collection<CsmReference> getReferences(
089: CsmObject target, CsmProject project,
090: EnumSet<CsmReferenceKind> kinds);
091:
092: /**
093: * look for references of target object in project
094: * @param target target object to find references
095: * @param file file as scope where to search
096: * @param kinds flag indicating wether or not to include
097: * self declaration object in collection
098: * @return references for target object, empty collection if not found
099: */
100: public abstract Collection<CsmReference> getReferences(
101: CsmObject target, CsmFile file,
102: EnumSet<CsmReferenceKind> kinds);
103:
104: /**
105: * look for references of target objects in project
106: * @param targets target objects to find references
107: * @param project project as scope where to search
108: * @param kinds flag indicating wether or not to include
109: * self declaration object in collection
110: * @return references for target object, empty collection if not found
111: */
112: //public abstract Map<CsmObject, Collection<CsmReference>> getReferences(CsmObject[] targets, CsmProject project, EnumSet<CsmReferenceKind> kinds);
113: /**
114: * look for references of target objects in file
115: * @param targets target objects to find references
116: * @param file file as scope where to search
117: * @param kinds kind of references to search
118: * @return references for target objects in file sorted from beginning,
119: * empty collection if no references
120: */
121: public abstract Collection<CsmReference> getReferences(
122: CsmObject[] targets, CsmFile file,
123: EnumSet<CsmReferenceKind> kinds);
124:
125: //
126: // Implementation of the default Repository
127: //
128: private static final class Empty extends CsmReferenceRepository {
129: Empty() {
130: }
131:
132: public Collection<CsmReference> getReferences(CsmObject target,
133: CsmProject project, EnumSet<CsmReferenceKind> kinds) {
134: return Collections.<CsmReference> emptyList();
135: }
136:
137: public Map<CsmObject, Collection<CsmReference>> getReferences(
138: CsmObject[] targets, CsmProject project,
139: EnumSet<CsmReferenceKind> kinds) {
140: return Collections
141: .<CsmObject, Collection<CsmReference>> emptyMap();
142: }
143:
144: public Collection<CsmReference> getReferences(CsmObject target,
145: CsmFile file, EnumSet<CsmReferenceKind> kinds) {
146: return Collections.<CsmReference> emptyList();
147: }
148:
149: public Collection<CsmReference> getReferences(
150: CsmObject[] targets, CsmFile file,
151: EnumSet<CsmReferenceKind> kinds) {
152: return Collections.<CsmReference> emptyList();
153: }
154: }
155: }
|