use of com.intellij.psi.PsiElementVisitor in project intellij-community by JetBrains.
the class WrongPropertyKeyValueDelimiterInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
if (!(holder.getFile() instanceof PropertiesFileImpl)) {
return PsiElementVisitor.EMPTY_VISITOR;
}
final PropertiesCodeStyleSettings codeStyleSettings = PropertiesCodeStyleSettings.getInstance(holder.getProject());
final char codeStyleKeyValueDelimiter = codeStyleSettings.getDelimiter();
return new PsiElementVisitor() {
@Override
public void visitElement(PsiElement element) {
if (element instanceof PropertyImpl) {
final char delimiter = ((PropertyImpl) element).getKeyValueDelimiter();
if (delimiter != codeStyleKeyValueDelimiter) {
holder.registerProblem(element, PropertiesBundle.message("wrong.property.key.value.delimiter.inspection.display.name"), new ReplaceKeyValueDelimiterQuickFix(element));
}
}
}
};
}
use of com.intellij.psi.PsiElementVisitor in project intellij-community by JetBrains.
the class SpellCheckingInspection method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
final SpellCheckerManager manager = SpellCheckerManager.getInstance(holder.getProject());
return new PsiElementVisitor() {
@Override
public void visitElement(final PsiElement element) {
final ASTNode node = element.getNode();
if (node == null) {
return;
}
// Extract parser definition from element
final Language language = element.getLanguage();
final IElementType elementType = node.getElementType();
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
// Handle selected options
if (parserDefinition != null) {
if (parserDefinition.getStringLiteralElements().contains(elementType)) {
if (!processLiterals) {
return;
}
} else if (parserDefinition.getCommentTokens().contains(elementType)) {
if (!processComments) {
return;
}
} else if (!processCode) {
return;
}
}
tokenize(element, language, new MyTokenConsumer(manager, holder, LanguageNamesValidation.INSTANCE.forLanguage(language)));
}
};
}
use of com.intellij.psi.PsiElementVisitor in project intellij-plugins by JetBrains.
the class CfmlFileReferenceInspection method buildVisitor.
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
return new PsiElementVisitor() {
public void visitElement(final PsiElement element) {
PsiElement tagParent = PsiTreeUtil.getParentOfType((element), CfmlTag.class);
if ((element.getNode().getElementType() == CfmlTokenTypes.STRING_TEXT)) {
if ((tagParent == null || (!((CfmlTag) tagParent).getTagName().equalsIgnoreCase("cfinclude") && !((CfmlTag) tagParent).getTagName().equalsIgnoreCase("cfmodule")))) {
PsiElement superParent = element.getParent() != null ? element.getParent().getParent() : null;
ASTNode superParentNode = superParent != null ? superParent.getNode() : null;
if ((superParentNode == null || superParentNode.getElementType() != CfmlElementTypes.INCLUDEEXPRESSION)) {
return;
}
}
final PsiReference[] refs = element.getParent().getReferences();
for (int i = 0, refsLength = refs.length; i < refsLength; i++) {
PsiReference ref = refs[i];
if (!(ref instanceof FileReference))
continue;
if (ref.resolve() == null) {
PsiDirectory dir;
if (i > 0) {
final PsiElement target = refs[i - 1].resolve();
dir = target instanceof PsiDirectory ? (PsiDirectory) target : null;
} else {
dir = element.getContainingFile().getParent();
}
holder.registerProblem(ref.getElement(), ref.getRangeInElement(), isOnTheFly ? "Path '" + ref.getCanonicalText() + "' not found" : "Path not found", isOnTheFly && dir != null ? new LocalQuickFix[] { new CreateFileFix(i < refs.length - 1, ref.getCanonicalText(), dir) } : LocalQuickFix.EMPTY_ARRAY);
// ProblemHighlightType.ERROR);
break;
}
}
}
}
};
}
use of com.intellij.psi.PsiElementVisitor in project intellij-plugins by JetBrains.
the class CucumberJavaAllFeaturesInFolderRunConfigurationProducer method getStepsGlue.
@Override
protected NullableComputable<String> getStepsGlue(@NotNull final PsiElement element) {
final Set<String> glues = getHookGlue(element);
if (element instanceof PsiDirectory) {
final PsiDirectory dir = (PsiDirectory) element;
final CucumberJvmExtensionPoint[] extensions = Extensions.getExtensions(CucumberJvmExtensionPoint.EP_NAME);
return new NullableComputable<String>() {
@Nullable
@Override
public String compute() {
dir.accept(new PsiElementVisitor() {
@Override
public void visitFile(final PsiFile file) {
if (file instanceof GherkinFile) {
for (CucumberJvmExtensionPoint extension : extensions) {
extension.getGlues((GherkinFile) file, glues);
}
}
}
@Override
public void visitDirectory(PsiDirectory dir) {
for (PsiDirectory subDir : dir.getSubdirectories()) {
subDir.accept(this);
}
for (PsiFile file : dir.getFiles()) {
file.accept(this);
}
}
});
return StringUtil.join(glues, " ");
}
};
}
return null;
}
use of com.intellij.psi.PsiElementVisitor in project android by JetBrains.
the class ThemeEditorStyle method getValueTag.
/**
* @param attribute The style attribute name.
* @return the XmlTag that contains the value for a given attribute in the current style.
*/
@Nullable
private /*if the attribute does not exist in this theme*/
XmlTag getValueTag(@NotNull XmlTag sourceTag, @NotNull final String attribute) {
if (!isProjectStyle()) {
// Non project styles do not contain local values.
return null;
}
final Ref<XmlTag> resultXmlTag = new Ref<XmlTag>();
ApplicationManager.getApplication().assertReadAccessAllowed();
sourceTag.acceptChildren(new PsiElementVisitor() {
@Override
public void visitElement(PsiElement element) {
super.visitElement(element);
if (!(element instanceof XmlTag)) {
return;
}
final XmlTag tag = (XmlTag) element;
if (SdkConstants.TAG_ITEM.equals(tag.getName()) && attribute.equals(tag.getAttributeValue(SdkConstants.ATTR_NAME))) {
resultXmlTag.set(tag);
}
}
});
return resultXmlTag.get();
}
Aggregations