use of com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference in project WebStormRequireJsPlugin by Fedott.
the class ReferenceTest method testCompletionInDefine.
public void testCompletionInDefine() {
myFixture.configureByFiles("public/blocks/fileWithDefine.js");
PsiReference reference;
PsiElement referenceElement;
// 1
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(5, 18));
reference = myFixture.getReferenceAtCaretPosition();
assert null != reference;
reference = ((PsiMultiReference) reference).getReferences()[1];
assertTrue(reference instanceof RequirejsReference);
assertEquals("'blocks/block'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertTrue(referenceElement instanceof JSFile);
assertEquals("block.js", ((JSFile) referenceElement).getName());
// 2
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(5, 33));
reference = myFixture.getReferenceAtCaretPosition();
assert null != reference;
reference = ((PsiMultiReference) reference).getReferences()[1];
assertTrue(reference instanceof RequirejsReference);
assertEquals("'/blocks/block'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertTrue(referenceElement instanceof JSFile);
assertEquals("block.js", ((JSFile) referenceElement).getName());
// 3
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(5, 51));
reference = myFixture.getReferenceAtCaretPosition();
assert null != reference;
reference = ((PsiMultiReference) reference).getReferences()[1];
assertTrue(reference instanceof RequirejsReference);
assertEquals("'./blocks/block'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertTrue(referenceElement instanceof JSFile);
assertEquals("block.js", ((JSFile) referenceElement).getName());
}
use of com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference in project WebStormRequireJsPlugin by Fedott.
the class ReferenceTest method testReferenceWithBaseUrl.
public void testReferenceWithBaseUrl() {
PsiReference reference;
PsiElement referenceElement;
myFixture.configureByFiles("public/fileForTestBaseUrlReference.js", "public/mainWithBaseUrl.js");
Settings.getInstance(getProject()).configFilePath = "mainWithBaseUrl.js";
// referenceNotFound
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(1, 40));
reference = myFixture.getReferenceAtCaretPosition();
assertTrue(reference instanceof RequirejsReference);
assertEquals("'app/as'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertNull(referenceElement);
// 1
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(2, 33));
reference = myFixture.getReferenceAtCaretPosition();
assertTrue(reference instanceof RequirejsReference);
assertEquals("'blocks/block'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertNull(referenceElement);
// 2
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(3, 33));
reference = myFixture.getReferenceAtCaretPosition();
assert null != reference;
reference = ((PsiMultiReference) reference).getReferences()[1];
assertTrue(reference instanceof RequirejsReference);
assertEquals("'block'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertTrue(referenceElement instanceof JSFile);
assertEquals("block.js", ((JSFile) referenceElement).getName());
// 3
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(4, 33));
reference = myFixture.getReferenceAtCaretPosition();
assertTrue(reference instanceof RequirejsReference);
assertEquals("'childBlocks/childBlock'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertTrue(referenceElement instanceof JSFile);
assertEquals("childBlock.js", ((JSFile) referenceElement).getName());
// 4
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(5, 33));
reference = myFixture.getReferenceAtCaretPosition();
assert null != reference;
reference = ((PsiMultiReference) reference).getReferences()[1];
assertTrue(reference instanceof RequirejsReference);
assertEquals("'childBlocks'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertNull(referenceElement);
// 5
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(6, 33));
reference = myFixture.getReferenceAtCaretPosition();
assertTrue(reference instanceof RequirejsReference);
assertEquals("'/block'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertNull(referenceElement);
// 6
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(7, 33));
reference = myFixture.getReferenceAtCaretPosition();
assertTrue(reference instanceof RequirejsReference);
assertEquals("'/blocks/block'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertTrue(referenceElement instanceof JSFile);
assertEquals("block.js", ((JSFile) referenceElement).getName());
// 7
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(8, 33));
reference = myFixture.getReferenceAtCaretPosition();
assertTrue(reference instanceof RequirejsReference);
assertEquals("'/childBlocks/childBlock'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertNull(referenceElement);
// 8
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(9, 33));
reference = myFixture.getReferenceAtCaretPosition();
assertTrue(reference instanceof RequirejsReference);
assertEquals("'./blocks/block'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertTrue(referenceElement instanceof JSFile);
assertEquals("block.js", ((JSFile) referenceElement).getName());
// 9
// TODO: Add check for parent root web directory
// myFixture
// .getEditor()
// .getCaretModel()
// .moveToLogicalPosition(new LogicalPosition(10, 33));
// reference = myFixture.getReferenceAtCaretPosition();
// assertTrue(reference instanceof RequirejsReference);
// assertEquals("'../public/blocks/block'", reference.getCanonicalText());
// referenceElement = reference.resolve();
// assertNull(referenceElement);
}
use of com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference in project WebStormRequireJsPlugin by Fedott.
the class ConfigParseTest method testReference.
public void testReference() {
Settings.getInstance(getProject()).configFilePath = "mainRequireJs.js";
PsiReference reference;
PsiElement referenceElement;
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(1, 36));
reference = myFixture.getReferenceAtCaretPosition();
assert (reference) != null;
reference = ((PsiMultiReference) reference).getReferences()[1];
assertTrue(reference instanceof RequirejsReference);
assertEquals("'module'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertEquals("rootWebPathConfigTest.js", ((JSFile) referenceElement).getName());
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(2, 36));
reference = myFixture.getReferenceAtCaretPosition();
assert (reference) != null;
reference = ((PsiMultiReference) reference).getReferences()[1];
assertTrue(reference instanceof RequirejsReference);
assertEquals("'moduleR'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertNull(referenceElement);
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(3, 51));
reference = myFixture.getReferenceAtCaretPosition();
assert (reference) != null;
reference = ((PsiMultiReference) reference).getReferences()[1];
assertTrue(reference instanceof RequirejsReference);
assertEquals("'moduleRelativeBaseUrlPath'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertTrue(referenceElement instanceof JSFile);
assertEquals("childBlock.js", ((JSFile) referenceElement).getName());
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(4, 51));
reference = myFixture.getReferenceAtCaretPosition();
assert (reference) != null;
reference = ((PsiMultiReference) reference).getReferences()[1];
assertTrue(reference instanceof RequirejsReference);
assertEquals("'moduleAbsolutePath'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertTrue(referenceElement instanceof JSFile);
assertEquals("block.js", ((JSFile) referenceElement).getName());
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(5, 51));
reference = myFixture.getReferenceAtCaretPosition();
assert (reference) != null;
reference = ((PsiMultiReference) reference).getReferences()[1];
assertTrue(reference instanceof RequirejsReference);
assertEquals("'moduleRelativeOneDotPath'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertTrue(referenceElement instanceof JSFile);
assertEquals("block.js", ((JSFile) referenceElement).getName());
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(6, 51));
reference = myFixture.getReferenceAtCaretPosition();
assert (reference) != null;
reference = ((PsiMultiReference) reference).getReferences()[1];
assertTrue(reference instanceof RequirejsReference);
assertEquals("'moduleRelativeTwoDotPAth'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertNull(referenceElement);
}
use of com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference in project smali by JesusFreke.
the class UsageTypeTest method doTest.
protected void doTest(@NotNull String fileName, @NotNull String text, @NotNull Object... expectedUsageTypes) throws Exception {
Assert.assertTrue(expectedUsageTypes.length % 2 == 0);
Map<Integer, UsageType> expectedUsageTypesMap = Maps.newHashMap();
for (int i = 0; i < expectedUsageTypes.length; i += 2) {
expectedUsageTypesMap.put((Integer) expectedUsageTypes[i], (UsageType) expectedUsageTypes[i + 1]);
}
PsiFile psiFile = createFile(fileName, REF_PATTERN.matcher(text).replaceAll(""));
Map<Integer, Integer> refIndexMap = getRefIndexes(text);
for (Map.Entry<Integer, Integer> entry : refIndexMap.entrySet()) {
int refId = entry.getKey();
int index = entry.getValue();
PsiReference reference = psiFile.getFirstChild().findReferenceAt(index);
Assert.assertNotNull(reference);
if (reference instanceof PsiMultiReference) {
// If there are multiple reference parents, the default seems to be the last one,
// i.e. the highest parent. We actually want the lowest one here.
reference = ((PsiMultiReference) reference).getReferences()[0];
}
UsageType usageType = usageTypeProvider.getUsageType(reference.getElement());
Assert.assertNotNull(usageType);
Assert.assertSame(expectedUsageTypesMap.get(refId), usageType);
expectedUsageTypesMap.remove(refId);
}
Assert.assertTrue(expectedUsageTypesMap.isEmpty());
}
use of com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference in project intellij-community by JetBrains.
the class LegacyCompletionContributor method processReferences.
public static void processReferences(final CompletionParameters parameters, final CompletionResultSet result, final PairConsumer<PsiReference, CompletionResultSet> consumer) {
final int startOffset = parameters.getOffset();
final PsiReference ref = parameters.getPosition().getContainingFile().findReferenceAt(startOffset);
if (ref instanceof PsiMultiReference) {
for (final PsiReference reference : CompletionData.getReferences((PsiMultiReference) ref)) {
processReference(result, startOffset, consumer, reference);
}
} else if (ref instanceof PsiDynaReference) {
for (final PsiReference reference : ((PsiDynaReference<?>) ref).getReferences()) {
processReference(result, startOffset, consumer, reference);
}
} else if (ref != null) {
processReference(result, startOffset, consumer, ref);
}
}
Aggregations