use of com.intellij.lang.javascript.psi.JSFunction 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.JSFunction in project intellij-plugins by JetBrains.
the class JSCreateMethodDialog method validateAndCommitData.
@Override
protected String validateAndCommitData() {
String error = super.validateAndCommitData();
if (error != null) {
return error;
}
JSFunction existingMethod = JSInheritanceUtil.findMethodInClass(createMethod(), myTargetClass, true);
if (existingMethod != null && existingMethod.getAttributeList().hasModifier(JSAttributeList.ModifierType.STATIC) == (myStaticCb != null && myStaticCb.isSelected())) {
boolean contains = existingMethod.getParent() == myTargetClass;
String message = JSBundle.message("class.already.contains.method.warning", myTargetClass.getQualifiedName(), Integer.valueOf(contains ? 1 : 2), getMethodName());
if (Messages.showYesNoDialog(myProject, message, getTitle(), Messages.getQuestionIcon()) != Messages.YES) {
return EXIT_SILENTLY;
}
}
return null;
}
use of com.intellij.lang.javascript.psi.JSFunction in project intellij-plugins by JetBrains.
the class CreateFlexUnitTestDialog method createUIComponents.
private void createUIComponents() {
final Module module = ModuleUtil.findModuleForPsiElement(myContextClass);
assert module != null;
myPackageCombo = JSReferenceEditor.forPackageName(StringUtil.getPackageName(myContextClass.getQualifiedName()), module.getProject(), null, getTestClassPackageScope(module), RefactoringBundle.message("choose.destination.package"));
final Condition<JSClass> filter = jsClass -> {
final JSAttributeList attributeList = jsClass.getAttributeList();
return !jsClass.isInterface() && attributeList != null && !attributeList.hasModifier(JSAttributeList.ModifierType.FINAL);
};
mySuperClassField = JSReferenceEditor.forClassName("", module.getProject(), null, getSuperClassScope(module), null, filter, JSBundle.message("choose.super.class.title"));
final List<JSMemberInfo> memberInfos = new ArrayList<>();
JSMemberInfo.extractClassMembers(myContextClass, memberInfos, new MemberInfoBase.Filter<JSAttributeListOwner>() {
public boolean includeMember(final JSAttributeListOwner member) {
final JSAttributeList attributeList = member.getAttributeList();
return member instanceof JSFunction && ((JSFunction) member).getKind() != JSFunction.FunctionKind.CONSTRUCTOR && attributeList != null && attributeList.getAccessType() == JSAttributeList.AccessType.PUBLIC;
}
});
myMemberSelectionPanel = new JSMemberSelectionPanel("Generate test methods for:", memberInfos, null);
}
use of com.intellij.lang.javascript.psi.JSFunction in project intellij-plugins by JetBrains.
the class NodeClassInfo method fillMapsForClass.
private static void fillMapsForClass(final JSClass jsClass, final Map<String, Icon> staticFields, final Map<String, Icon> staticProperties, final Map<String, Icon> fields, final Map<String, Icon> properties) {
for (final JSField variable : jsClass.getFields()) {
final JSAttributeList varAttributes = variable.getAttributeList();
if (varAttributes != null && varAttributes.hasModifier(JSAttributeList.ModifierType.STATIC)) {
staticFields.put(variable.getName(), variable.getIcon(Iconable.ICON_FLAG_VISIBILITY));
} else {
fields.put(variable.getName(), variable.getIcon(Iconable.ICON_FLAG_VISIBILITY));
}
}
for (final JSFunction function : jsClass.getFunctions()) {
if (function.getKind() == JSFunction.FunctionKind.GETTER && function.getName() != null) {
final JSAttributeList functionAttributes = function.getAttributeList();
if (functionAttributes != null && functionAttributes.hasModifier(JSAttributeList.ModifierType.STATIC)) {
staticProperties.put(function.getName(), function.getIcon(Iconable.ICON_FLAG_VISIBILITY));
} else {
properties.put(function.getName(), function.getIcon(Iconable.ICON_FLAG_VISIBILITY));
}
}
}
if (jsClass instanceof MxmlJSClass) {
final PsiFile file = jsClass.getContainingFile();
final XmlFile xmlFile = file instanceof XmlFile ? (XmlFile) file : null;
final XmlTag rootTag = xmlFile == null ? null : xmlFile.getRootTag();
if (rootTag != null) {
processSubtagsRecursively(rootTag, tag -> {
final String id = tag.getAttributeValue("id");
if (id != null) {
fields.put(id, tag.getIcon(Iconable.ICON_FLAG_VISIBILITY));
}
return !MxmlJSClass.isTagThatAllowsAnyXmlContent(tag);
});
}
}
}
use of com.intellij.lang.javascript.psi.JSFunction in project intellij-plugins by JetBrains.
the class MyImplicitUsageProvider method isImplicitUsage.
@Override
public boolean isImplicitUsage(PsiElement element) {
if (!(element instanceof JSFunction)) {
return false;
}
final JSFunction method = (JSFunction) element;
final String methodName = method.getName();
if (methodName == null || !Character.isUpperCase(methodName.charAt(0)) || !(method.getParent() instanceof JSClass) || method.getParent() instanceof XmlBackedJSClassImpl) {
return false;
}
final JSClass clazz = (JSClass) method.getParent();
if (!ActionScriptClassResolver.isParentClass(clazz, "com.intellij.flex.uiDesigner.TestCase")) {
return false;
}
final JSAttributeList attributeList = method.getAttributeList();
if (attributeList == null || attributeList.getAccessType() != JSAttributeList.AccessType.PUBLIC) {
return false;
}
final VirtualFile projectBaseDir = element.getProject().getBaseDir();
if (projectBaseDir == null) {
return false;
}
File testSourcePath = new File(projectBaseDir.getPath(), RELATIVE_TEST_DATA_PATH);
if (!testSourcePath.exists()) {
testSourcePath = new File(projectBaseDir.getPath(), "flex/tools/flex-ui-designer/" + RELATIVE_TEST_DATA_PATH);
assert testSourcePath.exists();
}
final JSAttributeList classAttributeList = clazz.getAttributeList();
if (classAttributeList != null) {
final JSAttribute testAnnotation = classAttributeList.findAttributeByName("Test");
if (testAnnotation == null) {
return false;
}
return new File(testSourcePath, testAnnotation.getValueByName("dir").getSimpleValue() + File.separatorChar + methodName + ".mxml").exists();
}
return false;
}
Aggregations