From dd1fe03ff3089b416853c2c2cd65cde59585e79e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Giraud?= Date: Tue, 18 Feb 2020 09:42:30 +0100 Subject: [PATCH] #167 add parsing for deconstruction let [193] --- jps-plugin/src/com/reason/Log.java | 6 +- .../lang/core/psi/PsiQualifiedElement.java | 12 ++++ .../ide/docs/DocumentationProvider.java | 14 ++--- src/com/reason/ide/files/FileBase.java | 8 ++- .../reason/ide/go/ORModuleContributor.java | 6 +- .../FreeExpressionCompletionProvider.java | 38 ++++++------- .../provider/ModuleCompletionProvider.java | 5 +- .../provider/ObjectCompletionProvider.java | 27 ++++----- .../intentions/ExpandLocalOpenIntention.java | 4 +- .../intentions/FunctionBracesIntention.java | 8 +-- src/com/reason/ide/search/PsiFinder.java | 28 ++++----- .../ide/search/RmlFindUsagesProvider.java | 22 +++---- .../ide/search/index/ExceptionFqnIndex.java | 2 +- .../ide/search/index/ExceptionIndex.java | 2 +- .../ide/search/index/ExternalIndex.java | 2 +- .../reason/ide/search/index/LetFqnIndex.java | 2 +- src/com/reason/ide/search/index/LetIndex.java | 2 +- .../search/index/ModuleComponentIndex.java | 2 +- .../ide/search/index/ModuleFqnIndex.java | 2 +- .../reason/ide/search/index/ModuleIndex.java | 2 +- .../ide/search/index/RecordFieldIndex.java | 4 +- .../reason/ide/search/index/TypeIndex.java | 2 +- .../reason/ide/search/index/ValFqnIndex.java | 2 +- src/com/reason/ide/search/index/ValIndex.java | 2 +- .../ide/search/index/VariantFqnIndex.java | 2 +- .../reason/ide/search/index/VariantIndex.java | 5 +- src/com/reason/lang/ParserScopeEnum.java | 3 +- ...ElementFactory.java => ORCodeFactory.java} | 8 +-- src/com/reason/lang/core/ORUtil.java | 15 +++-- .../reason/lang/core/PsiElementFactory.java | 2 + src/com/reason/lang/core/psi/PsiClass.java | 10 ++-- .../lang/core/psi/PsiDeconstruction.java | 29 ++++++++++ .../reason/lang/core/psi/PsiException.java | 4 +- src/com/reason/lang/core/psi/PsiExternal.java | 6 +- .../reason/lang/core/psi/PsiFakeModule.java | 8 ++- src/com/reason/lang/core/psi/PsiFunctor.java | 10 ++-- src/com/reason/lang/core/psi/PsiLet.java | 22 ++++--- src/com/reason/lang/core/psi/PsiModule.java | 3 +- .../reason/lang/core/psi/PsiParameter.java | 7 +-- .../lang/core/psi/PsiQualifiedElement.java | 9 --- .../reason/lang/core/psi/PsiRecordField.java | 7 +-- src/com/reason/lang/core/psi/PsiType.java | 12 ++-- src/com/reason/lang/core/psi/PsiVal.java | 4 +- .../lang/core/psi/PsiVariantDeclaration.java | 26 ++++++--- .../lang/core/psi/impl/PsiClassImpl.java | 13 ++++- .../lang/core/psi/impl/PsiExceptionImpl.java | 23 ++++++-- .../lang/core/psi/impl/PsiExternalImpl.java | 14 ++++- .../lang/core/psi/impl/PsiFunctorImpl.java | 34 ++++++----- .../lang/core/psi/impl/PsiIncludeImpl.java | 39 ++++++------- .../core/psi/impl/PsiInnerModuleImpl.java | 44 ++++++-------- .../reason/lang/core/psi/impl/PsiLetImpl.java | 20 ++++++- .../core/psi/impl/PsiLowerSymbolImpl.java | 4 +- .../lang/core/psi/impl/PsiOpenImpl.java | 41 ++++++------- .../lang/core/psi/impl/PsiParameterImpl.java | 27 ++++----- .../core/psi/impl/PsiRecordFieldImpl.java | 26 +++++---- .../lang/core/psi/impl/PsiTypeImpl.java | 13 ++++- .../core/psi/impl/PsiUpperSymbolImpl.java | 4 +- .../reason/lang/core/psi/impl/PsiValImpl.java | 24 +++++--- .../psi/reference/ORFakeResolvedElement.java | 2 +- .../reference/PsiLowerSymbolReference.java | 57 ++++++++++++++----- .../reference/PsiUpperSymbolReference.java | 20 +++---- .../lang/core/stub/PsiExceptionStub.java | 16 ++++-- .../lang/core/stub/PsiExternalStub.java | 15 +++-- src/com/reason/lang/core/stub/PsiLetStub.java | 15 ++++- .../reason/lang/core/stub/PsiModuleStub.java | 17 ++++-- .../lang/core/stub/PsiRecordFieldStub.java | 17 ++++-- .../reason/lang/core/stub/PsiTypeStub.java | 15 +++-- src/com/reason/lang/core/stub/PsiValStub.java | 21 ++++--- .../core/stub/PsiVariantDeclarationStub.java | 16 ++++-- .../type/PsiExceptionStubElementType.java | 8 +-- .../stub/type/PsiExternalStubElementType.java | 8 +-- .../type/PsiFakeModuleStubElementType.java | 2 +- .../core/stub/type/PsiLetStubElementType.java | 46 +++++++++++++-- .../stub/type/PsiModuleStubElementType.java | 8 +-- .../type/PsiRecordFieldStubElementType.java | 19 ++++--- .../stub/type/PsiTypeStubElementType.java | 8 +-- .../core/stub/type/PsiValStubElementType.java | 8 +-- .../stub/type/PsiVariantStubElementType.java | 8 +-- src/com/reason/lang/core/type/ORTypes.java | 1 + src/com/reason/lang/ocaml/OclParser.java | 18 +++++- src/com/reason/lang/ocaml/OclQNameFinder.java | 3 +- src/com/reason/lang/ocaml/OclTypes.java | 1 + src/com/reason/lang/reason/RmlParser.java | 20 +++++-- .../reason/lang/reason/RmlQNameFinder.java | 3 +- src/com/reason/lang/reason/RmlTypes.java | 1 + tests/com/reason/ide/PsiFinderTest.java | 30 ++++++++-- .../ide/completion/FreeCompletionTest.java | 9 +++ .../ide/reference/OclQNameFinderTest.java | 15 +++++ .../reference/ResolveExternalElementTest.java | 10 ++-- .../ide/reference/ResolveLetElementTest.java | 33 +++++------ .../reference/ResolveModuleElementTest.java | 41 +++++++------ .../reference/ResolveRecordFieldsTest.java | 13 ++--- .../ide/reference/ResolveTypeElementTest.java | 24 ++++---- .../reference/ResolveVariantElementTest.java | 11 ++-- .../ide/reference/RmlQNameFinderTest.java | 17 ++++++ tests/com/reason/lang/core/ORUtilTest.java | 41 +++++++++++++ .../reason/lang/core/PsiScopedExprTest.java | 3 +- tests/com/reason/lang/core/PsiUtilTest.java | 30 ---------- .../com/reason/lang/ocaml/LetParsingTest.java | 11 ++++ .../reason/lang/reason/LetParsingTest.java | 15 +++-- 100 files changed, 861 insertions(+), 537 deletions(-) create mode 100644 jps-plugin/src/com/reason/lang/core/psi/PsiQualifiedElement.java rename src/com/reason/lang/core/{ORElementFactory.java => ORCodeFactory.java} (97%) create mode 100644 src/com/reason/lang/core/psi/PsiDeconstruction.java delete mode 100644 src/com/reason/lang/core/psi/PsiQualifiedElement.java create mode 100644 tests/com/reason/ide/reference/OclQNameFinderTest.java create mode 100644 tests/com/reason/ide/reference/RmlQNameFinderTest.java create mode 100644 tests/com/reason/lang/core/ORUtilTest.java delete mode 100644 tests/com/reason/lang/core/PsiUtilTest.java diff --git a/jps-plugin/src/com/reason/Log.java b/jps-plugin/src/com/reason/Log.java index 4d418c5dc..8049d8b74 100644 --- a/jps-plugin/src/com/reason/Log.java +++ b/jps-plugin/src/com/reason/Log.java @@ -8,8 +8,8 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiQualifiedNamedElement; import com.intellij.psi.ResolveResult; +import com.reason.lang.core.psi.PsiQualifiedElement; public class Log { @@ -130,13 +130,13 @@ public void trace(String comment, @Nullable Collection t) { } } - public void debug(String comment, @NotNull PsiQualifiedNamedElement element) { + public void debug(String comment, @NotNull PsiQualifiedElement element) { if (m_log.isDebugEnabled()) { m_log.debug(comment + SEP + element.getQualifiedName() + " (" + element.getContainingFile().getVirtualFile().getPath() + ")"); } } - public void debug(String comment, @NotNull PsiQualifiedNamedElement element, int position) { + public void debug(String comment, @NotNull PsiQualifiedElement element, int position) { if (m_log.isDebugEnabled()) { m_log.debug(comment + SEP + element.getQualifiedName() + " (" + element.getContainingFile().getVirtualFile().getPath() + ") pos=" + position); } diff --git a/jps-plugin/src/com/reason/lang/core/psi/PsiQualifiedElement.java b/jps-plugin/src/com/reason/lang/core/psi/PsiQualifiedElement.java new file mode 100644 index 000000000..aaaa037b4 --- /dev/null +++ b/jps-plugin/src/com/reason/lang/core/psi/PsiQualifiedElement.java @@ -0,0 +1,12 @@ +package com.reason.lang.core.psi; + +import org.jetbrains.annotations.NotNull; +import com.intellij.psi.PsiNamedElement; + +public interface PsiQualifiedElement extends PsiNamedElement { + @NotNull + String getPath(); + + @NotNull + String getQualifiedName(); +} diff --git a/src/com/reason/ide/docs/DocumentationProvider.java b/src/com/reason/ide/docs/DocumentationProvider.java index eca064034..b3193a9fe 100644 --- a/src/com/reason/ide/docs/DocumentationProvider.java +++ b/src/com/reason/ide/docs/DocumentationProvider.java @@ -10,8 +10,6 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiNameIdentifierOwner; -import com.intellij.psi.PsiNamedElement; -import com.intellij.psi.PsiQualifiedNamedElement; import com.intellij.psi.PsiReference; import com.intellij.psi.PsiWhiteSpace; import com.intellij.psi.util.PsiTreeUtil; @@ -26,6 +24,7 @@ import com.reason.lang.core.psi.PsiLet; import com.reason.lang.core.psi.PsiLowerSymbol; import com.reason.lang.core.psi.PsiModule; +import com.reason.lang.core.psi.PsiQualifiedElement; import com.reason.lang.core.psi.PsiSignatureElement; import com.reason.lang.core.psi.PsiType; import com.reason.lang.core.psi.PsiTypeConstrName; @@ -183,20 +182,19 @@ public String getQuickNavigateInfo(@NotNull PsiElement element, @NotNull PsiElem ORSignature signature = ((PsiSignatureElement) resolvedElement).getORSignature(); if (!signature.isEmpty()) { String sig = DocFormatter.escapeCodeForHtml(signature.asString(originalElement.getLanguage())); - if (resolvedElement instanceof PsiQualifiedNamedElement) { - String path = ORUtil.getQualifiedPath((PsiNameIdentifierOwner) resolvedElement); + if (resolvedElement instanceof PsiQualifiedElement) { + PsiQualifiedElement qualifiedElement = (PsiQualifiedElement) resolvedElement; String elementType = PsiTypeElementProvider.getType(resolvedElement); - String desc = ((PsiNamedElement) resolvedElement).getName(); - return createQuickDocTemplate(path, elementType, desc, sig); + return createQuickDocTemplate(qualifiedElement.getPath(), elementType, qualifiedElement.getName(), sig); } return sig; } } // No signature found, but resolved - if (resolvedElement instanceof PsiQualifiedNamedElement) { + if (resolvedElement instanceof PsiNameIdentifierOwner) { String elementType = PsiTypeElementProvider.getType(resolvedElement); - String desc = ((PsiQualifiedNamedElement) resolvedElement).getName(); + String desc = ((PsiNameIdentifierOwner) resolvedElement).getName(); String path = ORUtil.getQualifiedPath((PsiNameIdentifierOwner) resolvedElement); if (inferredType == null) { diff --git a/src/com/reason/ide/files/FileBase.java b/src/com/reason/ide/files/FileBase.java index 0932bb921..850525b8b 100644 --- a/src/com/reason/ide/files/FileBase.java +++ b/src/com/reason/ide/files/FileBase.java @@ -130,7 +130,13 @@ public PsiType getTypeExpression(@Nullable String name) { return expressions.isEmpty() ? null : expressions.iterator().next(); } - @Nullable + @NotNull + @Override + public String getPath() { + return getModuleName(); + } + + @NotNull @Override public String getQualifiedName() { return getModuleName(); diff --git a/src/com/reason/ide/go/ORModuleContributor.java b/src/com/reason/ide/go/ORModuleContributor.java index 9b09945ef..5ad316082 100644 --- a/src/com/reason/ide/go/ORModuleContributor.java +++ b/src/com/reason/ide/go/ORModuleContributor.java @@ -6,7 +6,6 @@ import com.intellij.navigation.GotoClassContributor; import com.intellij.navigation.NavigationItem; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiQualifiedNamedElement; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.Processor; import com.intellij.util.indexing.FindSymbolParameters; @@ -16,6 +15,7 @@ import com.reason.ide.search.index.ModuleIndex; import com.reason.lang.core.ORFileType; import com.reason.lang.core.psi.PsiModule; +import com.reason.lang.core.psi.PsiQualifiedElement; // Implements the goto class public class ORModuleContributor implements GotoClassContributor, ChooseByNameContributorEx { @@ -43,8 +43,8 @@ public void processElementsWithName(@NotNull String name, @NotNull Processor