/** * Determine if this node is a reference to a package * * @return true if this node is really a package reference. */ public boolean isPackageReference() { // Return true if we're somewhere that MXML doesn't require packages to be imported if (getTreatAsPackage()) return true; boolean isPackage = false; if (this.getBaseExpression() == null) { // Only check for packages if we don't have a base expression. // in a.b.c, 'a', 'a.b', or 'a.b.c' could be package names, but not 'c' or 'b.c' String ref = this.computeSimpleReference(); if (ref != null) { ASScope scope = getASScope(); if (scope.isPackageName(ref)) isPackage = true; } } return isPackage; }
/** * Check an ExpressionNodeBase's base expression (if any) * to determine if it's a dynamic expression, which * means we don't know much about its definition. * @param binding - the binding whose base node is to be checked. * @param project - an ICompilerProject for the current project. * @return true if node's base expression is dynamic. */ public static boolean hasDynamicBase(Binding binding, ICompilerProject project) { ExpressionNodeBase base = getBaseNode(binding); if (base != null && base.isDynamicExpression(project)) return true; // the JS version of XML is not currently dynamic so special case it here. if (base != null && base.getNodeID() == ASTNodeID.IdentifierID && IdentifierNode.isXMLish(base.resolveType(project), project)) return true; return false; }
@Override public IDefinition resolve(ICompilerProject project) { return rightOperandNode.resolve(project); }
public ExpressionNodeBase copyForInitializer(IScopedNode scopedNode) { ExpressionNodeBase newExpr = copy(); if (newExpr != null) { // If we copied the expression successfully, // set up all the parent pointers within the new subtree. if (scopedNode instanceof NodeBase) { NodeBase node = (NodeBase) scopedNode; newExpr.setParent(node); } newExpr.normalize(false); } return newExpr; }
/** * Get the type of a node's base expression as a string. * @param node the node whose base's type is desired. * @param project an ICompilerProject for the current project. * @return the type string, or null if none found. */ public static String getTypeOfBase(IASNode node, ICompilerProject project) { if (!(node instanceof ExpressionNodeBase)) return null; ExpressionNodeBase base = ((ExpressionNodeBase)node).getBaseExpression(); if (base == null) return null; IDefinition def = base.resolve(project); if (def == null) return null; return def.getTypeAsDisplayString(); }
final IdentifierNode idNode = new IdentifierNode((ASToken)id); n = transformToNSAccessExpression(nsNode, (ASToken) op, idNode); n = n.copyForInitializer(null); n.setSourcePath(nsNode.getSourcePath()); n.setLine(nsNode.getLine()); n.setColumn(nsNode.getColumn()); n.setEndLine(idNode.getEndLine()); n.setEndColumn(idNode.getEndColumn()); n.setStart(nsNode.getStart()); n.setEnd(idNode.getEnd());
if(t.getStart() == -1) t.startAfter(colon); if (t.getEnd() == -1) t.endAfter(colon);
/** * Called when the parser enters a type application expression. It validates * the "collection expression" of the type application expression. It must * be either a {@code MemberAccessExpressionNode} or an * {@code IdentifierNode}. * * @param collectionExpression The expression node on the left-hand side of * {@code .< >}. */ protected final void enterTypeApplication(final ExpressionNodeBase collectionExpression) { if (collectionExpression == null || collectionExpression.getNodeID() == ASTNodeID.IdentifierID || collectionExpression.getNodeID() == ASTNodeID.FunctionCallID || collectionExpression.getNodeID() == ASTNodeID.TypedExpressionID || collectionExpression instanceof MemberAccessExpressionNode) { return; } else { final ICompilerProblem problem = new InvalidTypeProblem( LT(1), collectionExpression.getNodeID().getParaphrase()); addProblem(problem); } }
/** * Resolve a dotted name, e.g., foo.bar.baz */ Binding dottedName(IASNode iNode, String qualifiers, String base_name) { if ( iNode instanceof IdentifierNode ) { return currentScope.resolveName((IdentifierNode)iNode); } else if ( iNode instanceof ExpressionNodeBase ) { ExpressionNodeBase expr = (ExpressionNodeBase) iNode; Name n = expr.getMName(currentScope.getProject()); if ( n == null ) { currentScope.addProblem(new CodegenInternalProblem(iNode, "Unable to resove member name: " + iNode.toString())); n = new Name(CONSTANT_Qname, new Nsset(new Namespace(CONSTANT_PackageNs, qualifiers)), base_name); } return currentScope.getBinding(iNode, n, expr.resolve(currentScope.getProject())); } //else currentScope.addProblem(new CodegenInternalProblem(iNode, "Unable to resove to a dotted name: " + iNode.toString())); return new Binding(iNode, new Name(CONSTANT_Qname, new Nsset(new Namespace(CONSTANT_PackageNs, qualifiers)), base_name), null); }
nsRef = NamespaceDefinition.createNamespaceReference( getASScope(), getName(), w.getPackageNamespaceDefinitionCache().get(baseExpr.computeSimpleReference(), false)); break; nsRef = NamespaceDefinition.createNamespaceReference(getASScope(), getName(), qualExpr.computeNamespaceReference()); break; IReference base = baseExpr.computeTypeReference(); nsRef = NamespaceDefinition.createNamespaceReference(getASScope(), getName(), null, base); break;
/**' * Copy constructor. * * @param other The node to copy. */ protected BaseStatementExpressionNode(BaseStatementExpressionNode other) { super(other); this.expressionNode = other.expressionNode.copy(); }
InterfaceDefinition buildDefinition() { String definitionName = nameNode.computeSimpleReference(); InterfaceDefinition definition = new InterfaceDefinition(definitionName); definition.setNode(this); fillInNamespaceAndModifiers(definition); fillInMetadata(definition); // Set the interfaces that this interface extends. if (baseInterfacesNode != null) { int n = baseInterfacesNode.getChildCount(); IReference[] baseInterfaces = new IReference[n]; for (int i = 0; i < n; i++) { IASNode child = baseInterfacesNode.getChild(i); if (child instanceof ExpressionNodeBase) baseInterfaces[i] = ((ExpressionNodeBase)child).computeTypeReference(); } definition.setExtendedInterfaceReferences(baseInterfaces); } return definition; } }
/** * Get an ExpressionNodeBase's base node. * @return the node's base expression, or null * if the Binding does not wrap an ExpressionNodeBase. */ public static ExpressionNodeBase getBaseNode(Binding binding) { if ( binding.getNode() instanceof ExpressionNodeBase ) return ((ExpressionNodeBase)binding.getNode()).getBaseExpression(); else return null; }
@Override IReference computeTypeReference() { return rightOperandNode.computeTypeReference(); }
/** * Build the definitions for a bindable variable that needs a generated * getter/setter. * * @return An Array with all of the definitions built for this Node. */ DefinitionBase[] buildBindableDefinitions(ASScope containingScope) { String definitionName = nameNode.computeSimpleReference(); DefinitionBase[] definitions = new DefinitionBase[2]; definitions[0] = buildBindableGetter(definitionName); definitions[1] = buildBindableSetter(definitionName, containingScope, definitions[0].getTypeReference()); return definitions; }
@Override public INamespaceReference computeNamespaceReference() { return rightOperandNode.computeNamespaceReference(); }
openT = LT(1); match(TOKEN_BLOCK_OPEN); n.startBefore(openT); n.endAfter(closeT);
@Override protected void analyze(EnumSet<PostProcessStep> set, ASScope scope, Collection<ICompilerProblem> problems) { EnumSet<PostProcessStep> stepsToRunOnChildren; if (set.contains(PostProcessStep.RECONNECT_DEFINITIONS)) { stepsToRunOnChildren = EnumSet.copyOf(set); stepsToRunOnChildren.remove(PostProcessStep.RECONNECT_DEFINITIONS); stepsToRunOnChildren.add(PostProcessStep.POPULATE_SCOPE); } else { stepsToRunOnChildren = set; } super.analyze(stepsToRunOnChildren, scope, problems); }
/** * Matches a runtime attribute name. * * foo["name"] */ public final ExpressionNodeBase runtimeName() throws RecognitionException, TokenStreamException { ExpressionNodeBase n; Token closeT = null; ExpressionNodeBase e = null; n = null; try { // for error handling match(TOKEN_SQUARE_OPEN); e=expression(); closeT = LT(1); match(TOKEN_SQUARE_CLOSE); n = new RuntimeNameExpressionNode(e); n.endAfter(closeT); } catch (RecognitionException ex) { handleParsingError(ex); } return n; }
final IdentifierNode idNode = new IdentifierNode((ASToken)id); n = transformToNSAccessExpression(nsNode, (ASToken) op, idNode); n = n.copyForInitializer(null); n.setSourcePath(nsNode.getSourcePath()); n.setLine(nsNode.getLine()); n.setColumn(nsNode.getColumn()); n.setEndLine(idNode.getEndLine()); n.setEndColumn(idNode.getEndColumn()); n.setStart(nsNode.getStart()); n.setEnd(idNode.getEnd());