2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
41
package org.netbeans.modules.php.model.impl;
43
import java.util.LinkedList;
44
import java.util.List;
46
import org.netbeans.api.languages.ASTItem;
47
import org.netbeans.api.languages.ASTNode;
48
import org.netbeans.api.lexer.TokenSequence;
49
import org.netbeans.modules.php.model.CallExpression;
50
import org.netbeans.modules.php.model.ClassMemberExpression;
51
import org.netbeans.modules.php.model.Expression;
52
import org.netbeans.modules.php.model.IdentifierExpression;
53
import org.netbeans.modules.php.model.PhpModelVisitor;
54
import org.netbeans.modules.php.model.SourceElement;
55
import org.netbeans.modules.php.model.impl.factory.CallExpressionBuilder;
56
import org.netbeans.modules.php.model.impl.factory.CallExpressionFactory;
57
import org.netbeans.modules.php.model.impl.factory.ClassMemberBuilder;
58
import org.netbeans.modules.php.model.impl.factory.ExpressionFactory;
59
import org.netbeans.modules.php.model.impl.factory.IdentifierBuilder;
66
public class ClassMemberExpressionImpl extends SourceElementImpl implements
70
public ClassMemberExpressionImpl( SourceElement parent, ASTNode node,
71
ASTNode realNode, ASTNode memberAccessNode ,TokenSequence sequence )
73
super(parent, node, realNode, sequence);
74
myMemberNode = memberAccessNode;
78
* @see org.netbeans.modules.php.model.ClassMemberExpression#getExpression()
80
public Expression getExpression() {
81
List<Expression> children = getChildren( Expression.class );
82
for (Expression expression : children) {
84
* No need in this check.
85
* If expression is complex ( owner identidier is itself
86
* member access ) then owner has the same node as this class
87
* ( and this is MemberAccessExpression type ).
88
* If expression is simple then owner has IdentifierExpression
89
* type. In both cases check below failed.
90
if ( expression == getOwnerIdentifier() ){
93
assert expression instanceof SourceElementImpl;
94
SourceElementImpl impl = (SourceElementImpl) expression;
95
String nt = impl.getNarrowNode().getNT();
96
if ( nt.equals( CallExpressionBuilder.MEMBER_EXPRESSION )) {
104
* @see org.netbeans.modules.php.model.MemberExpression#getCallExpression()
106
public CallExpression getCallExpression() {
107
List<CallExpression> children = getChildren( CallExpression.class );
108
for ( CallExpression expression : children ){
109
assert expression instanceof SourceElementImpl;
110
SourceElementImpl impl = (SourceElementImpl) expression;
111
if ( impl.getNode() == getNode() ) {
112
return (CallExpression)impl;
119
* @see org.netbeans.modules.php.model.MemberExpression#getOwnerIdentifier()
121
public IdentifierExpression getOwnerIdentifier() {
122
if ( getCallExpression() != null ) {
125
return getChild( IdentifierExpression.class );
129
* @see org.netbeans.modules.php.model.SourceElement#getElementType()
131
public Class<? extends SourceElement> getElementType() {
132
return ClassMemberExpression.class;
136
* @see org.netbeans.modules.php.model.Acceptor#accept(org.netbeans.modules.php.model.PhpModelVisitor)
138
public void accept( PhpModelVisitor visitor ) {
139
visitor.visit( this );
143
protected List<SourceElement> createChildrenList()
145
ASTNode node = getNarrowNode();
146
List<ASTItem> nodes = node.getChildren();
147
ASTNode before = null;
148
ASTNode beforeBefore = null;
149
for (ASTItem item : nodes) {
150
if ( !(item instanceof ASTNode ) ){
153
ASTNode child = (ASTNode) item;
154
if ( child != getMemberNode() ) {
155
beforeBefore = before;
163
SourceElement memberExpression =
164
ClassMemberBuilder.getInstance().build( this , getMemberNode() ,
165
getMemberNode(), getTokenSequence() );
167
List<SourceElement> children = new LinkedList<SourceElement>();
168
assert before != null;
169
if ( before.getNT().equals( CallExpressionFactory.IDENTIFIER )) {
170
// this is the case : $a[ $i ];
171
SourceElement sourceElement = IdentifierBuilder.getInstance().
172
build( this, before , before , getTokenSequence() );
173
children.add( sourceElement );
176
assert before.getNT().equals( CallExpressionBuilder.MEMBER) ;
177
if ( before.getNode( CallExpressionBuilder.ARGS) != null ) {
178
SourceElement callExpression = null;
179
assert beforeBefore!= null;
180
if ( beforeBefore.getNT().equals(CallExpressionBuilder.MEMBER ) ) {
181
callExpression = new CallMemberExpressionImpl(
182
this , getNode() , getNarrowNode() , beforeBefore,
183
before , getTokenSequence());
186
assert beforeBefore.getNT().equals(
187
CallExpressionFactory.IDENTIFIER );
188
callExpression = new CallExpressionImpl( this , getNode() ,
189
getNarrowNode() , before , getTokenSequence() );
191
children.add( callExpression );
193
else if ( before.getNode( ExpressionFactory.EXPRESSION) != null ) {
194
SourceElement arrayMember = new ArrayMemberExpressionImpl( this ,
195
getNode() , getNarrowNode() , before , getTokenSequence() );
196
children.add( arrayMember );
198
else if ( before.getNode( CallExpressionBuilder.MEMBER_EXPRESSION)
202
* 'before' could be method name or attribute name
204
SourceElement classMember = new ClassMemberExpressionImpl( this ,
205
getNode() , getNarrowNode() , before , getTokenSequence() );
206
children.add( classMember );
213
children.add( memberExpression );
217
private ASTNode getMemberNode() {
221
private ASTNode myMemberNode;