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.modelimpl.csm;
043:
044: import org.netbeans.modules.cnd.api.model.*;
045: import antlr.collections.AST;
046: import java.io.DataInput;
047: import java.io.DataOutput;
048: import java.io.IOException;
049: import org.netbeans.modules.cnd.modelimpl.parser.generated.CPPTokenTypes;
050: import org.netbeans.modules.cnd.modelimpl.repository.PersistentUtils;
051:
052: /**
053: * CsmFunction + CsmMember implementation
054: * @param T
055: * @author Vladimir Kvashin
056: */
057: public class MethodImpl<T> extends FunctionImpl<T> implements
058: CsmMethod<T> {
059:
060: private final CsmVisibility visibility;
061: private int _attributes = 0;
062: private static final int ABSTRACT = 1 << 1;
063: private static final int VIRTUAL = 1 << 2;
064:
065: public MethodImpl(AST ast, ClassImpl cls, CsmVisibility visibility) {
066: this (ast, cls, visibility, true);
067: }
068:
069: protected MethodImpl(AST ast, ClassImpl cls,
070: CsmVisibility visibility, boolean register) {
071: super (ast, cls.getContainingFile(), cls, false);
072: this .visibility = visibility;
073: //this(cls, visibility, AstUtil.findId(ast), 0, 0);
074: //setAst(ast);
075: for (AST token = ast.getFirstChild(); token != null; token = token
076: .getNextSibling()) {
077: switch (token.getType()) {
078: case CPPTokenTypes.LITERAL_static:
079: setStatic(true);
080: break;
081: case CPPTokenTypes.LITERAL_virtual:
082: setVirtual(true);
083: break;
084: }
085: }
086: if (register) {
087: registerInProject();
088: }
089: }
090:
091: public CsmClass getContainingClass() {
092: return (CsmClass) getScope();
093: }
094:
095: public CsmVisibility getVisibility() {
096: return visibility;
097: }
098:
099: public boolean isAbstract() {
100: return (_attributes & ABSTRACT) == ABSTRACT;
101: }
102:
103: public void setAbstract(boolean _abstract) {
104: if (_abstract) {
105: this ._attributes |= ABSTRACT;
106: } else {
107: this ._attributes &= ~ABSTRACT;
108: }
109: }
110:
111: private void setVirtual(boolean _virtual) {
112: if (_virtual) {
113: this ._attributes |= VIRTUAL;
114: } else {
115: this ._attributes &= ~VIRTUAL;
116: }
117: }
118:
119: public boolean isExplicit() {
120: //TODO: implement!!
121: return false;
122: }
123:
124: public boolean isVirtual() {
125: //TODO: implement!
126: // returns direct "virtual" keyword presence
127: return (_attributes & VIRTUAL) == VIRTUAL;
128: }
129:
130: @Override
131: public boolean isConst() {
132: return super .isConst();
133: }
134:
135: ////////////////////////////////////////////////////////////////////////////
136: // iml of SelfPersistent
137:
138: @Override
139: public void write(DataOutput output) throws IOException {
140: super .write(output);
141: PersistentUtils.writeVisibility(this .visibility, output);
142: output.writeInt(_attributes);
143: }
144:
145: public MethodImpl(DataInput input) throws IOException {
146: super(input);
147: this.visibility = PersistentUtils.readVisibility(input);
148: this._attributes = input.readInt();
149: }
150: }
|