Search in sources :

Example 1 with ImportDirective

use of net.jangaroo.jooc.ast.ImportDirective in project jangaroo-tools by CoreMedia.

the class DeclarationScope method lookupDeclaration.

@Override
public IdeDeclaration lookupDeclaration(Ide ide) {
    IdeDeclaration decl = null;
    if (ide instanceof QualifiedIde) {
        String qname = ide.getQualifiedNameStr();
        if (importsByQualifiedName.containsKey(qname)) {
            return resolveImport(importsByQualifiedName.get(qname));
        }
        if (ide.isQualifiedByThis()) {
            return getClassDeclaration().resolvePropertyDeclaration(ide.getName());
        }
        if (ide.isQualifiedBySuper()) {
            final IdeDeclaration superTypeDeclaration = getClassDeclaration().getSuperTypeDeclaration();
            return superTypeDeclaration == null ? null : superTypeDeclaration.resolvePropertyDeclaration(ide.getName());
        }
    } else {
        final String name = ide.getName();
        final List<ImportDirective> importsOfThisIde = importsByName.get(name);
        if (importsOfThisIde != null) {
            if (importsOfThisIde.size() > 1) {
                ambigousImport(ide, importsOfThisIde);
            }
            return resolveImport(importsOfThisIde.get(0));
        }
        decl = ides.get(ide.getName());
        if (decl == null && getDefiningNode() != null && getClassDeclaration() == getDefiningNode()) {
            decl = getClassDeclaration().resolvePropertyDeclaration(ide.getName());
            if (decl != null && !isInstanceScope && !decl.isStatic()) {
                decl = null;
            }
        }
    }
    return decl != null ? decl : super.lookupDeclaration(ide);
}
Also used : ImportDirective(net.jangaroo.jooc.ast.ImportDirective) QualifiedIde(net.jangaroo.jooc.ast.QualifiedIde) IdeDeclaration(net.jangaroo.jooc.ast.IdeDeclaration)

Example 2 with ImportDirective

use of net.jangaroo.jooc.ast.ImportDirective in project jangaroo-tools by CoreMedia.

the class DeclarationScope method ambigousImport.

private void ambigousImport(Ide ide, Collection<ImportDirective> importsOfThisIde) {
    boolean isFirst = true;
    StringBuilder msg = new StringBuilder();
    msg.append("Can not resolve a multiname reference unambiguously: ");
    for (ImportDirective importDirective : importsOfThisIde) {
        if (!isFirst) {
            msg.append(" and ");
        }
        isFirst = false;
        msg.append(importDirective.getQualifiedName());
        JooSymbol importedIdeSymbol = resolveImport(importDirective).getSymbol();
        msg.append("(").append(importedIdeSymbol.getFileName()).append(":").append(importedIdeSymbol.getLine()).append(",").append(importedIdeSymbol.getColumn());
    }
    msg.append(" are available.");
    throw new CompilerError(ide.getSymbol(), msg.toString());
}
Also used : ImportDirective(net.jangaroo.jooc.ast.ImportDirective)

Example 3 with ImportDirective

use of net.jangaroo.jooc.ast.ImportDirective in project jangaroo-tools by CoreMedia.

the class DeclarationScope method addImport.

@Override
public void addImport(final ImportDirective importDirective) {
    Ide ide = importDirective.getIde();
    String name = ide.getName();
    Ide packageIde = ide.getQualifier();
    String packageName = "";
    final CompilationUnit compilationUnit = getCompilationUnit();
    if (packageIde != null) {
        packageName = packageIde.getQualifiedNameStr();
        packages.add(packageName);
    }
    if (AS3Type.ANY.toString().equals(name)) {
        final List<String> packageIdes = compilationUnit.getCompiler().getPackageIdes(packageName);
        for (String typeToImport : packageIdes) {
            ImportDirective implicitImport = new ImportDirective(packageIde, typeToImport);
            implicitImport.scope(this);
        }
    } else {
        if (importsByName.containsKey(name)) {
            final List<ImportDirective> directiveList = importsByName.get(name);
            if (isImportAlreadyAdded(directiveList, importDirective)) {
                return;
            }
            directiveList.add(importDirective);
        } else {
            List<ImportDirective> list = new LinkedList<ImportDirective>();
            list.add(importDirective);
            importsByName.put(name, list);
        }
        if (ides.containsKey(name)) {
            // name clash with value ide - error according to adobe
            throw new CompilerError(importDirective.getIde().getSymbol(), "attempt to redefine identifier " + name + " by import");
        }
        // define the fully qualified name if not (might be the same string for top level imports):
        final String qualifiedName = ide.getQualifiedNameStr();
        importsByQualifiedName.put(qualifiedName, importDirective);
    }
}
Also used : CompilationUnit(net.jangaroo.jooc.ast.CompilationUnit) ImportDirective(net.jangaroo.jooc.ast.ImportDirective) QualifiedIde(net.jangaroo.jooc.ast.QualifiedIde) Ide(net.jangaroo.jooc.ast.Ide) LinkedList(java.util.LinkedList)

Aggregations

ImportDirective (net.jangaroo.jooc.ast.ImportDirective)3 QualifiedIde (net.jangaroo.jooc.ast.QualifiedIde)2 LinkedList (java.util.LinkedList)1 CompilationUnit (net.jangaroo.jooc.ast.CompilationUnit)1 Ide (net.jangaroo.jooc.ast.Ide)1 IdeDeclaration (net.jangaroo.jooc.ast.IdeDeclaration)1