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-2006 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: package org.netbeans.modules.php.editor.completion;
042:
043: import java.util.Set;
044:
045: import javax.swing.ImageIcon;
046:
047: import org.netbeans.modules.gsf.api.ElementKind;
048: import org.netbeans.modules.gsf.api.HtmlFormatter;
049: import org.netbeans.modules.gsf.api.Modifier;
050:
051: /**
052: * @author ads
053: *
054: */
055: class VariableItem extends CompletionItem {
056:
057: enum VarTypes {
058: PSEUDO("Pseudo-variable"), // NOI18N a pseudo-variable $this
059: GLOBAL("Global"), // NOI18N variable that declared with global keyword
060: STATIC("Static"), // NOI18N variable that declared with static keyword
061: LOCAL("Local"), // NOI18N local variable with scope ( inside file, method )
062: ATTRIBUTE("Attribute"), // NOI18N static attribute in class f.e. Clazz::$attr
063: /**
064: * Class Constant.
065: * @see {@link http://www.php.net/manual/en/language.oop5.constants.php}
066: */
067: CONSTANT("Constant"), // NOI18N
068: PREDEFINED("Superglobal"); // NOI18N one of predefined variables ( $_POST, ... )
069:
070: VarTypes(String type) {
071: myType = type;
072: }
073:
074: String getType() {
075: return myType;
076: }
077:
078: private final String myType;
079: }
080:
081: /**
082: * Constructs <code>VariableItem</code>.
083: * @param varName
084: * @param caretOffset
085: * @param type
086: * @param formatter
087: * @param isPredefined <code>true</code> if this <code>VariableItem</code>
088: * describes a predefined variable, otherwise - <code>true</code>, i.e. when
089: * it describes a user defined variable.
090: */
091: VariableItem(String varName, int caretOffset, VarTypes type,
092: HtmlFormatter formatter, boolean isPredefined) {
093: super (caretOffset, formatter);
094: myVariable = varName;
095: myType = type;
096: this .isPredefined = isPredefined;
097: }
098:
099: /* (non-Javadoc)
100: * @see org.netbeans.modules.gsf.api.CompletionProposal#getIcon()
101: */
102: public ImageIcon getIcon() {
103: // TODO Auto-generated method stub
104: return null;
105: }
106:
107: /* (non-Javadoc)
108: * @see org.netbeans.modules.gsf.api.CompletionProposal#getInsertPrefix()
109: */
110: public String getInsertPrefix() {
111: return myVariable;
112: }
113:
114: /* (non-Javadoc)
115: * @see org.netbeans.modules.gsf.api.CompletionProposal#getKind()
116: */
117: public ElementKind getKind() {
118: return ElementKind.VARIABLE;
119: }
120:
121: /* (non-Javadoc)
122: * @see org.netbeans.modules.gsf.api.CompletionProposal#getLhsHtml()
123: */
124: public String getLhsHtml() {
125: ElementKind kind = getKind();
126: HtmlFormatter formatter = getFormatter();
127: formatter.reset();
128: formatter.name(kind, true);
129: formatter.appendText(getName());
130: formatter.name(kind, false);
131:
132: return formatter.getText();
133:
134: }
135:
136: /* (non-Javadoc)
137: * @see org.netbeans.modules.gsf.api.CompletionProposal#getModifiers()
138: */
139: public Set<Modifier> getModifiers() {
140: // TODO Auto-generated method stub
141: return null;
142: }
143:
144: /* (non-Javadoc)
145: * @see org.netbeans.modules.gsf.api.CompletionProposal#getName()
146: */
147: public String getName() {
148: return myVariable;
149: }
150:
151: /* (non-Javadoc)
152: * @see org.netbeans.modules.gsf.api.CompletionProposal#getRhsHtml()
153: */
154: public String getRhsHtml() {
155: getFormatter().reset();
156:
157: getFormatter().appendText(myType.getType());
158: return getFormatter().getText();
159: }
160:
161: /* (non-Javadoc)
162: * @see org.netbeans.modules.gsf.api.CompletionProposal#isSmart()
163: */
164: public boolean isSmart() {
165: return !isPredefined;
166: }
167:
168: private String myVariable;
169:
170: private VarTypes myType;
171:
172: private boolean isPredefined;
173:
174: }
|