use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class FlexNavigationTest method doTest.
public static void doTest(Editor editor, @Nullable VirtualFile expectedForSource, @Nullable VirtualFile expectedForDoc, @Nullable String expectedClassName, @Nullable Consumer<PsiElement> customCheck) {
PsiElement clazz = TargetElementUtil.findTargetElement(editor, TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED);
Collection<PsiElement> elementsToCheck;
GlobalSearchScope scope;
if (clazz == null || !(clazz instanceof JSQualifiedNamedElement)) {
PsiReference reference = TargetElementUtil.findReference(editor);
assertNotNull(reference);
elementsToCheck = TargetElementUtil.getInstance().getTargetCandidates(reference);
scope = null;
} else {
elementsToCheck = Arrays.asList(clazz);
final PsiFile file = PsiDocumentManager.getInstance(editor.getProject()).getPsiFile(editor.getDocument());
final PsiElement elementAt = file.findElementAt(editor.getCaretModel().getOffset());
scope = JSResolveUtil.getResolveScope(elementAt);
}
assertTrue("Target elements not found", elementsToCheck.size() > 0);
for (PsiElement element : elementsToCheck) {
if (element instanceof JSQualifiedNamedElement) {
String qName = ((JSQualifiedNamedElement) element).getQualifiedName();
GlobalSearchScope searchScope = scope != null ? scope : JSResolveUtil.getResolveScope(element);
final Collection<JSQualifiedNamedElement> candidates = StubIndex.getElements(JSQualifiedElementIndex.KEY, qName.hashCode(), editor.getProject(), searchScope, JSQualifiedNamedElement.class);
for (JSQualifiedNamedElement candidate : candidates) {
if (!qName.equals(candidate.getQualifiedName())) {
continue;
}
doCheck(candidate, expectedForSource, expectedForDoc, customCheck);
checkClassName(expectedClassName, candidate);
}
} else {
doCheck(element, expectedForSource, expectedForDoc, customCheck);
checkClassName(expectedClassName, element);
}
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class SwcCatalogXmlUtil method getTimestampFromCatalogXml.
public static long getTimestampFromCatalogXml(@NotNull final PsiElement psiElement) {
final Long cachedTimestamp = psiElement.getUserData(TIMESTAMP_IN_CATALOG_XML);
if (cachedTimestamp != null) {
return cachedTimestamp;
}
if (!(psiElement instanceof JSQualifiedNamedElement)) {
return -1;
}
final String qName = ((JSQualifiedNamedElement) psiElement).getQualifiedName();
if (StringUtil.isEmpty(qName)) {
return -1;
}
final PsiFile psiFile = psiElement.getContainingFile();
if (JavaScriptIndex.ECMASCRIPT_JS2.equals(psiFile.getName()))
return Integer.MIN_VALUE;
final VirtualFile swfFile = psiFile.getVirtualFile();
final VirtualFile dir = swfFile != null && "swf".equalsIgnoreCase(swfFile.getExtension()) ? swfFile.getParent() : null;
final VirtualFile catalogFile = dir == null ? null : dir.findChild("catalog.xml");
if (catalogFile == null) {
return -1;
}
Pair<Long, THashMap<String, TObjectLongHashMap<String>>> modStampAndSwfNameToQnameWithTimestampMap = catalogFile.getUserData(MOD_STAMP_AND_SWF_NAME_TO_QNAME_WITH_TIMESTAMP_MAP);
if (modStampAndSwfNameToQnameWithTimestampMap == null || modStampAndSwfNameToQnameWithTimestampMap.first != catalogFile.getModificationStamp()) {
final THashMap<String, TObjectLongHashMap<String>> swfNameToQnameWithTimestampMap = parseTimestampsFromCatalogXml(catalogFile);
modStampAndSwfNameToQnameWithTimestampMap = Pair.create(catalogFile.getModificationStamp(), swfNameToQnameWithTimestampMap);
catalogFile.putUserData(MOD_STAMP_AND_SWF_NAME_TO_QNAME_WITH_TIMESTAMP_MAP, modStampAndSwfNameToQnameWithTimestampMap);
}
final TObjectLongHashMap<String> qnameWithTimestampMap = modStampAndSwfNameToQnameWithTimestampMap.second.get(swfFile.getName());
final long timestamp = qnameWithTimestampMap == null ? -1 : qnameWithTimestampMap.get(qName);
psiElement.putUserData(TIMESTAMP_IN_CATALOG_XML, timestamp);
return timestamp;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class FlexMoveClassProcessor method findUsages.
@NotNull
@Override
protected UsageInfo[] findUsages() {
Collection<UsageInfo> result = Collections.synchronizedCollection(new ArrayList<UsageInfo>());
result.addAll(Arrays.asList(super.findUsages()));
for (JSQualifiedNamedElement element : myElements) {
if (element instanceof JSClass) {
JSRefactoringUtil.addConstructorUsages((JSClass) element, result);
}
TextOccurrencesUtil.findNonCodeUsages(element, element.getQualifiedName(), mySearchInComments, mySearchInNonJavaFiles, StringUtil.getQualifiedName(myTargetPackage, element.getName()), result);
}
return result.toArray(new UsageInfo[result.size()]);
}
use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class ActionScriptImportHandler method resolveTypeNameUsingImports.
@Nullable
private static JSImportedElementResolveResult resolveTypeNameUsingImports(@NotNull final String referencedName, PsiNamedElement parent) {
final Map<String, JSImportedElementResolveResult> map = myImportResolveCache.get(ourImportResolveCache, parent, null).getValue();
JSImportedElementResolveResult result = map.get(referencedName);
if (result == null) {
SinkResolveProcessor resolveProcessor = new SinkResolveProcessor(referencedName, new ResolveResultSink(null, referencedName));
INSTANCE.resolveTypeNameUsingImportsInner(resolveProcessor, parent);
final ResolveResult[] resolveResults = resolveProcessor.getResultsAsResolveResults();
assert resolveResults.length < 2;
if (resolveResults.length == 1 && resolveResults[0] instanceof JSResolveResult) {
JSResolveResult resolveResult = (JSResolveResult) resolveResults[0];
final PsiElement element = resolveResult.getElement();
String typeName = ((JSQualifiedNamedElement) element).getQualifiedName();
result = new JSImportedElementResolveResult(typeName, element, resolveResult.getActionScriptImport());
}
map.put(referencedName, result != null ? result : JSImportedElementResolveResult.EMPTY_RESULT);
}
return result != JSImportedElementResolveResult.EMPTY_RESULT ? result : null;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class AddImportECMAScriptClassOrFunctionAction method isAvailable.
public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile file) {
if (!myReference.getElement().isValid())
return false;
final long modL = myReference.getElement().getManager().getModificationTracker().getModificationCount();
if (!isAvailableCalculated || modL != modificationCount) {
final ResolveResult[] results = myReference.multiResolve(false);
boolean hasValidResult = false;
for (ResolveResult r : results) {
if (r.isValidResult()) {
hasValidResult = true;
break;
}
}
if (!hasValidResult) {
final Collection<JSQualifiedNamedElement> candidates = getCandidates(editor, file);
isAvailableCalculated = true;
isAvailable = candidates.size() > 0;
String text;
if (isAvailable) {
final JSQualifiedNamedElement element = candidates.iterator().next();
text = element.getQualifiedName() + "?";
if (candidates.size() > 1)
text += " (multiple choices...)";
if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
text += " Alt+Enter";
}
} else {
text = "";
}
myText = text;
} else {
isAvailableCalculated = true;
isAvailable = false;
myText = "";
}
modificationCount = modL;
}
return isAvailable;
}
Aggregations