forked from casteng/i-pascal
-
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.
- Loading branch information
Showing
3 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
plugin/test/com/siberika/idea/pascal/ReferencesSearchTest.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,62 @@ | ||
package com.siberika.idea.pascal; | ||
|
||
import com.intellij.openapi.editor.Document; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiReference; | ||
import com.intellij.psi.search.GlobalSearchScope; | ||
import com.intellij.psi.search.SearchScope; | ||
import com.intellij.psi.search.searches.ReferencesSearch; | ||
import com.intellij.psi.util.PsiTreeUtil; | ||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; | ||
import com.intellij.util.CommonProcessors; | ||
import com.intellij.util.Query; | ||
import com.siberika.idea.pascal.lang.psi.PasEntityScope; | ||
import com.siberika.idea.pascal.lang.psi.PascalRoutine; | ||
import com.siberika.idea.pascal.lang.psi.impl.PascalModuleImpl; | ||
import com.siberika.idea.pascal.lang.references.PasReferenceUtil; | ||
import com.siberika.idea.pascal.util.DocUtil; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public class ReferencesSearchTest extends LightPlatformCodeInsightFixtureTestCase { | ||
@Override | ||
protected String getTestDataPath() { | ||
return "testData/reference"; | ||
} | ||
|
||
public void testFromOtherUnit() { | ||
myFixture.configureByFiles("unit1.pas", "unit2.pas"); | ||
List<PasEntityScope> decls = getDeclarations("unit1"); | ||
System.out.println("===*** decls: " + decls.size()); | ||
SearchScope scope = GlobalSearchScope.allScope(getProject()); | ||
for (PasEntityScope decl : decls) { | ||
Document doc = myFixture.getDocument(decl.getContainingFile()); | ||
System.out.println(String.format("Decl: %s (%s)", DocUtil.getWholeLineAt(doc, decl.getTextRange().getStartOffset()), DocUtil.getLocation(doc, decl))); | ||
Collection<PsiReference> refs = new ArrayList<>(); | ||
Query<PsiReference> query = ReferencesSearch.search(decl, scope); | ||
query.forEach(new CommonProcessors.CollectProcessor<>(refs)); | ||
for (PsiReference ref : refs) { | ||
PsiElement el = ref.getElement(); | ||
doc = myFixture.getDocument(el.getContainingFile()); | ||
System.out.println(String.format(" ref: %s (%s)", DocUtil.getWholeLineAt(doc, el.getTextRange().getStartOffset()), DocUtil.getLocation(doc, el))); | ||
} | ||
|
||
} | ||
} | ||
|
||
private List<PasEntityScope> getDeclarations(String unitName) { | ||
List<PasEntityScope> res = new ArrayList<>(); | ||
PascalModuleImpl mod = (PascalModuleImpl) PasReferenceUtil.findUnit(myFixture.getProject(), | ||
PasReferenceUtil.findUnitFiles(myFixture.getProject(), myModule), unitName); | ||
Collection<PasEntityScope> scopes = PsiTreeUtil.findChildrenOfType(mod, PasEntityScope.class); | ||
for (PasEntityScope scope : scopes) { | ||
if ((scope instanceof PascalRoutine)) { | ||
res.add(scope); | ||
} | ||
} | ||
return res; | ||
} | ||
|
||
} |
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,43 @@ | ||
unit unit1; | ||
|
||
interface | ||
|
||
type | ||
TParent = class | ||
function test(): TParent; | ||
end; | ||
|
||
TChild = class(TParent) | ||
function test(): TParent; | ||
end; | ||
|
||
procedure test(); | ||
|
||
implementation | ||
|
||
{ TParent } | ||
|
||
function TParent.test(): TParent; | ||
begin | ||
end; | ||
|
||
{ TChild } | ||
|
||
function TChild.test(): TParent; | ||
begin | ||
inherited; | ||
end; | ||
|
||
procedure test(); | ||
begin | ||
end; | ||
|
||
var | ||
P: TParent; | ||
C: TChild; | ||
|
||
begin | ||
test(); | ||
P.test(); | ||
C.test(); | ||
end. |
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,18 @@ | ||
unit unit2; | ||
|
||
interface | ||
|
||
uses | ||
unit1; | ||
|
||
implementation | ||
|
||
var | ||
P: TParent; | ||
C: TChild; | ||
|
||
begin | ||
test(); | ||
P.test(); | ||
C.test(); | ||
end. |