Search in sources :

Example 1 with JSElementVisitor

use of com.intellij.lang.javascript.psi.JSElementVisitor in project intellij-plugins by JetBrains.

the class AbstractMethodBasedInspection method createVisitor.

@NotNull
@Override
protected final JSElementVisitor createVisitor(final ProblemsHolder holder, LocalInspectionToolSession session) {
    if (holder == null) {
        return JSElementVisitor.NOP_ELEMENT_VISITOR;
    }
    Project project = holder.getProject();
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
        if (!JstdSettingsUtil.areJstdConfigFilesInProjectCached(project)) {
            return JSElementVisitor.NOP_ELEMENT_VISITOR;
        }
    }
    return new JSElementVisitor() {

        @Override
        public void visitJSCallExpression(final JSCallExpression jsCallExpression) {
            JSFile jsFile = null;
            if (jsCallExpression != null) {
                jsFile = ObjectUtils.tryCast(jsCallExpression.getContainingFile(), JSFile.class);
            }
            if (jsFile == null) {
                return;
            }
            JSReferenceExpression methodExpression = ObjectUtils.tryCast(jsCallExpression.getMethodExpression(), JSReferenceExpression.class);
            if (methodExpression == null) {
                return;
            }
            boolean suitableSymbol = isSuitableElement(jsFile, jsCallExpression);
            if (suitableSymbol) {
                boolean resolved = isResolved(methodExpression);
                if (!resolved) {
                    TextRange rangeInElement = TextRange.create(0, methodExpression.getTextLength());
                    HintWrapperQuickFix fix = new HintWrapperQuickFix(methodExpression, rangeInElement, getFix());
                    holder.registerProblem(methodExpression, getProblemDescription(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, rangeInElement, fix);
                }
            }
        }
    };
}
Also used : Project(com.intellij.openapi.project.Project) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) TextRange(com.intellij.openapi.util.TextRange) JSFile(com.intellij.lang.javascript.psi.JSFile) JSElementVisitor(com.intellij.lang.javascript.psi.JSElementVisitor) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JSElementVisitor

use of com.intellij.lang.javascript.psi.JSElementVisitor in project intellij-plugins by JetBrains.

the class KarmaBasePathFinder method buildBasePath.

@Nullable
private static String buildBasePath(@NotNull JSFile jsFile) {
    final Ref<String> basePathRef = Ref.create(null);
    JSElementVisitor visitor = new JSElementVisitor() {

        @Override
        public void visitJSProperty(JSProperty property) {
            String name = JsPsiUtils.getPropertyName(property);
            if (BASE_PATH_VAR_NAME.equals(name)) {
                JSLiteralExpression value = ObjectUtils.tryCast(property.getValue(), JSLiteralExpression.class);
                if (value != null && value.isQuotedLiteral()) {
                    basePathRef.set(StringUtil.unquoteString(value.getText()));
                }
            }
        }

        @Override
        public void visitElement(PsiElement element) {
            ProgressIndicatorProvider.checkCanceled();
            if (basePathRef.isNull()) {
                element.acceptChildren(this);
            }
        }
    };
    visitor.visitJSFile(jsFile);
    return basePathRef.get();
}
Also used : JSLiteralExpression(com.intellij.lang.javascript.psi.JSLiteralExpression) JSProperty(com.intellij.lang.javascript.psi.JSProperty) JSElementVisitor(com.intellij.lang.javascript.psi.JSElementVisitor) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JSElementVisitor (com.intellij.lang.javascript.psi.JSElementVisitor)2 JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)1 JSFile (com.intellij.lang.javascript.psi.JSFile)1 JSLiteralExpression (com.intellij.lang.javascript.psi.JSLiteralExpression)1 JSProperty (com.intellij.lang.javascript.psi.JSProperty)1 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)1 Project (com.intellij.openapi.project.Project)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1