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);
}
}
}
};
}
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();
}
Aggregations