forked from redhat-developer/quarkus-ls
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documentation when hovering object members in Qute
eg. The documentation for `java.lang.String.length()` will be shown when hovering here: ``` {myString.len|gth()} ``` Closes redhat-developer#452 Signed-off-by: David Thompson <davthomp@redhat.com>
- Loading branch information
Showing
31 changed files
with
956 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...dhat.qute.jdt.test/src/main/java/com/redhat/qute/jdt/template/TemplateGetJavadocTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.qute.jdt.template; | ||
|
||
import static com.redhat.qute.jdt.QuteProjectTest.getJDTUtils; | ||
import static com.redhat.qute.jdt.QuteProjectTest.loadMavenProject; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.eclipse.core.runtime.NullProgressMonitor; | ||
import org.junit.Test; | ||
|
||
import com.redhat.qute.commons.DocumentFormat; | ||
import com.redhat.qute.commons.QuteJavadocParams; | ||
import com.redhat.qute.jdt.QuteProjectTest.QuteMavenProjectName; | ||
import com.redhat.qute.jdt.QuteSupportForTemplate; | ||
|
||
/** | ||
* Tests for getting the formatted Javadocs for Java members | ||
* | ||
* @author datho7561 | ||
*/ | ||
public class TemplateGetJavadocTest { | ||
|
||
@Test | ||
public void getFieldJavadoc() throws Exception { | ||
loadMavenProject(QuteMavenProjectName.qute_quickstart); | ||
|
||
QuteJavadocParams params = new QuteJavadocParams(// | ||
"org.acme.qute.Item", // | ||
QuteMavenProjectName.qute_quickstart, // | ||
"name", // | ||
"name : java.lang.String", // | ||
DocumentFormat.Markdown); | ||
|
||
String actual = QuteSupportForTemplate.getInstance().getJavadoc(params, getJDTUtils(), new NullProgressMonitor()); | ||
String expected = "The name of the item"; | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void getMethodJavadoc() throws Exception { | ||
loadMavenProject(QuteMavenProjectName.qute_quickstart); | ||
|
||
QuteJavadocParams params = new QuteJavadocParams(// | ||
"org.acme.qute.Item", // | ||
QuteMavenProjectName.qute_quickstart, // | ||
"getDerivedItems", // | ||
"getDerivedItems() : org.acme.qute.Item[]", // | ||
DocumentFormat.Markdown); | ||
|
||
String actual = QuteSupportForTemplate.getInstance().getJavadoc(params, getJDTUtils(), new NullProgressMonitor()); | ||
String expected = "Returns the derived items.\n\n * **Returns:**\n \n * the derived items"; | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void getFieldJavadocPlainText() throws Exception { | ||
loadMavenProject(QuteMavenProjectName.qute_quickstart); | ||
|
||
QuteJavadocParams params = new QuteJavadocParams(// | ||
"org.acme.qute.Item", // | ||
QuteMavenProjectName.qute_quickstart, // | ||
"name", // | ||
"name : java.lang.String", // | ||
DocumentFormat.PlainText); | ||
|
||
String actual = QuteSupportForTemplate.getInstance().getJavadoc(params, getJDTUtils(), new NullProgressMonitor()); | ||
String expected = " The name of the item "; | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void getMethodJavadocPlainText() throws Exception { | ||
loadMavenProject(QuteMavenProjectName.qute_quickstart); | ||
|
||
QuteJavadocParams params = new QuteJavadocParams(// | ||
"org.acme.qute.Item", // | ||
QuteMavenProjectName.qute_quickstart, // | ||
"getDerivedItems", // | ||
"getDerivedItems() : org.acme.qute.Item[]", // | ||
DocumentFormat.PlainText); | ||
|
||
String actual = QuteSupportForTemplate.getInstance().getJavadoc(params, getJDTUtils(), new NullProgressMonitor()); | ||
String expected = " Returns the derived items. \n * Returns:\n - the derived items"; | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void getMethodJavadocCyclic() throws Exception { | ||
loadMavenProject(QuteMavenProjectName.qute_quickstart); | ||
|
||
QuteJavadocParams params = new QuteJavadocParams(// | ||
"org.acme.qute.cyclic.ClassC", // | ||
QuteMavenProjectName.qute_quickstart, // | ||
"convert", // | ||
"convert() : java.lang.String", // | ||
DocumentFormat.PlainText); | ||
|
||
String actual = QuteSupportForTemplate.getInstance().getJavadoc(params, getJDTUtils(), new NullProgressMonitor()); | ||
String expected = " cyclic documentation "; | ||
assertEquals(expected, actual); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
qute.jdt/com.redhat.qute.jdt/src/main/java/com/redhat/qute/commons/DocumentFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.qute.commons; | ||
|
||
/** | ||
* Document format. | ||
* | ||
* @author Angelo ZERR | ||
*/ | ||
public enum DocumentFormat { | ||
|
||
PlainText(1), Markdown(2); | ||
|
||
private final int value; | ||
|
||
DocumentFormat(int value) { | ||
this.value = value; | ||
} | ||
|
||
public int getValue() { | ||
return value; | ||
} | ||
|
||
public static DocumentFormat forValue(int value) { | ||
DocumentFormat[] allValues = DocumentFormat.values(); | ||
if (value < 1 || value > allValues.length) | ||
throw new IllegalArgumentException("Illegal enum value: " + value); | ||
return allValues[value - 1]; | ||
} | ||
|
||
} |
92 changes: 92 additions & 0 deletions
92
qute.jdt/com.redhat.qute.jdt/src/main/java/com/redhat/qute/commons/QuteJavadocParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.qute.commons; | ||
|
||
/** | ||
* Represents the parameters needed to fetch the javadocs from the Java language | ||
* server component. | ||
* | ||
* @author datho7561 | ||
*/ | ||
public class QuteJavadocParams { | ||
|
||
private String sourceType; | ||
private String projectUri; | ||
private String memberName; | ||
private String signature; | ||
private DocumentFormat documentFormat; | ||
|
||
public QuteJavadocParams() { | ||
// needed for gson | ||
} | ||
|
||
public QuteJavadocParams(String sourceType, String projectUri, String memberName, String signature, | ||
DocumentFormat documentFormat) { | ||
this.sourceType = sourceType; | ||
this.projectUri = projectUri; | ||
this.memberName = memberName; | ||
this.signature = signature; | ||
this.documentFormat = documentFormat; | ||
} | ||
|
||
/** | ||
* Returns the fully qualified name of the class from which the Javadocs should | ||
* be retrieved. | ||
* | ||
* @return the fully qualified name of the class from which the Javadocs should | ||
* be retrieved | ||
*/ | ||
public String getSourceType() { | ||
return this.sourceType; | ||
} | ||
|
||
/** | ||
* Returns the uri of the project where the Javadocs should be retrieved from. | ||
* | ||
* @return the uri of the project where the Javadocs should be retrieved from | ||
*/ | ||
public String getProjectUri() { | ||
return this.projectUri; | ||
} | ||
|
||
/** | ||
* Returns the name of the field or method to get the documentation of. | ||
* | ||
* @return the name of the field or method to get the documentation of | ||
*/ | ||
public String getMemberName() { | ||
return this.memberName; | ||
} | ||
|
||
/** | ||
* Returns the signature of the field or method for which the documentation is | ||
* being retrieved. | ||
* | ||
* @return the signature of the field or method for which the documentation is | ||
* being retrieved | ||
*/ | ||
public String getSignature() { | ||
return this.signature; | ||
} | ||
|
||
/** | ||
* Returns the document format that should be used to represent the | ||
* documentation. | ||
* | ||
* @return the document format that should be used to represent the | ||
* documentation | ||
*/ | ||
public DocumentFormat getDocumentFormat() { | ||
return this.documentFormat; | ||
} | ||
|
||
} |
Oops, something went wrong.