Search in sources :

Example 1 with IInterfaceDefinition

use of org.apache.flex.compiler.definitions.IInterfaceDefinition in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method collectInterfaceNamespaces.

private void collectInterfaceNamespaces(IInterfaceDefinition interfaceDefinition, Set<INamespaceDefinition> namespaceSet) {
    TypeScope typeScope = (TypeScope) interfaceDefinition.getContainedScope();
    namespaceSet.addAll(typeScope.getNamespaceSet(currentProject));
    IInterfaceDefinition[] interfaceDefinitions = interfaceDefinition.resolveExtendedInterfaces(currentProject);
    for (IInterfaceDefinition extendedInterface : interfaceDefinitions) {
        collectInterfaceNamespaces(extendedInterface, namespaceSet);
    }
}
Also used : IInterfaceDefinition(org.apache.flex.compiler.definitions.IInterfaceDefinition) TypeScope(org.apache.flex.compiler.internal.scopes.TypeScope)

Example 2 with IInterfaceDefinition

use of org.apache.flex.compiler.definitions.IInterfaceDefinition in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method autoCompleteImport.

private void autoCompleteImport(String importName, CompletionList result) {
    List<CompletionItem> items = result.getItems();
    for (ICompilationUnit unit : compilationUnits) {
        if (unit == null) {
            continue;
        }
        Collection<IDefinition> definitions = null;
        try {
            definitions = unit.getFileScopeRequest().get().getExternallyVisibleDefinitions();
        } catch (Exception e) {
            //safe to ignore
            continue;
        }
        for (IDefinition definition : definitions) {
            if (definition instanceof ITypeDefinition) {
                String qualifiedName = definition.getQualifiedName();
                if (qualifiedName.equals(definition.getBaseName())) {
                    //this definition is top-level. no import required.
                    continue;
                }
                if (qualifiedName.startsWith(importName)) {
                    int index = importName.lastIndexOf(".");
                    if (index != -1) {
                        qualifiedName = qualifiedName.substring(index + 1);
                    }
                    index = qualifiedName.indexOf(".");
                    if (index > 0) {
                        qualifiedName = qualifiedName.substring(0, index);
                    }
                    CompletionItem item = new CompletionItem();
                    item.setLabel(qualifiedName);
                    if (definition.getBaseName().equals(qualifiedName)) {
                        ITypeDefinition typeDefinition = (ITypeDefinition) definition;
                        if (typeDefinition instanceof IInterfaceDefinition) {
                            item.setKind(CompletionItemKind.Interface);
                        } else if (typeDefinition instanceof IClassDefinition) {
                            item.setKind(CompletionItemKind.Class);
                        } else {
                            item.setKind(CompletionItemKind.Text);
                        }
                    } else {
                        item.setKind(CompletionItemKind.Text);
                    }
                    if (!items.contains(item)) {
                        items.add(item);
                    }
                }
            }
        }
    }
}
Also used : ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) IInterfaceDefinition(org.apache.flex.compiler.definitions.IInterfaceDefinition) IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) CompletionItem(org.eclipse.lsp4j.CompletionItem) ITypeDefinition(org.apache.flex.compiler.definitions.ITypeDefinition) IDefinition(org.apache.flex.compiler.definitions.IDefinition) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with IInterfaceDefinition

use of org.apache.flex.compiler.definitions.IInterfaceDefinition in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method definitionToSymbol.

private SymbolInformation definitionToSymbol(IDefinition definition) {
    SymbolInformation symbol = new SymbolInformation();
    if (definition instanceof IClassDefinition) {
        symbol.setKind(SymbolKind.Class);
    } else if (definition instanceof IInterfaceDefinition) {
        symbol.setKind(SymbolKind.Interface);
    } else if (definition instanceof IFunctionDefinition) {
        IFunctionDefinition functionDefinition = (IFunctionDefinition) definition;
        if (functionDefinition.isConstructor()) {
            symbol.setKind(SymbolKind.Constructor);
        } else {
            symbol.setKind(SymbolKind.Function);
        }
    } else if (definition instanceof IFunctionDefinition) {
        symbol.setKind(SymbolKind.Function);
    } else if (definition instanceof IConstantDefinition) {
        symbol.setKind(SymbolKind.Constant);
    } else {
        symbol.setKind(SymbolKind.Variable);
    }
    symbol.setName(definition.getQualifiedName());
    Location location = new Location();
    String sourcePath = definition.getSourcePath();
    if (sourcePath == null) {
        //I'm not sure why getSourcePath() can sometimes return null, but
        //getContainingFilePath() seems to work as a fallback -JT
        sourcePath = definition.getContainingFilePath();
    }
    Path definitionPath = Paths.get(sourcePath);
    location.setUri(definitionPath.toUri().toString());
    Position start = new Position();
    Position end = new Position();
    //getLine() and getColumn() may include things like metadata, so it
    //makes more sense to jump to where the definition name starts
    int line = definition.getNameLine();
    int column = definition.getNameColumn();
    if (line < 0 || column < 0) {
        //this is not ideal, but MXML variable definitions may not have a
        //node associated with them, so we need to figure this out from the
        //offset instead of a pre-calculated line and column -JT
        String code = sourceByPath.get(Paths.get(sourcePath));
        offsetToLineAndCharacter(new StringReader(code), definition.getNameStart(), start);
        end.setLine(start.getLine());
        end.setCharacter(start.getCharacter());
    } else {
        start.setLine(line);
        start.setCharacter(column);
        end.setLine(line);
        end.setCharacter(column);
    }
    Range range = new Range();
    range.setStart(start);
    range.setEnd(end);
    location.setRange(range);
    symbol.setLocation(location);
    return symbol;
}
Also used : Path(java.nio.file.Path) IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) IInterfaceDefinition(org.apache.flex.compiler.definitions.IInterfaceDefinition) IFunctionDefinition(org.apache.flex.compiler.definitions.IFunctionDefinition) Position(org.eclipse.lsp4j.Position) StringReader(java.io.StringReader) Range(org.eclipse.lsp4j.Range) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) IConstantDefinition(org.apache.flex.compiler.definitions.IConstantDefinition) Location(org.eclipse.lsp4j.Location) ISourceLocation(org.apache.flex.compiler.common.ISourceLocation)

Example 4 with IInterfaceDefinition

use of org.apache.flex.compiler.definitions.IInterfaceDefinition in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method addDefinitionsInTypeScopeToAutoComplete.

private void addDefinitionsInTypeScopeToAutoComplete(TypeScope typeScope, ASScope otherScope, boolean isStatic, boolean includeSuperStatics, boolean forMXML, String prefix, CompletionList result) {
    IMetaTag[] excludeMetaTags = typeScope.getDefinition().getMetaTagsByName(IMetaAttributeConstants.ATTRIBUTE_EXCLUDE);
    ArrayList<IDefinition> memberAccessDefinitions = new ArrayList<>();
    Set<INamespaceDefinition> namespaceSet = otherScope.getNamespaceSet(currentProject);
    if (typeScope.getContainingDefinition() instanceof IInterfaceDefinition) {
        //interfaces have a special namespace that isn't actually the same
        //as public, but should be treated the same way
        IInterfaceDefinition interfaceDefinition = (IInterfaceDefinition) typeScope.getContainingDefinition();
        collectInterfaceNamespaces(interfaceDefinition, namespaceSet);
    }
    IClassDefinition otherContainingClass = otherScope.getContainingClass();
    if (otherContainingClass != null) {
        IClassDefinition classDefinition = typeScope.getContainingClass();
        if (classDefinition != null) {
            boolean isSuperClass = Arrays.asList(otherContainingClass.resolveAncestry(currentProject)).contains(classDefinition);
            if (isSuperClass) {
                //namespaces from the super classes
                do {
                    namespaceSet.add(classDefinition.getProtectedNamespaceReference());
                    classDefinition = classDefinition.resolveBaseClass(currentProject);
                } while (classDefinition instanceof IClassDefinition);
            }
        }
    }
    typeScope.getAllPropertiesForMemberAccess(currentProject, memberAccessDefinitions, namespaceSet);
    for (IDefinition localDefinition : memberAccessDefinitions) {
        if (localDefinition.isOverride()) {
            //overrides would add unnecessary duplicates to the list
            continue;
        }
        if (excludeMetaTags != null && excludeMetaTags.length > 0) {
            boolean exclude = false;
            for (IMetaTag excludeMetaTag : excludeMetaTags) {
                String excludeName = excludeMetaTag.getAttributeValue(IMetaAttributeConstants.NAME_EXCLUDE_NAME);
                if (excludeName.equals(localDefinition.getBaseName())) {
                    exclude = true;
                    break;
                }
            }
            if (exclude) {
                continue;
            }
        }
        //there are some things that we need to skip in MXML
        if (forMXML) {
            if (localDefinition instanceof IGetterDefinition) {
                //no getters because we can only set
                continue;
            } else if (localDefinition instanceof IFunctionDefinition && !(localDefinition instanceof ISetterDefinition)) {
                //no calling functions, unless they're setters
                continue;
            }
        } else //actionscript
        {
            if (localDefinition instanceof ISetterDefinition) {
                ISetterDefinition setter = (ISetterDefinition) localDefinition;
                IGetterDefinition getter = setter.resolveGetter(currentProject);
                if (getter != null) {
                    //would add a duplicate entry
                    continue;
                }
            }
        }
        if (isStatic) {
            if (!localDefinition.isStatic()) {
                //static, skip it
                continue;
            }
            if (!includeSuperStatics && localDefinition.getParent() != typeScope.getContainingDefinition()) {
                //aren't available with member access
                continue;
            }
        }
        if (!isStatic && localDefinition.isStatic()) {
            //skip it!
            continue;
        }
        if (forMXML) {
            addDefinitionAutoCompleteMXML(localDefinition, prefix, null, result);
        } else //actionscript
        {
            addDefinitionAutoCompleteActionScript(localDefinition, result);
        }
    }
}
Also used : IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) ArrayList(java.util.ArrayList) ISetterDefinition(org.apache.flex.compiler.definitions.ISetterDefinition) IDefinition(org.apache.flex.compiler.definitions.IDefinition) IInterfaceDefinition(org.apache.flex.compiler.definitions.IInterfaceDefinition) IMetaTag(org.apache.flex.compiler.definitions.metadata.IMetaTag) IFunctionDefinition(org.apache.flex.compiler.definitions.IFunctionDefinition) INamespaceDefinition(org.apache.flex.compiler.definitions.INamespaceDefinition) IGetterDefinition(org.apache.flex.compiler.definitions.IGetterDefinition)

Example 5 with IInterfaceDefinition

use of org.apache.flex.compiler.definitions.IInterfaceDefinition in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method getDefinitionDetail.

private String getDefinitionDetail(IDefinition definition) {
    StringBuilder detailBuilder = new StringBuilder();
    if (definition instanceof IClassDefinition) {
        IClassDefinition classDefinition = (IClassDefinition) definition;
        if (classDefinition.isDynamic()) {
            detailBuilder.append(IASKeywordConstants.DYNAMIC);
            detailBuilder.append(" ");
        }
        detailBuilder.append(IASKeywordConstants.CLASS);
        detailBuilder.append(" ");
        if (classDefinition.getPackageName().startsWith(PACKAGE_NAME_NO_IMPORT)) {
            //classes like __AS3__.vec.Vector should not include the
            //package name
            detailBuilder.append(classDefinition.getBaseName());
        } else {
            detailBuilder.append(classDefinition.getQualifiedName());
        }
        IClassDefinition baseClassDefinition = classDefinition.resolveBaseClass(currentProject);
        if (baseClassDefinition != null && !baseClassDefinition.getQualifiedName().equals(IASLanguageConstants.Object)) {
            detailBuilder.append(" ");
            detailBuilder.append(IASKeywordConstants.EXTENDS);
            detailBuilder.append(" ");
            detailBuilder.append(baseClassDefinition.getBaseName());
        }
        IInterfaceDefinition[] interfaceDefinitions = classDefinition.resolveImplementedInterfaces(currentProject);
        if (interfaceDefinitions.length > 0) {
            detailBuilder.append(" ");
            detailBuilder.append(IASKeywordConstants.IMPLEMENTS);
            detailBuilder.append(" ");
            appendInterfaceNamesToDetail(detailBuilder, interfaceDefinitions);
        }
    } else if (definition instanceof IInterfaceDefinition) {
        IInterfaceDefinition interfaceDefinition = (IInterfaceDefinition) definition;
        detailBuilder.append(IASKeywordConstants.INTERFACE);
        detailBuilder.append(" ");
        detailBuilder.append(interfaceDefinition.getQualifiedName());
        IInterfaceDefinition[] interfaceDefinitions = interfaceDefinition.resolveExtendedInterfaces(currentProject);
        if (interfaceDefinitions.length > 0) {
            detailBuilder.append(" ");
            detailBuilder.append(IASKeywordConstants.EXTENDS);
            detailBuilder.append(" ");
            appendInterfaceNamesToDetail(detailBuilder, interfaceDefinitions);
        }
    } else if (definition instanceof IVariableDefinition) {
        IVariableDefinition variableDefinition = (IVariableDefinition) definition;
        IDefinition parentDefinition = variableDefinition.getParent();
        if (parentDefinition instanceof ITypeDefinition) {
            //IVariableDefinition and IFunctionDefinition 
            if (variableDefinition instanceof IAccessorDefinition) {
                detailBuilder.append("(property) ");
            } else if (variableDefinition instanceof IConstantDefinition) {
                detailBuilder.append("(const) ");
            } else {
                detailBuilder.append("(variable) ");
            }
            detailBuilder.append(parentDefinition.getQualifiedName());
            detailBuilder.append(".");
        } else if (parentDefinition instanceof IFunctionDefinition) {
            if (variableDefinition instanceof IParameterDefinition) {
                detailBuilder.append("(parameter) ");
            } else {
                detailBuilder.append("(local ");
                if (variableDefinition instanceof IConstantDefinition) {
                    detailBuilder.append("const) ");
                } else {
                    detailBuilder.append("var) ");
                }
            }
        } else {
            if (variableDefinition instanceof IConstantDefinition) {
                detailBuilder.append(IASKeywordConstants.CONST);
            } else {
                detailBuilder.append(IASKeywordConstants.VAR);
            }
            detailBuilder.append(" ");
        }
        detailBuilder.append(variableDefinition.getBaseName());
        detailBuilder.append(":");
        detailBuilder.append(variableDefinition.getTypeAsDisplayString());
    } else if (definition instanceof IFunctionDefinition) {
        IFunctionDefinition functionDefinition = (IFunctionDefinition) definition;
        IDefinition parentDefinition = functionDefinition.getParent();
        if (parentDefinition instanceof ITypeDefinition) {
            if (functionDefinition.isConstructor()) {
                detailBuilder.append("(constructor) ");
            } else {
                detailBuilder.append("(method) ");
            }
            detailBuilder.append(parentDefinition.getQualifiedName());
            detailBuilder.append(".");
        } else if (parentDefinition instanceof IFunctionDefinition) {
            detailBuilder.append("(local function) ");
        } else {
            detailBuilder.append(IASKeywordConstants.FUNCTION);
            detailBuilder.append(" ");
        }
        detailBuilder.append(getSignatureLabel(functionDefinition));
    } else if (definition instanceof IEventDefinition) {
        IEventDefinition eventDefinition = (IEventDefinition) definition;
        detailBuilder.append("(event) ");
        detailBuilder.append("[");
        detailBuilder.append(IMetaAttributeConstants.ATTRIBUTE_EVENT);
        detailBuilder.append("(");
        detailBuilder.append(IMetaAttributeConstants.NAME_EVENT_NAME);
        detailBuilder.append("=");
        detailBuilder.append("\"");
        detailBuilder.append(eventDefinition.getBaseName());
        detailBuilder.append("\"");
        detailBuilder.append(",");
        detailBuilder.append(IMetaAttributeConstants.NAME_EVENT_TYPE);
        detailBuilder.append("=");
        detailBuilder.append("\"");
        detailBuilder.append(eventDefinition.getTypeAsDisplayString());
        detailBuilder.append("\"");
        detailBuilder.append(")");
        detailBuilder.append("]");
    } else if (definition instanceof IStyleDefinition) {
        IStyleDefinition styleDefinition = (IStyleDefinition) definition;
        detailBuilder.append("(style) ");
        detailBuilder.append("[");
        detailBuilder.append(IMetaAttributeConstants.ATTRIBUTE_STYLE);
        detailBuilder.append("(");
        detailBuilder.append(IMetaAttributeConstants.NAME_STYLE_NAME);
        detailBuilder.append("=");
        detailBuilder.append("\"");
        detailBuilder.append(styleDefinition.getBaseName());
        detailBuilder.append("\"");
        detailBuilder.append(",");
        detailBuilder.append(IMetaAttributeConstants.NAME_STYLE_TYPE);
        detailBuilder.append("=");
        detailBuilder.append("\"");
        detailBuilder.append(styleDefinition.getTypeAsDisplayString());
        detailBuilder.append("\"");
        detailBuilder.append(")");
        detailBuilder.append("]");
    }
    return detailBuilder.toString();
}
Also used : IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) IAccessorDefinition(org.apache.flex.compiler.definitions.IAccessorDefinition) ITypeDefinition(org.apache.flex.compiler.definitions.ITypeDefinition) IStyleDefinition(org.apache.flex.compiler.definitions.IStyleDefinition) IDefinition(org.apache.flex.compiler.definitions.IDefinition) IInterfaceDefinition(org.apache.flex.compiler.definitions.IInterfaceDefinition) IFunctionDefinition(org.apache.flex.compiler.definitions.IFunctionDefinition) IVariableDefinition(org.apache.flex.compiler.definitions.IVariableDefinition) IParameterDefinition(org.apache.flex.compiler.definitions.IParameterDefinition) IEventDefinition(org.apache.flex.compiler.definitions.IEventDefinition) IConstantDefinition(org.apache.flex.compiler.definitions.IConstantDefinition)

Aggregations

IInterfaceDefinition (org.apache.flex.compiler.definitions.IInterfaceDefinition)6 IClassDefinition (org.apache.flex.compiler.definitions.IClassDefinition)4 IDefinition (org.apache.flex.compiler.definitions.IDefinition)3 IFunctionDefinition (org.apache.flex.compiler.definitions.IFunctionDefinition)3 IConstantDefinition (org.apache.flex.compiler.definitions.IConstantDefinition)2 ITypeDefinition (org.apache.flex.compiler.definitions.ITypeDefinition)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 ISourceLocation (org.apache.flex.compiler.common.ISourceLocation)1 IAccessorDefinition (org.apache.flex.compiler.definitions.IAccessorDefinition)1 IEventDefinition (org.apache.flex.compiler.definitions.IEventDefinition)1 IGetterDefinition (org.apache.flex.compiler.definitions.IGetterDefinition)1 INamespaceDefinition (org.apache.flex.compiler.definitions.INamespaceDefinition)1 IParameterDefinition (org.apache.flex.compiler.definitions.IParameterDefinition)1 ISetterDefinition (org.apache.flex.compiler.definitions.ISetterDefinition)1 IStyleDefinition (org.apache.flex.compiler.definitions.IStyleDefinition)1