Skip to content

Commit

Permalink
JS: inline unwrapProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
ulitink committed Sep 20, 2016
1 parent da1ae9b commit 58b404c
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 45 deletions.
Expand Up @@ -7,7 +7,6 @@
import com.intellij.lang.javascript.library.JSLibraryMappings;
import com.intellij.lang.javascript.psi.JSFunction;
import com.intellij.lang.javascript.psi.JSReferenceExpression;
import com.intellij.lang.javascript.psi.resolve.JSResolveUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
Expand Down Expand Up @@ -109,7 +108,7 @@ private static PsiElement unwrapResolveResult(@NotNull ResolveResult resolveResu
if (resolvedElement == null || !resolveResult.isValidResult()) {
return null;
}
return JSResolveUtil.unwrapProxy(resolvedElement);
return resolvedElement;
}

}
Expand Up @@ -24,7 +24,6 @@
import com.intellij.lang.refactoring.NamesValidator;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
Expand All @@ -33,7 +32,6 @@
import com.intellij.psi.xml.*;
import com.intellij.util.ArrayUtil;
import com.intellij.util.PlatformIcons;
import com.intellij.util.Processor;
import com.intellij.util.containers.HashSet;
import com.intellij.util.text.StringTokenizer;
import com.intellij.xml.*;
Expand Down Expand Up @@ -305,15 +303,11 @@ public boolean process(final JSAttributeNameValuePair pair, final String annotat

boolean b = jsClass == null || ClassBackedElementDescriptor.processAttributes(jsClass, itemsProcessor);

if (b && jsClass != null) {
final PsiElement _clazz = JSResolveUtil.unwrapProxy(jsClass);
final JSClass clazz = _clazz instanceof JSClass ? (JSClass)_clazz : null;

if (clazz != null) {
final JSClass[] classes = clazz.getSuperClasses();
if (classes.length > 0 && clazz.getName().equals(classes[0].getName()) && clazz != classes[0]) {
b = ClassBackedElementDescriptor.processAttributes(classes[0], itemsProcessor);
}
if (b && jsClass instanceof JSClass) {
final JSClass clazz = (JSClass)jsClass;
final JSClass[] classes = clazz.getSuperClasses();
if (classes.length > 0 && clazz.getName().equals(classes[0].getName()) && clazz != classes[0]) {
b = ClassBackedElementDescriptor.processAttributes(classes[0], itemsProcessor);
}
}

Expand Down Expand Up @@ -669,8 +663,8 @@ private static String checkClearDirectiveContext(final XmlElement context) {
final PsiElement iStyleClient = ActionScriptClassResolver.findClassByQNameStatic(I_STYLE_CLIENT_CLASS, attributeOrTag);

if (!(declaration instanceof JSClass) || !(iStyleClient instanceof JSClass)
|| !JSInheritanceUtil.isParentClass((JSClass)JSResolveUtil.unwrapProxy(declaration),
(JSClass)JSResolveUtil.unwrapProxy(iStyleClient))) {
|| !JSInheritanceUtil.isParentClass((JSClass)declaration,
(JSClass)iStyleClient)) {
return FlexBundle.message("clear.directive.IStyleClient.error");
}
return null;
Expand Down Expand Up @@ -763,7 +757,7 @@ public XmlElementDescriptor getElementDescriptor(final XmlTag childTag, XmlTag c
}

if (descriptor == null) {
PsiElement element = JSResolveUtil.unwrapProxy(getDeclaration());
PsiElement element = getDeclaration();
if (element instanceof JSNamedElement) {
element = new ClassBackedElementDescriptor(ClassBackedElementDescriptor.getPropertyType((JSNamedElement)element),
parentDescriptor.context, parentDescriptor.project, true).getDeclaration();
Expand Down
Expand Up @@ -407,7 +407,6 @@ XmlElementDescriptor getClassIfDynamic(final String localName, PsiElement elemen
}

static boolean isDynamicClass(PsiElement element) {
element = JSResolveUtil.unwrapProxy(element);
JSAttributeList attrList;
return element instanceof JSClass &&
(attrList = ((JSClass)element).getAttributeList()) != null &&
Expand Down Expand Up @@ -528,7 +527,6 @@ private void ensureDescriptorsMapsInitialized(PsiElement element, @Nullable Set<

if (element instanceof JSNamedElement) {
JSNamedElement jsClass = (JSNamedElement)element;
jsClass = (JSNamedElement)JSResolveUtil.unwrapProxy(jsClass);

if (visited == null || !visited.contains(jsClass)) {
if (!MxmlJSClass.XML_TAG_NAME.equals(jsClass.getName()) && !MxmlJSClass.XMLLIST_TAG_NAME.equals(jsClass.getName())) {
Expand All @@ -547,7 +545,7 @@ private void ensureDescriptorsMapsInitialized(PsiElement element, @Nullable Set<
appendSuperClassDescriptors(
map,
packageToInternalDescriptors,
JSResolveUtil.unwrapProxy(ActionScriptClassResolver.findClassByQNameStatic(OBJECT_CLASS_NAME, jsClass)),
ActionScriptClassResolver.findClassByQNameStatic(OBJECT_CLASS_NAME, jsClass),
visited);
}
}
Expand Down Expand Up @@ -941,7 +939,7 @@ XmlElementDescriptor[] getElementDescriptorsInheritedFromGivenType(@NotNull Stri
return EMPTY_ARRAY;
}

final PsiElement clazz = JSResolveUtil.unwrapProxy(ActionScriptClassResolver.findClassByQNameStatic(arrayElementType, declaration));
final PsiElement clazz = ActionScriptClassResolver.findClassByQNameStatic(arrayElementType, declaration);
if (!(clazz instanceof JSClass)) {
return EMPTY_ARRAY;
}
Expand Down Expand Up @@ -988,9 +986,8 @@ static XmlElementDescriptor checkValidDescriptorAccordingToType(String arrayElem
return null;
}

PsiElement element = JSResolveUtil.unwrapProxy(declaration);
if (element instanceof JSClass) {
if (!JSResolveUtil.isAssignableType(arrayElementType, ((JSClass)element).getQualifiedName(), element)) {
if (declaration instanceof JSClass) {
if (!JSResolveUtil.isAssignableType(arrayElementType, ((JSClass)declaration).getQualifiedName(), declaration)) {
return null;
}
}
Expand All @@ -1002,7 +999,7 @@ static XmlElementDescriptor checkValidDescriptorAccordingToType(String arrayElem
@Nullable
public AnnotationBackedDescriptor getDefaultPropertyDescriptor() {
if (!defaultPropertyDescriptorInitialized) {
PsiElement element = predefined ? null : JSResolveUtil.unwrapProxy(getDeclaration());
PsiElement element = predefined ? null : getDeclaration();

if (element instanceof XmlFile) {
element = XmlBackedJSClassFactory.getXmlBackedClass((XmlFile)element);
Expand Down Expand Up @@ -1158,8 +1155,6 @@ interface AttributedItemsProcessor {
}

static boolean processAttributes(PsiElement jsClass, AttributedItemsProcessor processor) {
jsClass = JSResolveUtil.unwrapProxy(jsClass);

return doProcess(jsClass, processor);
}

Expand Down
Expand Up @@ -90,7 +90,6 @@ public boolean canMove(PsiElement[] elements, @Nullable PsiElement targetContain

@Nullable
public static JSQualifiedNamedElement adjustForMove(PsiElement element) {
element = JSResolveUtil.unwrapProxy(element);
PsiFile file = element.getContainingFile();
if (file == null || !file.getLanguage().is(JavaScriptSupportLoader.ECMA_SCRIPT_L4) && !JavaScriptSupportLoader.isFlexMxmFile(file)) {
return null;
Expand Down
Expand Up @@ -80,7 +80,7 @@ public static boolean isParentClass(JSClass clazz, String className) {
}

public static boolean isParentClass(JSClass clazz, String className, boolean strict) {
final PsiElement parentClass = JSResolveUtil.unwrapProxy(findClassByQNameStatic(className, clazz.getResolveScope()));
final PsiElement parentClass = findClassByQNameStatic(className, clazz.getResolveScope());
if (!(parentClass instanceof JSClass)) return false;

return JSInheritanceUtil.isParentClass(clazz, (JSClass)parentClass, strict);
Expand Down
Expand Up @@ -422,9 +422,8 @@ public void findAcceptableVariants(JSReferenceExpression expression) {
if (clazzToProcess == null) return;
myEventsMap = getEventsMap(clazzToProcess);

final PsiElement eventClass1 = JSResolveUtil.unwrapProxy(
ActionScriptClassResolver
.findClassByQName(FlexCommonTypeNames.FLASH_EVENT_FQN, index, ModuleUtilCore.findModuleForPsiElement(expression)));
final PsiElement eventClass1 = ActionScriptClassResolver
.findClassByQName(FlexCommonTypeNames.FLASH_EVENT_FQN, index, ModuleUtilCore.findModuleForPsiElement(expression));
if ((eventClass1 instanceof JSClass)) {
setToProcessMembers(true);
setTypeContext(false);
Expand All @@ -436,9 +435,8 @@ public void findAcceptableVariants(JSReferenceExpression expression) {
}
}

final PsiElement eventClass2 = JSResolveUtil.unwrapProxy(
ActionScriptClassResolver
.findClassByQName(FlexCommonTypeNames.STARLING_EVENT_FQN, index, ModuleUtilCore.findModuleForPsiElement(expression)));
final PsiElement eventClass2 = ActionScriptClassResolver
.findClassByQName(FlexCommonTypeNames.STARLING_EVENT_FQN, index, ModuleUtilCore.findModuleForPsiElement(expression));
if ((eventClass2 instanceof JSClass)) {
setToProcessMembers(true);
setTypeContext(false);
Expand Down
Expand Up @@ -21,7 +21,6 @@
import com.intellij.lang.javascript.flex.sdk.FlexSdkUtils;
import com.intellij.lang.javascript.flex.sdk.FlexmojosSdkType;
import com.intellij.lang.javascript.psi.ecmal4.JSClass;
import com.intellij.lang.javascript.psi.resolve.JSResolveUtil;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
Expand Down Expand Up @@ -513,8 +512,7 @@ private void doCheck(final Pair<Module, FlexBuildConfiguration> moduleAndBC) thr
throw new RuntimeConfigurationError(FlexBundle.message("main.class.not.set"));
}

PsiElement clazz = JSResolveUtil.unwrapProxy(
ActionScriptClassResolver.findClassByQNameStatic(myOverriddenMainClass, moduleAndBC.first.getModuleScope(true)));
PsiElement clazz = ActionScriptClassResolver.findClassByQNameStatic(myOverriddenMainClass, moduleAndBC.first.getModuleScope(true));
if (!(clazz instanceof JSClass)) {
throw new RuntimeConfigurationError(FlexBundle.message("main.class.not.found", myOverriddenMainClass, bc.getName()));
}
Expand Down
Expand Up @@ -198,13 +198,13 @@ public static Trinity<JSExpressionStatement, String, String> getEventConstantInf
}

public static boolean isEventClass(final JSClass jsClass) {
final PsiElement eventClass = JSResolveUtil.unwrapProxy(ActionScriptClassResolver.findClassByQNameStatic(FlexCommonTypeNames.FLASH_EVENT_FQN, jsClass));
final PsiElement eventClass = ActionScriptClassResolver.findClassByQNameStatic(FlexCommonTypeNames.FLASH_EVENT_FQN, jsClass);
if ((eventClass instanceof JSClass) && JSInheritanceUtil.isParentClass(jsClass, (JSClass)eventClass)) {
return true;
}

final PsiElement eventClass2 =
JSResolveUtil.unwrapProxy(ActionScriptClassResolver.findClassByQNameStatic(FlexCommonTypeNames.STARLING_EVENT_FQN, jsClass));
ActionScriptClassResolver.findClassByQNameStatic(FlexCommonTypeNames.STARLING_EVENT_FQN, jsClass);
if ((eventClass2 instanceof JSClass) && JSInheritanceUtil.isParentClass(jsClass, (JSClass)eventClass2)) {
return true;
}
Expand Down Expand Up @@ -426,9 +426,8 @@ private static void ensureTrailingSemicolonPresent(final PsiFile psiFile, final

@Nullable
private JSClass getEventBaseClass() {
final PsiElement eventClass = JSResolveUtil
.unwrapProxy(JSDialectSpecificHandlersFactory.forElement(myJsClass).getClassResolver()
.findClassByQName(FlexCommonTypeNames.FLASH_EVENT_FQN, myJsClass));
final PsiElement eventClass = JSDialectSpecificHandlersFactory.forElement(myJsClass).getClassResolver()
.findClassByQName(FlexCommonTypeNames.FLASH_EVENT_FQN, myJsClass);
if (eventClass instanceof JSClass) return (JSClass)eventClass;
return null;
}
Expand Down
Expand Up @@ -15,7 +15,6 @@
import com.intellij.lang.javascript.flex.AnnotationBackedDescriptor;
import com.intellij.lang.javascript.psi.JSCommonTypeNames;
import com.intellij.lang.javascript.psi.ecmal4.JSClass;
import com.intellij.lang.javascript.psi.resolve.JSResolveUtil;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.util.Condition;
Expand Down Expand Up @@ -520,8 +519,8 @@ private void processClass(XmlElementValueProvider valueProvider) throws InvalidP

final Module module = ModuleUtilCore.findModuleForPsiElement(valueProvider.getElement());
if (module != null) {
jsClass = (JSClass)JSResolveUtil.unwrapProxy(
ActionScriptClassResolver.findClassByQNameStatic(trimmed, module.getModuleWithDependenciesAndLibrariesScope(false)));
jsClass = (JSClass)ActionScriptClassResolver
.findClassByQNameStatic(trimmed, module.getModuleWithDependenciesAndLibrariesScope(false));
}

if (jsClass == null) {
Expand Down

0 comments on commit 58b404c

Please sign in to comment.