use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexUnitSuiteInspectionBase method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new FlexUnitInspectionVisitor() {
@Override
public void visitJSClass(JSClass aClass) {
FlexUnitSupport support = getFlexUnitSupport(aClass);
if (support == null || !support.isSuite(aClass))
return;
visitSuite(aClass, holder, support);
}
};
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class ActionScriptTypeChecker method checkExpressionIsAssignableToVariable.
@Override
public void checkExpressionIsAssignableToVariable(JSVariable p, final JSExpression expr, PsiFile containingFile, @PropertyKey(resourceBundle = JSBundle.BUNDLE) String problemKey, boolean allowChangeVariableTypeFix) {
final JSType type = p.getType();
Pair<Annotation, String> annotationAndExprType = checkExpressionIsAssignableToType(expr, type, problemKey, allowChangeVariableTypeFix ? p : null);
if (annotationAndExprType != null && p.getParent() instanceof JSParameterList && expr.getParent() instanceof JSArgumentList && !JSCommonTypeNames.VOID_TYPE_NAME.equals(annotationAndExprType.second)) {
JSFunction method = (JSFunction) p.getParent().getParent();
JSFunction topMethod = JSInheritanceUtil.findTopMethods(method).iterator().next();
annotationAndExprType.first.registerFix(new ChangeSignatureFix(topMethod, (JSArgumentList) expr.getParent()));
}
PsiElement _fun;
if (annotationAndExprType == null && type != null && FUNCTION_CLASS_NAME.equals(type.getResolvedTypeText()) && p instanceof JSParameter && isAddEventListenerMethod((JSFunction) p.getParent().getParent()) && ((expr instanceof JSReferenceExpression && (_fun = ((JSReferenceExpression) expr).resolve()) instanceof JSFunction) || (expr instanceof JSFunctionExpression && (_fun = expr) != null))) {
JSFunction fun = (JSFunction) _fun;
JSParameterList parameterList = fun.getParameterList();
if (parameterList != null) {
JSParameter[] parameters = parameterList.getParameterVariables();
boolean invalidArgs = parameters.length == 0;
if (!invalidArgs && parameters.length > 1) {
for (int i = parameters.length - 1; i > 0; --i) {
if (!parameters[i].isRest() && parameters[i].getInitializer() == null) {
invalidArgs = true;
break;
}
}
}
Computable.NotNullCachedComputable<JSParameterList> expectedParameterListForEventListener = new Computable.NotNullCachedComputable<JSParameterList>() {
@NotNull
@Override
protected JSParameterList internalCompute() {
JSClass jsClass = calcNontrivialExpectedEventType(expr);
ASTNode treeFromText = JSChangeUtil.createJSTreeFromText(expr.getProject(), "function f(event:" + (jsClass != null ? jsClass.getQualifiedName() : FlexCommonTypeNames.FLASH_EVENT_FQN) + ") {}", JavaScriptSupportLoader.ECMA_SCRIPT_L4);
return ((JSFunction) treeFromText.getPsi()).getParameterList();
}
};
if (invalidArgs) {
PsiElement expr_;
if (expr instanceof JSFunctionExpression) {
expr_ = ((JSFunctionExpression) expr).getParameterList();
} else {
expr_ = expr;
}
registerProblem(expr_, JSBundle.message("javascript.callback.signature.mismatch"), ProblemHighlightType.WEAK_WARNING, new ChangeSignatureFix(fun, expectedParameterListForEventListener));
} else {
final JSClass expectedEventClass = calcNontrivialExpectedEventType(expr);
JSType paramType = parameters[0].getType();
final String actualParameterType = paramType != null ? paramType.getResolvedTypeText() : null;
if (expectedEventClass == null) {
if (!JSResolveUtil.isAssignableType(FlexCommonTypeNames.FLASH_EVENT_FQN, actualParameterType, parameters[0]) && !JSResolveUtil.isAssignableType(FlexCommonTypeNames.STARLING_EVENT_FQN, actualParameterType, parameters[0])) {
registerProblem(expr instanceof JSFunctionExpression ? parameters[0] : expr, JSBundle.message("javascript.callback.signature.mismatch"), ProblemHighlightType.WEAK_WARNING, new ChangeSignatureFix(fun, expectedParameterListForEventListener));
}
} else {
if (!JSResolveUtil.isAssignableType(actualParameterType, expectedEventClass.getQualifiedName(), parameters[0])) {
registerProblem(expr instanceof JSFunctionExpression ? parameters[0] : expr, JSBundle.message("javascript.callback.signature.mismatch.event.class", expectedEventClass.getQualifiedName()), ProblemHighlightType.WEAK_WARNING, new ChangeSignatureFix(fun, expectedParameterListForEventListener));
}
}
}
}
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class JSImplicitlyInternalDeclarationInspection method process.
private static void process(final JSNamedElement node, final ProblemsHolder holder) {
if (!DialectDetector.isActionScript(node))
return;
JSFunction fun = PsiTreeUtil.getParentOfType(node, JSFunction.class);
if (fun != null)
return;
ASTNode nameIdentifier = node.findNameIdentifier();
if (nameIdentifier == null)
return;
JSClass clazz = JSResolveUtil.getClassOfContext(node);
if (clazz == null) {
PsiElement parent = JSResolveUtil.findParent(node);
if (!(parent instanceof JSPackageStatement))
return;
}
JSAttributeList attributeList = ((JSAttributeListOwner) node).getAttributeList();
JSAttributeList.AccessType accessType = attributeList != null ? attributeList.getAccessType() : null;
if (accessType == JSAttributeList.AccessType.PACKAGE_LOCAL && attributeList.findAccessTypeElement() == null && attributeList.getNamespaceElement() == null && !JSResolveUtil.isConstructorFunction(node)) {
holder.registerProblem(nameIdentifier.getPsi(), FlexBundle.message("js.implicitly.internal.declaration.problem"), new LocalQuickFix() {
@NotNull
@Override
public String getFamilyName() {
return FlexBundle.message("js.implicitly.internal.declaration.problem.add.internal.fix");
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement anchor = descriptor.getPsiElement();
JSChangeVisibilityUtil.setVisibility((JSAttributeListOwner) anchor.getParent(), JSAttributeList.AccessType.PACKAGE_LOCAL);
}
});
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class ActionScriptGenerateDelegatesHandler method findCandidateFields.
private static Collection<JSField> findCandidateFields(JSClass clazz) {
Collection<JSField> result = new ArrayList<>();
for (JSField field : clazz.getFields()) {
JSType type = field.getType();
JSClass fieldType = type != null ? type.resolveClass() : null;
if (fieldType != null && !ArrayUtil.contains(fieldType.getQualifiedName(), PRIMITIVE_TYPES) && !JSInheritanceUtil.isParentClass(clazz, fieldType, false)) {
result.add(field);
}
}
return result;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class ActionScriptGenerateEventHandler method isEventClass.
public static boolean isEventClass(final JSClass 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 = ActionScriptClassResolver.findClassByQNameStatic(FlexCommonTypeNames.STARLING_EVENT_FQN, jsClass);
if ((eventClass2 instanceof JSClass) && JSInheritanceUtil.isParentClass(jsClass, (JSClass) eventClass2)) {
return true;
}
return false;
}
Aggregations