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.completion.cplusplus;
043:
044: import org.netbeans.editor.BaseDocument;
045:
046: /**
047: *
048: * @author vv159170
049: */
050: public class NbCsmUtilities {
051:
052: private BaseDocument doc;
053:
054: // private FileObject fileObject = null;
055:
056: // ..........................................................................
057:
058: public static synchronized NbCsmUtilities get(BaseDocument doc) {
059: NbCsmUtilities utils = (NbCsmUtilities) doc
060: .getProperty(NbCsmUtilities.class);
061: if (utils == null) {
062: utils = new NbCsmUtilities(doc);
063: doc.putProperty(NbCsmUtilities.class, utils);
064: }
065: return utils;
066: }
067:
068: /**
069: * Creates a new instance of NbCsmUtilities
070: */
071: private NbCsmUtilities(BaseDocument doc) {
072: this .doc = doc;
073: // DataObject dob = NbEditorUtilities.getDataObject(doc);
074: // if (dob != null) {
075: // FileObject fo=dob.getPrimaryFile();
076: // ClassPath sourceCP = ClassPath.getClassPath(fo, ClassPath.SOURCE);
077: // if (sourceCP != null) {
078: // this.fileObject = sourceCP.findOwnerRoot(fo);
079: // }
080: // }
081: }
082:
083: // private Object getAssociatedObject(Object item) {
084: // return item;
085: // }
086:
087: // public Object findItemAtCaretPos(JTextComponent target){
088: // Completion completion = ExtUtilities.getCompletion(target);
089: // if (completion != null) {
090: // if (completion.isPaneVisible()) { // completion pane visible
091: // Object item = getAssociatedObject(completion.getSelectedValue());
092: // if (item != null) {
093: // return item;
094: // }
095: // } else { // pane not visible
096: // try {
097: // SyntaxSupport sup = Utilities.getSyntaxSupport(target);
098: // CompletionQuery qry = (CompletionQuery)completion.getQuery();
099: // if (!(qry instanceof NbCsmCompletionQuery)) {
100: // return null;
101: // }
102: // NbCsmCompletionQuery query = (NbCsmCompletionQuery)qry;
103: //
104: // int dotPos = target.getCaret().getDot();
105: // BaseDocument doc = (BaseDocument)target.getDocument();
106: // int[] idFunBlk = NbEditorUtilities.getIdentifierAndMethodBlock(doc, dotPos);
107: //
108: // if (idFunBlk == null) {
109: // idFunBlk = new int[] { dotPos, dotPos };
110: // }
111: //
112: // for (int ind = idFunBlk.length - 1; ind >= 1; ind--) {
113: // CompletionQuery.Result result = query.query(target, idFunBlk[ind], sup, true);
114: // if (result != null && result.getData().size() > 0) {
115: // Object itm = getAssociatedObject(result.getData().get(0));
116: // if (result.getData().size() > 1 /*&& (itm instanceof Constructor || itm instanceof Method)*/) {
117: // // It is overloaded method, lets check for the right one
118: //// int endOfMethod = JCExtension.findEndOfMethod(target, idFunBlk[ind]);
119: // int endOfMethod = findEndOfMethod(target, idFunBlk[ind]);
120: // if (endOfMethod > -1){
121: // CompletionQuery.Result resultx = query.query(target, endOfMethod, sup, true);
122: // if (resultx != null && resultx.getData().size() > 0) {
123: // return getAssociatedObject(resultx.getData().get(0));
124: // }
125: // }
126: // }
127: // return itm;
128: // }
129: // }
130: // } catch (BadLocationException e) {
131: // }
132: // }
133: // }
134: // // Complete the messages
135: // return null;
136: //
137: // }
138:
139: // static int findEndOfMethod(JTextComponent textComp, int startPos){
140: // try{
141: // int level = 0;
142: // BaseDocument doc = (BaseDocument)textComp.getDocument();
143: // for(int i = startPos; i<textComp.getDocument().getLength(); i++){
144: // char ch = doc.getChars(i, 1)[0];
145: // if (ch == ';') return -1;
146: // if (ch == '(') level++;
147: // if (ch == ')'){
148: // if (level == 0){
149: // return i+1;
150: // }else{
151: // level--;
152: // }
153: // }
154: // }
155: // return -1;
156: // } catch (BadLocationException e) {
157: // return -1;
158: // }
159: // }
160: }
|