Skip to content

Commit

Permalink
do not create shortname for non-imported classes
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Nov 17, 2020
1 parent 46a1538 commit 77cbfd5
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ const parameterIndexToLetterMap = {
* @param {string} name
* @returns {string}
*/
const getDisplayName = (name) => {
const displayName = name.split('.').pop() || name;
const getDisplayName = (name, imported) => {
let displayName = name;

// If imported === true, we assume it is a Java class and need the short name
if (imported) {
displayName = name.split('.').pop() || name;
}

return displayName.replace('$', '.');
};

Expand Down Expand Up @@ -241,13 +247,13 @@ const getPainlessClassToAutocomplete = (painlessClass) => {
];
};

const getPainlessConstructorToAutocomplete = (constructors) => {
const getPainlessConstructorToAutocomplete = (constructors, imported) => {
if (constructors.length) {
// There are sometimes two constructor definitions if a parameter is accepted
// We only care about getting the constructor name for now, so we can access the first one in the array
const { declaring } = constructors[0];
// The constructor name is sometimes prefixed by the Java package and needs to be removed
const constructorName = getDisplayName(declaring);
const constructorName = getDisplayName(declaring, imported);

return {
label: constructorName,
Expand Down Expand Up @@ -276,9 +282,10 @@ const createAutocompleteDefinitions = (painlessClasses) => {
static_methods: staticMethods,
methods,
constructors,
imported,
}) => {
// The name is often prefixed by the Java package (e.g., Java.lang.Math) and needs to be removed
const displayName = getDisplayName(name);
const displayName = getDisplayName(name, imported);
const isType = getPrimitives(painlessClasses).includes(name);

const properties = getPainlessClassToAutocomplete({
Expand All @@ -288,7 +295,7 @@ const createAutocompleteDefinitions = (painlessClasses) => {
methods,
});

const constructorDefinition = getPainlessConstructorToAutocomplete(constructors);
const constructorDefinition = getPainlessConstructorToAutocomplete(constructors, imported);

return {
label: displayName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42501,10 +42501,10 @@
]
},
{
"label": "BooleanFieldScript",
"label": "org.elasticsearch.xpack.runtimefields.mapper.BooleanFieldScript",
"kind": "class",
"documentation": "Class: BooleanFieldScript",
"insertText": "BooleanFieldScript",
"documentation": "Class: org.elasticsearch.xpack.runtimefields.mapper.BooleanFieldScript",
"insertText": "org.elasticsearch.xpack.runtimefields.mapper.BooleanFieldScript",
"properties": [
{
"label": "equals",
Expand All @@ -42527,10 +42527,10 @@
]
},
{
"label": "BooleanFieldScript.Factory",
"label": "org.elasticsearch.xpack.runtimefields.mapper.BooleanFieldScript.Factory",
"kind": "class",
"documentation": "Class: BooleanFieldScript.Factory",
"insertText": "BooleanFieldScript.Factory",
"documentation": "Class: org.elasticsearch.xpack.runtimefields.mapper.BooleanFieldScript.Factory",
"insertText": "org.elasticsearch.xpack.runtimefields.mapper.BooleanFieldScript.Factory",
"properties": [
{
"label": "equals",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42501,10 +42501,10 @@
]
},
{
"label": "DateFieldScript",
"label": "org.elasticsearch.xpack.runtimefields.mapper.DateFieldScript",
"kind": "class",
"documentation": "Class: DateFieldScript",
"insertText": "DateFieldScript",
"documentation": "Class: org.elasticsearch.xpack.runtimefields.mapper.DateFieldScript",
"insertText": "org.elasticsearch.xpack.runtimefields.mapper.DateFieldScript",
"properties": [
{
"label": "equals",
Expand All @@ -42527,10 +42527,10 @@
]
},
{
"label": "DateFieldScript.Factory",
"label": "org.elasticsearch.xpack.runtimefields.mapper.DateFieldScript.Factory",
"kind": "class",
"documentation": "Class: DateFieldScript.Factory",
"insertText": "DateFieldScript.Factory",
"documentation": "Class: org.elasticsearch.xpack.runtimefields.mapper.DateFieldScript.Factory",
"insertText": "org.elasticsearch.xpack.runtimefields.mapper.DateFieldScript.Factory",
"properties": [
{
"label": "equals",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42501,10 +42501,10 @@
]
},
{
"label": "DoubleFieldScript",
"label": "org.elasticsearch.xpack.runtimefields.mapper.DoubleFieldScript",
"kind": "class",
"documentation": "Class: DoubleFieldScript",
"insertText": "DoubleFieldScript",
"documentation": "Class: org.elasticsearch.xpack.runtimefields.mapper.DoubleFieldScript",
"insertText": "org.elasticsearch.xpack.runtimefields.mapper.DoubleFieldScript",
"properties": [
{
"label": "equals",
Expand All @@ -42527,10 +42527,10 @@
]
},
{
"label": "DoubleFieldScript.Factory",
"label": "org.elasticsearch.xpack.runtimefields.mapper.DoubleFieldScript.Factory",
"kind": "class",
"documentation": "Class: DoubleFieldScript.Factory",
"insertText": "DoubleFieldScript.Factory",
"documentation": "Class: org.elasticsearch.xpack.runtimefields.mapper.DoubleFieldScript.Factory",
"insertText": "org.elasticsearch.xpack.runtimefields.mapper.DoubleFieldScript.Factory",
"properties": [
{
"label": "equals",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42501,10 +42501,10 @@
]
},
{
"label": "IpFieldScript",
"label": "org.elasticsearch.xpack.runtimefields.mapper.IpFieldScript",
"kind": "class",
"documentation": "Class: IpFieldScript",
"insertText": "IpFieldScript",
"documentation": "Class: org.elasticsearch.xpack.runtimefields.mapper.IpFieldScript",
"insertText": "org.elasticsearch.xpack.runtimefields.mapper.IpFieldScript",
"properties": [
{
"label": "equals",
Expand All @@ -42527,10 +42527,10 @@
]
},
{
"label": "IpFieldScript.Factory",
"label": "org.elasticsearch.xpack.runtimefields.mapper.IpFieldScript.Factory",
"kind": "class",
"documentation": "Class: IpFieldScript.Factory",
"insertText": "IpFieldScript.Factory",
"documentation": "Class: org.elasticsearch.xpack.runtimefields.mapper.IpFieldScript.Factory",
"insertText": "org.elasticsearch.xpack.runtimefields.mapper.IpFieldScript.Factory",
"properties": [
{
"label": "equals",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42501,10 +42501,10 @@
]
},
{
"label": "LongFieldScript",
"label": "org.elasticsearch.xpack.runtimefields.mapper.LongFieldScript",
"kind": "class",
"documentation": "Class: LongFieldScript",
"insertText": "LongFieldScript",
"documentation": "Class: org.elasticsearch.xpack.runtimefields.mapper.LongFieldScript",
"insertText": "org.elasticsearch.xpack.runtimefields.mapper.LongFieldScript",
"properties": [
{
"label": "equals",
Expand All @@ -42527,10 +42527,10 @@
]
},
{
"label": "LongFieldScript.Factory",
"label": "org.elasticsearch.xpack.runtimefields.mapper.LongFieldScript.Factory",
"kind": "class",
"documentation": "Class: LongFieldScript.Factory",
"insertText": "LongFieldScript.Factory",
"documentation": "Class: org.elasticsearch.xpack.runtimefields.mapper.LongFieldScript.Factory",
"insertText": "org.elasticsearch.xpack.runtimefields.mapper.LongFieldScript.Factory",
"properties": [
{
"label": "equals",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42425,10 +42425,10 @@
]
},
{
"label": "ScoreScript",
"label": "org.elasticsearch.script.ScoreScript",
"kind": "class",
"documentation": "Class: ScoreScript",
"insertText": "ScoreScript",
"documentation": "Class: org.elasticsearch.script.ScoreScript",
"insertText": "org.elasticsearch.script.ScoreScript",
"properties": [
{
"label": "equals",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42501,10 +42501,10 @@
]
},
{
"label": "StringFieldScript",
"label": "org.elasticsearch.xpack.runtimefields.mapper.StringFieldScript",
"kind": "class",
"documentation": "Class: StringFieldScript",
"insertText": "StringFieldScript",
"documentation": "Class: org.elasticsearch.xpack.runtimefields.mapper.StringFieldScript",
"insertText": "org.elasticsearch.xpack.runtimefields.mapper.StringFieldScript",
"properties": [
{
"label": "equals",
Expand All @@ -42527,10 +42527,10 @@
]
},
{
"label": "StringFieldScript.Factory",
"label": "org.elasticsearch.xpack.runtimefields.mapper.StringFieldScript.Factory",
"kind": "class",
"documentation": "Class: StringFieldScript.Factory",
"insertText": "StringFieldScript.Factory",
"documentation": "Class: org.elasticsearch.xpack.runtimefields.mapper.StringFieldScript.Factory",
"insertText": "org.elasticsearch.xpack.runtimefields.mapper.StringFieldScript.Factory",
"properties": [
{
"label": "equals",
Expand Down

0 comments on commit 77cbfd5

Please sign in to comment.