Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public String extractStatus(T element) {
.filter(docTree -> docTree.getKind().equals(DocTree.Kind.DEPRECATED))
.findFirst()
.isPresent();
if (isDeprecated){
if (isDeprecated) {
return DocTree.Kind.DEPRECATED.name().toLowerCase();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@
import com.microsoft.model.Return;
import com.microsoft.util.CommentHelper;
import com.microsoft.util.Utils;
import com.sun.source.doctree.*;
import com.sun.source.doctree.DocCommentTree;
import com.sun.source.doctree.DocTree;
import com.sun.source.doctree.DocTree.Kind;
import com.sun.source.doctree.ParamTree;
import com.sun.source.doctree.ReturnTree;
import com.sun.source.doctree.ThrowsTree;
import jdk.javadoc.doclet.DocletEnvironment;

import javax.lang.model.element.*;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -151,7 +160,7 @@ String extractOverriddenUid(ExecutableElement ovr) {
private String determineComment(ExecutableElement methodElement) {
String inheritedInlineComment = getInheritedInlineCommentString(methodElement);
Optional<DocCommentTree> docCommentTree = getDocCommentTree(methodElement);
if (docCommentTree.isPresent()){
if (docCommentTree.isPresent()) {
return replaceBlockTags(docCommentTree.get(), inheritedInlineComment);
}
return inheritedInlineComment;
Expand Down Expand Up @@ -198,4 +207,16 @@ private CommentHelper getInheritedInlineTags(CommentHelper input) {

return output;
}

public String extractJavaType(Element element) {
if (element.getModifiers().contains(Modifier.STATIC)) {
if (element.getKind().equals(ElementKind.METHOD)) {
return "static method";
}
if (element.getKind().equals(ElementKind.FIELD) || element.getKind().equals(ElementKind.ENUM_CONSTANT)) {
return "static field";
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ String determinePackageContent(PackageElement packageElement) {
}

public String extractJavaType(PackageElement element) {
String javaType = element.getKind().name().toLowerCase().replaceAll("_", "");
String javaType = element.getKind().name().toLowerCase();
if (javaType.equals("package")) {
return javaType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
import com.microsoft.model.ExceptionItem;
import com.microsoft.model.MethodParameter;
import com.microsoft.model.Return;
import com.sun.source.doctree.*;
import com.sun.source.doctree.DeprecatedTree;
import com.sun.source.doctree.DocCommentTree;
import com.sun.source.doctree.DocTree.Kind;
import com.sun.source.doctree.IdentifierTree;
import com.sun.source.doctree.ParamTree;
import com.sun.source.doctree.ReturnTree;
import com.sun.source.doctree.TextTree;
import com.sun.source.doctree.ThrowsTree;
import com.sun.source.util.DocTrees;
import jdk.javadoc.doclet.DocletEnvironment;
import org.junit.Before;
Expand All @@ -15,24 +21,31 @@
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.Elements;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class ClassItemsLookupTest {

@Rule
public CompilationRule rule = new CompilationRule();
private Elements elements;
private List<Element> allGenderElements;
private List<Element> allPersonElements;
private DocletEnvironment environment;
private DocTrees docTrees;
private DocCommentTree docCommentTree;
Expand All @@ -47,6 +60,10 @@ public class ClassItemsLookupTest {
@Before
public void setup() {
elements = rule.getElements();
allGenderElements = elements.getTypeElement("com.microsoft.samples.subpackage.Person.IdentificationInfo.Gender")
.getEnclosedElements().stream().collect(Collectors.toList());
allPersonElements = elements.getTypeElement("com.microsoft.samples.subpackage.Person")
.getEnclosedElements().stream().collect(Collectors.toList());
environment = Mockito.mock(DocletEnvironment.class);
docTrees = Mockito.mock(DocTrees.class);
docCommentTree = Mockito.mock(DocCommentTree.class);
Expand Down Expand Up @@ -265,4 +282,34 @@ public void determineTypeForEnumConstant() {
assertEquals(classItemsLookup.determineType(element.getEnclosedElements().get(0)), "Field");
assertEquals(classItemsLookup.determineType(element.getEnclosedElements().get(1)), "Field");
}

@Test
public void testExtractJavaTypeStaticMethod() {
Element staticMethod = getElementByName(allGenderElements,"valueOf(java.lang.String)");
assertEquals("Wrong javaType","static method", classItemsLookup.extractJavaType(staticMethod));
}

@Test
public void testExtractJavaTypeStaticField() {
Element field = getElementByName(allGenderElements,"FEMALE");
assertEquals("Wrong javaType", "static field", classItemsLookup.extractJavaType(field));
}

@Test
public void testExtractJavaTypeNonStatic() {
Element constructor = getElementByName(allGenderElements,"Gender()");
assertEquals("Wrong javaType",null, classItemsLookup.extractJavaType(constructor));

Element nonStaticMethod = getElementByName(allPersonElements,"getFirstName()");
assertEquals("Wrong javaType",null, classItemsLookup.extractJavaType(nonStaticMethod));

Element nonStaticField = getElementByName(allPersonElements,"age");
assertEquals("Wrong javaType",null, classItemsLookup.extractJavaType(nonStaticField));
}

private Element getElementByName(List<Element> elements, String name) {
return elements.stream()
.filter(e -> e.toString().equals(name))
.findFirst().orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ items:
content: "public static final ExceptionHandler.Interceptor.RetryResult CONTINUE_EVALUATION"
return:
type: "com.microsoft.samples.ExceptionHandler.Interceptor.RetryResult"
javaType: "static field"
- uid: "com.microsoft.samples.ExceptionHandler.Interceptor.RetryResult.NO_RETRY"
id: "NO_RETRY"
parent: "com.microsoft.samples.ExceptionHandler.Interceptor.RetryResult"
Expand All @@ -67,6 +68,7 @@ items:
content: "public static final ExceptionHandler.Interceptor.RetryResult NO_RETRY"
return:
type: "com.microsoft.samples.ExceptionHandler.Interceptor.RetryResult"
javaType: "static field"
- uid: "com.microsoft.samples.ExceptionHandler.Interceptor.RetryResult.RETRY"
id: "RETRY"
parent: "com.microsoft.samples.ExceptionHandler.Interceptor.RetryResult"
Expand All @@ -81,6 +83,7 @@ items:
content: "public static final ExceptionHandler.Interceptor.RetryResult RETRY"
return:
type: "com.microsoft.samples.ExceptionHandler.Interceptor.RetryResult"
javaType: "static field"
- uid: "com.microsoft.samples.ExceptionHandler.Interceptor.RetryResult.RetryResult()"
id: "RetryResult()"
parent: "com.microsoft.samples.ExceptionHandler.Interceptor.RetryResult"
Expand Down Expand Up @@ -112,6 +115,7 @@ items:
type: "java.lang.String"
return:
type: "com.microsoft.samples.ExceptionHandler.Interceptor.RetryResult"
javaType: "static method"
- uid: "com.microsoft.samples.ExceptionHandler.Interceptor.RetryResult.values()"
id: "values()"
parent: "com.microsoft.samples.ExceptionHandler.Interceptor.RetryResult"
Expand All @@ -127,6 +131,7 @@ items:
content: "public static ExceptionHandler.Interceptor.RetryResult[] values()"
return:
type: "com.microsoft.samples.ExceptionHandler.Interceptor.RetryResult[]"
javaType: "static method"
references:
- uid: "com.microsoft.samples.ExceptionHandler.Interceptor.RetryResult.RetryResult*"
name: "RetryResult"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ items:
content: "public static ExceptionHandler getDefaultInstance()"
return:
type: "com.microsoft.samples.ExceptionHandler"
javaType: "static method"
- uid: "com.microsoft.samples.ExceptionHandler.hashCode()"
id: "hashCode()"
parent: "com.microsoft.samples.ExceptionHandler"
Expand Down Expand Up @@ -143,6 +144,7 @@ items:
content: "public static ExceptionHandler.Builder newBuilder()"
return:
type: "com.microsoft.samples.ExceptionHandler.Builder"
javaType: "static method"
- uid: "com.microsoft.samples.ExceptionHandler.shouldRetry(java.lang.Throwable,java.lang.Object)"
id: "shouldRetry(java.lang.Throwable,java.lang.Object)"
parent: "com.microsoft.samples.ExceptionHandler"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ items:
type: "com.microsoft.samples.google.ProductSearchSettings"
exceptions:
- type: "java.io.IOException"
javaType: "static method"
- uid: "com.microsoft.samples.google.ProductSearchSettings.createProductSetSettings()"
id: "createProductSetSettings()"
parent: "com.microsoft.samples.google.ProductSearchSettings"
Expand Down Expand Up @@ -191,6 +192,7 @@ items:
content: "public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder()"
return:
type: "com.google.api.gax.rpc.ApiClientHeaderProvider.Builder"
javaType: "static method"
- uid: "com.microsoft.samples.google.ProductSearchSettings.defaultCredentialsProviderBuilder()"
id: "defaultCredentialsProviderBuilder()"
parent: "com.microsoft.samples.google.ProductSearchSettings"
Expand All @@ -207,6 +209,7 @@ items:
content: "public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder()"
return:
type: "com.google.api.gax.core.GoogleCredentialsProvider.Builder"
javaType: "static method"
- uid: "com.microsoft.samples.google.ProductSearchSettings.defaultExecutorProviderBuilder()"
id: "defaultExecutorProviderBuilder()"
parent: "com.microsoft.samples.google.ProductSearchSettings"
Expand All @@ -223,6 +226,7 @@ items:
content: "public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder()"
return:
type: "com.google.api.gax.core.InstantiatingExecutorProvider.Builder"
javaType: "static method"
- uid: "com.microsoft.samples.google.ProductSearchSettings.defaultGrpcTransportProviderBuilder()"
id: "defaultGrpcTransportProviderBuilder()"
parent: "com.microsoft.samples.google.ProductSearchSettings"
Expand All @@ -239,6 +243,7 @@ items:
content: "public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder()"
return:
type: "com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.Builder"
javaType: "static method"
- uid: "com.microsoft.samples.google.ProductSearchSettings.defaultTransportChannelProvider()"
id: "defaultTransportChannelProvider()"
parent: "com.microsoft.samples.google.ProductSearchSettings"
Expand All @@ -254,6 +259,7 @@ items:
content: "public static TransportChannelProvider defaultTransportChannelProvider()"
return:
type: "com.google.api.gax.rpc.TransportChannelProvider"
javaType: "static method"
- uid: "com.microsoft.samples.google.ProductSearchSettings.deleteProductSetSettings()"
id: "deleteProductSetSettings()"
parent: "com.microsoft.samples.google.ProductSearchSettings"
Expand Down Expand Up @@ -318,6 +324,7 @@ items:
content: "public static String getDefaultEndpoint()"
return:
type: "java.lang.String"
javaType: "static method"
- uid: "com.microsoft.samples.google.ProductSearchSettings.getDefaultServiceScopes()"
id: "getDefaultServiceScopes()"
parent: "com.microsoft.samples.google.ProductSearchSettings"
Expand All @@ -334,6 +341,7 @@ items:
content: "public static List<String> getDefaultServiceScopes()"
return:
type: "java.util.List<java.lang.String>"
javaType: "static method"
- uid: "com.microsoft.samples.google.ProductSearchSettings.getProductSetSettings()"
id: "getProductSetSettings()"
parent: "com.microsoft.samples.google.ProductSearchSettings"
Expand Down Expand Up @@ -494,6 +502,7 @@ items:
content: "public static ProductSearchSettings.Builder newBuilder()"
return:
type: "com.microsoft.samples.google.ProductSearchSettings.Builder"
javaType: "static method"
- uid: "com.microsoft.samples.google.ProductSearchSettings.newBuilder(com.google.api.gax.rpc.ClientContext)"
id: "newBuilder(com.google.api.gax.rpc.ClientContext)"
parent: "com.microsoft.samples.google.ProductSearchSettings"
Expand All @@ -513,6 +522,7 @@ items:
type: "com.google.api.gax.rpc.ClientContext"
return:
type: "com.microsoft.samples.google.ProductSearchSettings.Builder"
javaType: "static method"
- uid: "com.microsoft.samples.google.ProductSearchSettings.purgeProductsOperationSettings()"
id: "purgeProductsOperationSettings()"
parent: "com.microsoft.samples.google.ProductSearchSettings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ items:
content: "public static final RecognitionAudio.AudioSourceCase AUDIOSOURCE_NOT_SET"
return:
type: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase"
javaType: "static field"
- uid: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase.AudioSourceCase(int)"
id: "AudioSourceCase(int)"
parent: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase"
Expand Down Expand Up @@ -88,6 +89,7 @@ items:
content: "public static final RecognitionAudio.AudioSourceCase CONTENT"
return:
type: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase"
javaType: "static field"
- uid: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase.URI"
id: "URI"
parent: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase"
Expand All @@ -102,6 +104,7 @@ items:
content: "public static final RecognitionAudio.AudioSourceCase URI"
return:
type: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase"
javaType: "static field"
- uid: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase.forNumber(int)"
id: "forNumber(int)"
parent: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase"
Expand All @@ -120,6 +123,7 @@ items:
type: "int"
return:
type: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase"
javaType: "static method"
- uid: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase.getNumber()"
id: "getNumber()"
parent: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase"
Expand Down Expand Up @@ -157,6 +161,7 @@ items:
type: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase"
description: "The enum associated with the given number."
status: "deprecated"
javaType: "static method"
- uid: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase.valueOf(java.lang.String)"
id: "valueOf(java.lang.String)"
parent: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase"
Expand All @@ -175,6 +180,7 @@ items:
type: "java.lang.String"
return:
type: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase"
javaType: "static method"
- uid: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase.values()"
id: "values()"
parent: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase"
Expand All @@ -190,6 +196,7 @@ items:
content: "public static RecognitionAudio.AudioSourceCase[] values()"
return:
type: "com.microsoft.samples.google.RecognitionAudio.AudioSourceCase[]"
javaType: "static method"
references:
- uid: "int"
href: "https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ items:
content: "public static final int CONTENT_FIELD_NUMBER"
return:
type: "int"
javaType: "static field"
- uid: "com.microsoft.samples.google.RecognitionAudio.RecognitionAudio()"
id: "RecognitionAudio()"
parent: "com.microsoft.samples.google.RecognitionAudio"
Expand Down Expand Up @@ -194,6 +195,7 @@ items:
content: "public static final int URI_FIELD_NUMBER"
return:
type: "int"
javaType: "static field"
- uid: "com.microsoft.samples.google.RecognitionAudio.getAudioSourceCase()"
id: "getAudioSourceCase()"
parent: "com.microsoft.samples.google.RecognitionAudio"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ items:
type: "com.microsoft.samples.google.SpeechClient"
exceptions:
- type: "java.io.IOException"
javaType: "static method"
- uid: "com.microsoft.samples.google.SpeechClient.create(com.google.cloud.speech.v1p1beta1.stub.SpeechStub)"
id: "create(com.google.cloud.speech.v1p1beta1.stub.SpeechStub)"
parent: "com.microsoft.samples.google.SpeechClient"
Expand All @@ -157,6 +158,7 @@ items:
type: "com.google.cloud.speech.v1p1beta1.stub.SpeechStub"
return:
type: "com.microsoft.samples.google.SpeechClient"
javaType: "static method"
- uid: "com.microsoft.samples.google.SpeechClient.create(com.microsoft.samples.google.SpeechSettings)"
id: "create(com.microsoft.samples.google.SpeechSettings)"
parent: "com.microsoft.samples.google.SpeechClient"
Expand All @@ -178,6 +180,7 @@ items:
type: "com.microsoft.samples.google.SpeechClient"
exceptions:
- type: "java.io.IOException"
javaType: "static method"
- uid: "com.microsoft.samples.google.SpeechClient.getOperationsClient()"
id: "getOperationsClient()"
parent: "com.microsoft.samples.google.SpeechClient"
Expand Down
Loading