use of com.intellij.lang.javascript.psi.JSVariable in project intellij-plugins by JetBrains.
the class FlexImplicitUsageProvider method isImplicitUsage.
@Override
public boolean isImplicitUsage(PsiElement element) {
if (element instanceof XmlAttribute && ((XmlAttribute) element).isNamespaceDeclaration() && JavaScriptSupportLoader.isLanguageNamespace(((XmlAttribute) element).getValue())) {
return true;
}
if (element instanceof JSClass) {
JSClass clazz = (JSClass) element;
final Module module = ModuleUtilCore.findModuleForPsiElement(clazz);
if (module == null || ModuleType.get(module) != FlexModuleType.getInstance())
return false;
if (FlashRunConfigurationProducer.isAcceptedMainClass(clazz, module))
return true;
if (ActionScriptClassResolver.isParentClass(clazz, FlashRunConfigurationForm.MODULE_BASE_CLASS_NAME))
return true;
FlexUnitSupport flexUnitSupport = FlexUnitSupport.getSupport(module);
if (flexUnitSupport != null && flexUnitSupport.isTestClass(clazz, true))
return true;
} else if (element instanceof JSFunction) {
if (isTestMethod((JSFunction) element))
return true;
if (isAnnotatedByUnknownAttribute((JSAttributeListOwner) element))
return true;
} else if (element instanceof JSVariable) {
if (isAnnotatedByUnknownAttribute((JSAttributeListOwner) element))
return true;
if (JSResolveUtil.findParent(element) instanceof JSClass) {
final JSAttributeList varAttrList = ((JSVariable) element).getAttributeList();
if (varAttrList != null && varAttrList.findAttributeByName(FlexAnnotationNames.EMBED) != null) {
return true;
}
}
}
if (element instanceof JSParameter) {
JSFunction function = PsiTreeUtil.getParentOfType(element, JSFunction.class);
if (function != null) {
final JSParameter[] params = function.getParameterVariables();
if (params.length == 1 && element == params[0]) {
@NonNls String type = ((JSParameter) element).getTypeString();
if (type != null)
type = JSImportHandlingUtil.resolveTypeName(type, element);
if (type != null) {
if (FlexCommonTypeNames.FLASH_EVENT_FQN.equals(type) || FlexCommonTypeNames.STARLING_EVENT_FQN.equals(type)) {
return true;
}
boolean b = JSResolveUtil.processHierarchy(type, element.getContainingFile(), jsClass -> !FlexCommonTypeNames.FLASH_EVENT_FQN.equals(jsClass.getQualifiedName()) && !FlexCommonTypeNames.STARLING_EVENT_FQN.equals(jsClass.getQualifiedName()), false);
if (!b)
return true;
}
}
}
}
return false;
}
use of com.intellij.lang.javascript.psi.JSVariable in project intellij-plugins by JetBrains.
the class FlexClassMemberNode method update.
@Override
protected void update(PresentationData presentation) {
String text;
JSElement value = getValue();
if (value == null || !value.isValid()) {
return;
}
if (value instanceof JSFunction) {
text = JSFormatUtil.formatMethod(((JSFunction) value), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER, PsiFormatUtilBase.SHOW_TYPE);
} else if (value instanceof JSVariable) {
text = JSFormatUtil.formatField(((JSVariable) value), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER);
} else {
text = value.getName();
}
presentation.setPresentableText(text);
presentation.setIcon(value.getIcon(Iconable.ICON_FLAG_VISIBILITY));
}
use of com.intellij.lang.javascript.psi.JSVariable in project intellij-plugins by JetBrains.
the class InjectedASWriter method processProperty.
public ValueWriter processProperty(PsiElement host, String name, @Nullable String type, boolean isStyle, @NotNull MxmlObjectReferenceProvider mxmlObjectReferenceProvider) throws InvalidPropertyException {
final InjectedPsiVisitor visitor = new InjectedPsiVisitor(host, type, problemsHolder);
InjectedLanguageUtil.enumerate(host, visitor);
//noinspection ThrowableResultOfMethodCallIgnored
if (visitor.getInvalidPropertyException() != null) {
throw visitor.getInvalidPropertyException();
} else {
final Binding binding = visitor.getBinding();
if (binding != null) {
if (binding instanceof VariableBinding) {
JSVariable variable = ((VariableBinding) binding).variable;
VariableReference variableReference = variableReferenceMap.get(variable);
if (variableReference == null) {
variableReferenceMap.put(variable, new VariableReference(variable));
} else {
variableReference.markAsMultipleReferred();
}
}
if (mxmlObjectReferenceProvider instanceof Context && ((Context) mxmlObjectReferenceProvider).getParentScope().staticObjectPointToScope || mxmlObjectReferenceProvider instanceof InnerComponentContext) {
MxmlWriter.LOG.warn("IDEA-86372 " + host.getText());
} else {
binding.setTarget(mxmlObjectReferenceProvider.getMxmlObjectReference(), writer.getNameReference(name), isStyle);
bindingItems.add(binding);
}
return IGNORE;
} else {
return visitor.getValueWriter();
}
}
}
use of com.intellij.lang.javascript.psi.JSVariable in project intellij-plugins by JetBrains.
the class ActionScriptGenerateToStringHandler method createFix.
protected BaseCreateMethodsFix createFix(final JSClass jsClass) {
return new BaseCreateMethodsFix<JSVariable>(jsClass) {
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
evalAnchor(editor, file);
final boolean[] needOverride = new boolean[1];
JSInheritanceUtil.processOverrides(jsClass, new JSOverrideHandler() {
public boolean process(@NotNull List<JSPsiElementBase> elements, final PsiElement scope, final String className) {
needOverride[0] = !"Object".equals(className);
return false;
}
}, "toString", null, myJsClass, true);
@NonNls String functionText = "public " + (needOverride[0] ? "override " : "") + "function toString():String {\nreturn " + (needOverride[0] ? "super.toString()" : "\"" + jsClass.getName());
final String semicolon = JSCodeStyleSettings.getSemicolon(file);
boolean first = true;
final Set<JSVariable> jsVariables = getElementsToProcess();
if (!jsVariables.isEmpty()) {
functionText += needOverride[0] ? " + \"{" : "{";
for (JSVariable var : jsVariables) {
if (!first) {
functionText += " + \",";
}
first = false;
functionText += var.getName() + "=\" + String(" + var.getName() + ")";
}
functionText += "+\"}\"";
} else {
if (!needOverride[0])
functionText += "\"";
}
functionText += semicolon + "\n}";
doAddOneMethod(project, functionText, anchor);
}
};
}
use of com.intellij.lang.javascript.psi.JSVariable in project intellij-plugins by JetBrains.
the class FlexExtractFunctionTest method testSelectEntireLine.
public void testSelectEntireLine() throws Exception {
doTest(at -> {
JSExtractFunctionSettings.ParametersInfo parametersInfo = new JSExtractFunctionSettings.ParametersInfo();
JSVariable var = PsiTreeUtil.getParentOfType(myFile.findElementAt(myEditor.getCaretModel().getOffset()), JSVariable.class);
assertNotNull(var);
parametersInfo.variables.add(var);
parametersInfo.variableOptions.put(var, new JSExtractFunctionSettings.ParameterInfo(var.getName() + "2", true, null, 0));
return new MockJSExtractFunctionHandler.MyJSExtractFunctionSettings("created", true, false, JSAttributeList.AccessType.PUBLIC, parametersInfo, at);
}, getTestName(false), "js2");
}
Aggregations