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.completion.impl.xref;
041:
042: import java.io.File;
043: import java.util.ArrayList;
044: import java.util.List;
045: import org.netbeans.editor.BaseDocument;
046: import org.netbeans.editor.TokenID;
047: import org.netbeans.editor.TokenItem;
048: import org.netbeans.editor.ext.ExtSyntaxSupport;
049: import org.netbeans.modules.cnd.api.model.CsmFile;
050: import org.netbeans.modules.cnd.api.model.CsmObject;
051: import org.netbeans.modules.cnd.api.model.util.CsmTracer;
052: import org.netbeans.modules.cnd.editor.cplusplus.CCTokenContext;
053: import org.netbeans.modules.cnd.modelimpl.test.ProjectBasedTestCase;
054:
055: /**
056: *
057: * @author Vladimir Voskresensky
058: */
059: public class ReferencesBaseTestCase extends ProjectBasedTestCase {
060:
061: public ReferencesBaseTestCase(String testName) {
062: super (testName);
063: }
064:
065: protected final void performTest(String source) throws Exception {
066: File testSourceFile = getDataFile(source);
067: CsmFile csmFile = getCsmFile(testSourceFile);
068: BaseDocument doc = getBaseDocument(testSourceFile);
069: ExtSyntaxSupport ssup = (ExtSyntaxSupport) doc
070: .getSyntaxSupport();
071: TokenItem token = ssup.getTokenChain(0, doc.getLength());
072: log("creating list of references:");
073: List<ReferenceImpl> refs = new ArrayList(1024);
074: while (token != null) {
075: if (supportReference(token.getTokenID())) {
076: ReferenceImpl ref = ReferencesSupport
077: .createReferenceImpl(csmFile, doc, token);
078: assertNotNull(
079: "reference must not be null for valid token "
080: + token, ref);
081: refs.add(ref);
082: log(ref.toString());
083: }
084: token = token.getNext();
085: }
086: log("end of references list");
087: log("start resolving referenced objects");
088: for (ReferenceImpl ref : refs) {
089: CsmObject owner = ref.getOwner();
090: ref(ref.toString());
091: ref("--OWNER:\n " + CsmTracer.toString(owner));
092: CsmObject out = ref.getReferencedObject();
093: ref("--RESOLVED TO:\n " + CsmTracer.toString(out));
094: ref("==============================================================");
095: }
096: log("end of resolving referenced objects");
097: compareReferenceFiles();
098: }
099:
100: protected boolean supportReference(TokenID tokenID) {
101: assert tokenID != null;
102: switch (tokenID.getNumericID()) {
103: case CCTokenContext.IDENTIFIER_ID:
104: case CCTokenContext.SYS_INCLUDE_ID:
105: case CCTokenContext.USR_INCLUDE_ID:
106: return true;
107: }
108: return false;
109: }
110: }
|