
org.apache.royale.compiler.tree.as.IVariableNode Maven / Gradle / Ivy
Show all versions of compiler-common Show documentation
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.royale.compiler.tree.as;
import org.apache.royale.compiler.definitions.IVariableDefinition.VariableClassification;
/**
* An AST node representing a var
or const
declaration.
*
* The shape of this node is:
*
* IVariableNode
* IMetaTagsNode <-- getMetaTagsNode()
* INamespaceDecorationNode <-- getNamespaceNode()
* IKeywordNode <-- getKeywordNode()
* IExpressionNode <-- getNameExpressionNode()
* IExpressionNode <-- getVariableTypeNode()
* IExpressionNode <-- getAssignedValueNode()
* IVariableNode <-- ???
* IVariableNode
* ...
*
* For example,
*
* [Foo]
* [Bar]
* public var i:int = 1, j:int = 2;
*
* is represented as
*
* IVariableNode
* IMetaTagsNode
* IMetaTagNode "Foo"
* IMetaTagNode "Bar"
* INamespaceDecorationNode "public"
* IKeywordNode "var"
* IIdentifierNode "i"
* IIdentifierNode "int"
* INumericLiteralNode 1
* IVariableNode
* IIdentifierNode "j"
* IIdentifierNode "int"
* INumericLiteralNode 2
*
* If there is no metadata, the corresponding child node is not present.
*
* If there is no namespace, the corresponding child node is not present.
*
* If there is no type annotation, an implicit IIdentifierNode
* for "*"
is produced.
*
* If there is no initial value, the corresponding child node is not present.
*
* If multiple variables or constants are declared, then additional children
* of type IVariable
are present. These will not have metadata,
* or a namespace, or a keyword.
*/
public interface IVariableNode extends IDefinitionNode, IDocumentableDefinitionNode
{
/**
* Returns the type of this variable as it exist in source. If a variable
* does not have an explicit type, *
is returned
*
* @return type of variable as seen in source
*/
String getVariableType();
/**
* Returns the {@link IExpressionNode} that corresponds to the type node of
* this {@link IVariableNode}
*
* @return an {@link IExpressionNode} or null
*/
// TODO Should this return IIdentifierNode?
IExpressionNode getVariableTypeNode();
IExpressionNode getAssignedValueNode();
/**
* Get the classification for this variable (local, argument, class member,
* etc)
*
* @return variable classification
*/
VariableClassification getVariableClassification();
/**
* Returns if this variable is decorated with const
*
* @return true if const
exists
*/
boolean isConst();
/**
* Get the local end offset of this variable declaration. For single
* variables such as var i:int = 10; getEnd() will be returned For multiple
* variables such as var i:int = 10, j:int = 20, k:int = 30; we create a
* variable node for variable 'i'. Variable 'j' and 'k' are created as
* chained nodes with parent as variable node 'i' So, if we call this api
* for 'i', then the offset where the variable 'i' declaration ends will be
* returned. Note that in this case, getEnd() returns the end of the entire
* statement. This api is different from getEnd() only when variable node
* contains chained variables
*
* @return the local offset where the variable declaration ends
*/
int getDeclarationEnd();
}