use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class CheckEmptyTagInspection method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new XmlElementVisitor() {
@Override
public void visitXmlTag(final XmlTag tag) {
if (!isTagWithEmptyEndNotAllowed(tag)) {
return;
}
final ASTNode child = XmlChildRole.EMPTY_TAG_END_FINDER.findChild(tag.getNode());
if (child == null) {
return;
}
final LocalQuickFix fix = new MyLocalQuickFix();
holder.registerProblem(tag, XmlBundle.message("html.inspections.check.empty.script.message"), tag.getContainingFile().getContext() != null ? ProblemHighlightType.INFORMATION : ProblemHighlightType.GENERIC_ERROR_OR_WARNING, fix);
}
};
}
use of com.intellij.lang.ASTNode in project kotlin by JetBrains.
the class KotlinInplaceVariableIntroducer method runWriteActionAndRestartRefactoring.
protected final void runWriteActionAndRestartRefactoring(final Runnable runnable) {
final Ref<Boolean> greedyToRight = new Ref<Boolean>();
new WriteCommandAction(myProject, getCommandName(), getCommandName()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument());
ASTNode identifier = myDeclaration.getNode().findChildByType(KtTokens.IDENTIFIER);
if (identifier != null) {
TextRange range = identifier.getTextRange();
RangeHighlighter[] highlighters = myEditor.getMarkupModel().getAllHighlighters();
for (RangeHighlighter highlighter : highlighters) {
if (highlighter.getStartOffset() == range.getStartOffset()) {
if (highlighter.getEndOffset() == range.getEndOffset()) {
greedyToRight.set(highlighter.isGreedyToRight());
highlighter.setGreedyToRight(false);
}
}
}
}
runnable.run();
TemplateState templateState = TemplateManagerImpl.getTemplateState(InjectedLanguageUtil.getTopLevelEditor(myEditor));
if (templateState != null) {
myEditor.putUserData(INTRODUCE_RESTART, true);
templateState.cancelTemplate();
}
}
}.execute();
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
ASTNode identifier = myDeclaration.getNode().findChildByType(KtTokens.IDENTIFIER);
if (identifier != null) {
TextRange range = identifier.getTextRange();
RangeHighlighter[] highlighters = myEditor.getMarkupModel().getAllHighlighters();
for (RangeHighlighter highlighter : highlighters) {
if (highlighter.getStartOffset() == range.getStartOffset()) {
if (highlighter.getEndOffset() == range.getEndOffset()) {
highlighter.setGreedyToRight(greedyToRight.get());
}
}
}
}
}
});
if (myEditor.getUserData(INTRODUCE_RESTART) == Boolean.TRUE) {
myInitialName = myDeclaration.getName();
performInplaceRefactoring(getSuggestionsForNextRun());
}
}
use of com.intellij.lang.ASTNode in project kotlin by JetBrains.
the class KtInvokeFunctionReference method getRanges.
@Override
public List<TextRange> getRanges() {
List<TextRange> list = new ArrayList<TextRange>();
KtValueArgumentList valueArgumentList = getExpression().getValueArgumentList();
if (valueArgumentList != null) {
if (valueArgumentList.getArguments().size() > 0) {
ASTNode valueArgumentListNode = valueArgumentList.getNode();
ASTNode lPar = valueArgumentListNode.findChildByType(KtTokens.LPAR);
if (lPar != null) {
list.add(getRange(lPar));
}
ASTNode rPar = valueArgumentListNode.findChildByType(KtTokens.RPAR);
if (rPar != null) {
list.add(getRange(rPar));
}
} else {
list.add(getRange(valueArgumentList.getNode()));
}
}
List<KtLambdaArgument> functionLiteralArguments = getExpression().getLambdaArguments();
for (KtLambdaArgument functionLiteralArgument : functionLiteralArguments) {
KtLambdaExpression functionLiteralExpression = functionLiteralArgument.getLambdaExpression();
list.add(getRange(functionLiteralExpression.getLeftCurlyBrace()));
ASTNode rightCurlyBrace = functionLiteralExpression.getRightCurlyBrace();
if (rightCurlyBrace != null) {
list.add(getRange(rightCurlyBrace));
}
}
return list;
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class ExpressionGenerator method visitBuiltinTypeClassExpression.
@Override
public void visitBuiltinTypeClassExpression(@NotNull GrBuiltinTypeClassExpression expression) {
PsiElement firstChild = expression.getFirstChild();
LOG.assertTrue(firstChild != null);
ASTNode node = firstChild.getNode();
LOG.assertTrue(node != null);
final IElementType type = node.getElementType();
final String boxed = TypesUtil.getBoxedTypeName(type);
builder.append(boxed);
if (expression.getParent() instanceof GrIndexProperty) {
builder.append("[]");
}
builder.append(".class");
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class I18nMessageGotoDeclarationHandler method getGotoDeclarationTarget.
@Override
public PsiElement getGotoDeclarationTarget(@Nullable PsiElement element, Editor editor) {
if (!(element instanceof PsiJavaToken))
return null;
//some street magic
int i = 4;
while (element != null && i > 0) {
final ASTNode node = element.getNode();
if (node != null && node.getUserData(KEY) instanceof PropertyFoldingBuilder) {
break;
} else {
i--;
element = element.getParent();
}
}
//case: "literalAnnotatedWithPropertyKey"
if (element instanceof PsiLiteralExpression) {
return resolve(element);
}
//case: MyBundle.message("literalAnnotatedWithPropertyKey", param1, param2)
if (element instanceof PsiMethodCallExpression) {
final PsiMethodCallExpression methodCall = (PsiMethodCallExpression) element;
FoldRegion foldRegion = null;
for (FoldRegion region : editor.getFoldingModel().getAllFoldRegions()) {
final PsiElement psiElement = EditorFoldingInfo.get(editor).getPsiElement(region);
if (methodCall.equals(psiElement)) {
foldRegion = region;
}
}
if (foldRegion == null || foldRegion.isExpanded())
return null;
for (PsiExpression expression : methodCall.getArgumentList().getExpressions()) {
if (expression instanceof PsiLiteralExpression && PropertyFoldingBuilder.isI18nProperty((PsiLiteralExpression) expression)) {
return resolve(expression);
}
}
}
return null;
}
Aggregations