use of com.intellij.lang.javascript.psi.JSReferenceExpression in project intellij-plugins by JetBrains.
the class ActionScriptResolveTest method testResolveIt.
public void testResolveIt() throws Exception {
String fileText = "package {\n" + "\n" + "public class Test {\n" + " public function Test() {\n" + " var describeType:XML = describe<ref>Type(Test);\n" + " }\n" + "}\n" + "function describeType(x) {}";
JSReferenceExpression ref = (JSReferenceExpression) configureByFileText(fileText, "sample.js2");
assertTrue(ref.resolve() instanceof JSLocalVariable);
}
use of com.intellij.lang.javascript.psi.JSReferenceExpression in project intellij-plugins by JetBrains.
the class ActionScriptResolveTest method testResolveInClass.
public void testResolveInClass() throws Exception {
String fileText = "class A { function get aaa() {} function foo() {\n" + " var aaa = a<ref>aa;\n}" + "}";
JSReferenceExpression ref = (JSReferenceExpression) configureByFileText(fileText, "sample.js2");
assertTrue(ref.resolve() instanceof JSFunction);
}
use of com.intellij.lang.javascript.psi.JSReferenceExpression in project intellij-plugins by JetBrains.
the class FlexRenameTest method testRenameClassTwoTimes.
public void testRenameClassTwoTimes() throws Exception {
final String name = getTestName(false);
VirtualFile file = getVirtualFile(getBasePath() + name + "/mytest/foo/" + name + "_2.js2");
VirtualFile[] files = { getVirtualFile(getBasePath() + name + "/mytest/boo/" + name + ".js2"), file };
configureByFiles(new File(getTestDataPath() + getBasePath() + name), files);
int referencesCount = findRenamedRefsToReferencedElementAtCaret().length;
performAction(name + "_3", true);
checkResultByFile(getBasePath() + name + "_after.js2");
assertEquals(referencesCount, findRenamedRefsToReferencedElementAtCaret().length);
performAction(name + "_4", true);
checkResultByFile(getBasePath() + name + "_after2.js2");
PsiReference[] refs = findRenamedRefsToReferencedElementAtCaret();
assertEquals(referencesCount, refs.length);
for (PsiReference ref : refs) {
PsiElement refElement = ref.getElement();
PsiElement refElementParent = refElement.getParent();
assertFalse(refElementParent instanceof JSReferenceExpression);
if (!(refElementParent instanceof JSImportStatement)) {
assertEquals(name + "_4", refElement.getText());
}
}
}
use of com.intellij.lang.javascript.psi.JSReferenceExpression in project intellij-plugins by JetBrains.
the class JSShortenFQNamesProcessor method processText.
public void processText(final Project project, final Template template, final Document document, final RangeMarker templateRange, final Editor editor) {
if (!template.isToShortenLongNames())
return;
try {
final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
psiDocumentManager.commitDocument(document);
final PsiFile hostFile = PsiUtilBase.getPsiFileInEditor(editor, project);
final PsiFile file = (hostFile != null && JavaScriptSupportLoader.isFlexMxmFile(hostFile)) ? InjectedLanguageUtil.findInjectedPsiNoCommit(hostFile, templateRange.getStartOffset()) : hostFile;
if (file instanceof JSFile && file.getLanguage().isKindOf(JavaScriptSupportLoader.ECMA_SCRIPT_L4)) {
final ActionScriptUnusedImportsHelper.Results unusedImportsResults = ActionScriptUnusedImportsHelper.getUnusedImports(file);
for (final JSReferenceExpression reference : unusedImportsResults.fqnsToReplaceWithShortName) {
final TextRange range = InjectedLanguageManager.getInstance(project).injectedToHost(file, reference.getTextRange());
if (TextRange.create(templateRange).contains(range)) {
final String shortName = StringUtil.getShortName(reference.getReferencedName());
final String resolved = JSImportHandlingUtil.resolveTypeName(shortName, reference);
// insert import statement if needed
if (shortName.equals(resolved)) {
final FormatFixer fixer = ImportUtils.insertImportStatements(reference, Collections.singletonList(reference.getText()));
if (fixer != null) {
fixer.fixFormat();
}
}
// shorten FQN
reference.replace(JSChangeUtil.createExpressionFromText(project, shortName).getPsi());
}
}
psiDocumentManager.doPostponedOperationsAndUnblockDocument(document);
}
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
use of com.intellij.lang.javascript.psi.JSReferenceExpression in project intellij-plugins by JetBrains.
the class FlexMoveClassProcessor method retargetUsages.
@Override
protected void retargetUsages(UsageInfo[] usages, Map<PsiElement, PsiElement> oldToNewMap) {
super.retargetUsages(usages, oldToNewMap);
for (UsageInfo usage : usages) {
if (usage instanceof JSRefactoringUtil.ConstructorUsageInfo) {
final JSRefactoringUtil.ConstructorUsageInfo constuctorUsage = (JSRefactoringUtil.ConstructorUsageInfo) usage;
final JSReferenceExpression ref = constuctorUsage.getElement();
if (ref != null && constuctorUsage.getSubject().isValid()) {
ref.bindToElement(constuctorUsage.getSubject().getContainingFile());
}
}
}
}
Aggregations