PT #156686000: Make enum value description look closer to javadoc

This commit is contained in:
BoykoAlex
2018-06-06 21:42:28 -04:00
parent 1a8f536b60
commit 1203b899dd
12 changed files with 124 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016-2017 Pivotal, Inc.
* Copyright (c) 2016-2018 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,12 +11,14 @@
package org.springframework.ide.vscode.commons.jandex;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.jboss.jandex.FieldInfo;
import org.springframework.ide.vscode.commons.java.Flags;
import org.springframework.ide.vscode.commons.java.IAnnotation;
import org.springframework.ide.vscode.commons.java.IField;
import org.springframework.ide.vscode.commons.java.IJavaType;
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
import org.springframework.ide.vscode.commons.java.IType;
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
@@ -93,4 +95,26 @@ class FieldImpl implements IField {
return BindingKeyUtils.getBindingKey(field);
}
@Override
public IJavaType type() {
return Wrappers.wrap(field.type());
}
@Override
public String signature() {
String jandexSignature = field.toString();
int typeEndIdx = jandexSignature.indexOf(' ');
if (typeEndIdx < 0) {
return jandexSignature;
} else {
if (isEnumConstant()) {
// Chop off field type completely for enum constant
return jandexSignature.substring(typeEndIdx + 1);
} else {
// Chop off prefix of the FQ name of the field type
return Pattern.compile(field.type().name().toString(), Pattern.LITERAL).matcher(jandexSignature).replaceFirst(Wrappers.simpleName(field.type().name()));
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016-2017 Pivotal, Inc.
* Copyright (c) 2016-2018 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -75,16 +75,6 @@ public class MethodImpl implements IMethod {
return Wrappers.wrap(method.returnType());
}
// @Override
// public String getSignature() {
// StringBuilder sb = new StringBuilder();
// sb.append('(');
// method.parameters().forEach(p -> sb.append(signature(p)));
// sb.append(')');
// sb.append(getReturnType());
// return sb.toString();
// }
@Override
public String toString() {
return method.toString();
@@ -113,4 +103,10 @@ public class MethodImpl implements IMethod {
return BindingKeyUtils.getBindingKey(method);
}
@Override
public String signature() {
//Return Jandex signature for now
return method.toString();
}
}

View File

@@ -154,4 +154,9 @@ class TypeImpl implements IType {
return classpathContainer;
}
@Override
public String signature() {
return info.toString();
}
}

View File

@@ -18,6 +18,7 @@ import java.io.File;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.FieldInfo;
import org.jboss.jandex.MethodInfo;
import org.jboss.jandex.PrimitiveType;
@@ -153,4 +154,10 @@ public class Wrappers {
throw new IllegalArgumentException("Invalid Java Type " + type.toString());
}
public static String simpleName(DotName dotName) {
String fqName = dotName.toString();
int idx = fqName.lastIndexOf('.');
return idx < 0 ? fqName : fqName.substring(idx + 1);
}
}

View File

@@ -15,6 +15,8 @@ import java.io.File;
public interface IField extends IMember {
boolean isEnumConstant();
IJavaType type();
@Override
default File classpathContainer() {
return getDeclaringType().classpathContainer();

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2013, 2016 IBM Corporation and others.
* Copyright (c) 2000, 2013, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -47,4 +47,6 @@ public interface IMember extends IJavaElement, IAnnotatable {
File classpathContainer();
String signature();
}

View File

@@ -10,16 +10,21 @@
*******************************************************************************/
package org.springframework.ide.vscode.commons.jandex;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.File;
import java.util.function.BiConsumer;
import java.util.stream.Stream;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.ide.vscode.commons.java.ClasspathData;
import org.springframework.ide.vscode.commons.java.IField;
import org.springframework.ide.vscode.commons.java.IMethod;
import org.springframework.ide.vscode.commons.java.IType;
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath.CPE;
import org.springframework.ide.vscode.commons.util.BasicFileObserver;
@@ -99,4 +104,35 @@ public class JandexClasspathTest {
assertNull(subject.findType("demo.Hello"));
assertNull(subject.findType("demo.Goodbye"));
}
@Test public void fieldSignature() throws Exception {
TestProject project = new TestProject("simple-java-project");
project.createClass("demo.Hello");
JandexClasspath subject = project.getJandexClasspath();
IType type = subject.findType("demo.Hello");
assertNotNull(type);
IField field = type.getField("message");
assertNotNull(field);
assertEquals("String demo.Hello.message", field.signature());
}
@Test public void methodSignature() throws Exception {
TestProject project = new TestProject("simple-java-project");
project.createClass("demo.Hello");
JandexClasspath subject = project.getJandexClasspath();
IType type = subject.findType("demo.Hello");
assertNotNull(type);
IMethod method = type.getMethod("getMessage", Stream.of());
assertNotNull(method);
assertEquals("java.util.List<java.lang.String> getMessage()", method.signature());
}
}

View File

@@ -1,5 +1,14 @@
package demo;
import java.util.Collections;
import java.util.List;
public class Hello {
String message;
public List<String> getMessage() {
return Collections.singletonList(message);
}
}