use of org.apache.flex.compiler.definitions.IConstantDefinition 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;
}
use of org.apache.flex.compiler.definitions.IConstantDefinition 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();
}
Aggregations