Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Go directly to thrift declaration #139

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

azdrojowa123
Copy link

No description provided.

.map(name -> ThriftDeclarationIndex.findDeclaration(getElementName(name), getPackageName(name), project, GlobalSearchScope.allScope(project)))
.flatMap(Collection::stream)
.collect(Collectors.toList());
} catch (NoClassDefFoundError ignored) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious when does this exception happen

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I am curious too - I didn't think about this try.. catch block by myself (this try..catch block come from GoToThriftDefinition#getThriftDeclarations) Now I don't see any place where it could be thrown

}

@Override
public @Nullable @Nls(capitalization = Nls.Capitalization.Title) String getActionText(@NotNull DataContext context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it required to override this method if it just calls super?

private String getPackageName(String qualifiedName) {
try {
return qualifiedName.substring(0, qualifiedName.lastIndexOf("."));
} catch (IndexOutOfBoundsException ex){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid exception driven development. Just check if index of dot is >= 0 and return null if not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for getElementName


@Override
public PsiElement @Nullable [] getGotoDeclarationTargets(@Nullable PsiElement sourceElement, int offset, Editor editor) {
assert sourceElement != null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it good to throw AssertionError in such case? sourceElement is nullable. You could just return null.

List<String> fullyQualifiedNames = Collections.emptyList();

if (psiReference instanceof PsiJavaCodeReferenceElement) {
fullyQualifiedNames = Arrays.stream(((PsiJavaCodeReferenceElement) psiReference).multiResolve(false))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add /*paramName = */ for the boolean parameter, or extract this false to a named variable, so that it is easier to understand what it means?

assert sourceElement != null;

PsiFile containingFile = sourceElement.getContainingFile();
PsiReference psiReference = containingFile.findReferenceAt(sourceElement.getTextRange().getStartOffset());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See if getContainingFile can be null, if so, add a null check.

for (PsiElement child : psiFile.getChildren()) {
if (child instanceof ThriftTopLevelDeclaration && name.equals(((ThriftDeclaration)child).getName())) {
result.add((ThriftDeclaration)child);
file -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could align indents so this method looks similar to the one above

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants