use of org.apache.flex.compiler.definitions.IDefinition in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method findMXMLUnits.
private void findMXMLUnits(IMXMLTagData tagData, IDefinition definition, List<ISourceLocation> result) {
IDefinition tagDefinition = currentProject.resolveXMLNameToDefinition(tagData.getXMLName(), tagData.getMXMLDialect());
if (tagDefinition != null && definition == tagDefinition) {
result.add(tagData);
}
if (tagDefinition instanceof IClassDefinition) {
IClassDefinition classDefinition = (IClassDefinition) tagDefinition;
IMXMLTagAttributeData[] attributes = tagData.getAttributeDatas();
for (IMXMLTagAttributeData attributeData : attributes) {
IDefinition attributeDefinition = currentProject.resolveSpecifier(classDefinition, attributeData.getShortName());
if (attributeDefinition != null && definition == attributeDefinition) {
result.add(attributeData);
}
}
}
IMXMLTagData childTag = tagData.getFirstChild(true);
while (childTag != null) {
if (childTag.isCloseTag()) {
//only open tags matter
continue;
}
findMXMLUnits(childTag, definition, result);
childTag = childTag.getNextSibling(true);
}
}
use of org.apache.flex.compiler.definitions.IDefinition in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method autoCompleteScope.
private void autoCompleteScope(IScopedNode node, boolean typesOnly, CompletionList result) {
IScopedNode currentNode = node;
ASScope scope = (ASScope) node.getScope();
while (currentNode != null) {
IASScope currentScope = currentNode.getScope();
boolean isType = currentScope instanceof TypeScope;
boolean staticOnly = currentNode == node && isType;
if (currentScope instanceof TypeScope && !typesOnly) {
TypeScope typeScope = (TypeScope) currentScope;
addDefinitionsInTypeScopeToAutoComplete(typeScope, scope, true, true, false, null, result);
if (!staticOnly) {
addDefinitionsInTypeScopeToAutoCompleteActionScript(typeScope, scope, false, result);
}
} else {
for (IDefinition localDefinition : currentScope.getAllLocalDefinitions()) {
if (localDefinition.getBaseName().length() == 0) {
continue;
}
if (typesOnly && !(localDefinition instanceof ITypeDefinition)) {
continue;
}
if (!staticOnly || localDefinition.isStatic()) {
if (localDefinition instanceof ISetterDefinition) {
ISetterDefinition setter = (ISetterDefinition) localDefinition;
IGetterDefinition getter = setter.resolveGetter(currentProject);
if (getter != null) {
//it would add a duplicate entry
continue;
}
}
addDefinitionAutoCompleteActionScript(localDefinition, result);
}
}
}
currentNode = currentNode.getContainingScope();
}
}
use of org.apache.flex.compiler.definitions.IDefinition 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);
}
}
}
use of org.apache.flex.compiler.definitions.IDefinition in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method mxmlAttributeCompletion.
private CompletableFuture<CompletionList> mxmlAttributeCompletion(IMXMLTagData offsetTag, CompletionList result) {
List<CompletionItem> items = result.getItems();
IDefinition attributeDefinition = getDefinitionForMXMLTagAttribute(offsetTag, currentOffset, true);
if (attributeDefinition instanceof IVariableDefinition) {
IVariableDefinition variableDefinition = (IVariableDefinition) attributeDefinition;
if (variableDefinition.getTypeAsDisplayString().equals(IASLanguageConstants.Boolean)) {
CompletionItem falseItem = new CompletionItem();
falseItem.setKind(CompletionItemKind.Value);
falseItem.setLabel(IASLanguageConstants.FALSE);
items.add(falseItem);
CompletionItem trueItem = new CompletionItem();
trueItem.setKind(CompletionItemKind.Value);
trueItem.setLabel(IASLanguageConstants.TRUE);
items.add(trueItem);
return CompletableFuture.completedFuture(result);
}
}
return CompletableFuture.completedFuture(result);
}
use of org.apache.flex.compiler.definitions.IDefinition in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method classDefinitionToConstructor.
private IFunctionDefinition classDefinitionToConstructor(IClassDefinition definition) {
IASScope scope = definition.getContainedScope();
Collection<IDefinition> definitions = scope.getAllLocalDefinitions();
for (IDefinition localDefinition : definitions) {
if (localDefinition instanceof IFunctionDefinition) {
IFunctionDefinition functionDefinition = (IFunctionDefinition) localDefinition;
if (functionDefinition.isConstructor()) {
return functionDefinition;
}
}
}
return null;
}
Aggregations