use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class GrLabelBlock method createTextRange.
private static TextRange createTextRange(List<ASTNode> subStatements) {
ASTNode first = subStatements.get(0);
ASTNode last = subStatements.get(subStatements.size() - 1);
return new TextRange(first.getTextRange().getStartOffset(), last.getTextRange().getEndOffset());
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class GroovyBlock method getChildAttributes.
@Override
@NotNull
public ChildAttributes getChildAttributes(final int newChildIndex) {
ASTNode astNode = getNode();
final PsiElement psiParent = astNode.getPsi();
if (psiParent instanceof GroovyFileBase) {
return new ChildAttributes(Indent.getNoneIndent(), null);
}
if (psiParent instanceof GrSwitchStatement) {
List<Block> subBlocks = getSubBlocks();
if (newChildIndex > 0) {
Block block = subBlocks.get(newChildIndex - 1);
if (block instanceof GroovyBlock) {
PsiElement anchorPsi = ((GroovyBlock) block).getNode().getPsi();
if (anchorPsi instanceof GrCaseSection) {
for (GrStatement statement : ((GrCaseSection) anchorPsi).getStatements()) {
if (statement instanceof GrBreakStatement || statement instanceof GrContinueStatement || statement instanceof GrReturnStatement || statement instanceof GrThrowStatement) {
final Indent indent = GroovyIndentProcessor.getSwitchCaseIndent(myContext.getSettings());
return new ChildAttributes(indent, null);
}
}
int indentSize = myContext.getSettings().getIndentOptions().INDENT_SIZE;
final int spaces = myContext.getSettings().INDENT_CASE_FROM_SWITCH ? 2 * indentSize : indentSize;
return new ChildAttributes(Indent.getSpaceIndent(spaces), null);
}
}
}
}
if (psiParent instanceof GrCaseLabel) {
return new ChildAttributes(GroovyIndentProcessor.getSwitchCaseIndent(getContext().getSettings()), null);
}
if (psiParent instanceof GrCaseSection) {
return getSwitchIndent((GrCaseSection) psiParent, newChildIndex);
}
if (TokenSets.BLOCK_SET.contains(astNode.getElementType()) || GroovyElementTypes.SWITCH_STATEMENT.equals(astNode.getElementType())) {
return new ChildAttributes(Indent.getNormalIndent(), null);
}
if (GroovyElementTypes.CASE_SECTION.equals(astNode.getElementType())) {
return new ChildAttributes(Indent.getNormalIndent(), null);
}
if (psiParent instanceof GrBinaryExpression || psiParent instanceof GrConditionalExpression || psiParent instanceof GrCommandArgumentList || psiParent instanceof GrArgumentList || psiParent instanceof GrParameterList || psiParent instanceof GrListOrMap || psiParent instanceof GrAnnotationArgumentList || psiParent instanceof GrVariable || psiParent instanceof GrAssignmentExpression) {
return new ChildAttributes(Indent.getContinuationWithoutFirstIndent(), null);
}
if (psiParent instanceof GrDocComment || psiParent instanceof GrDocTag) {
return new ChildAttributes(Indent.getSpaceIndent(GroovyIndentProcessor.GDOC_COMMENT_INDENT), null);
}
if (psiParent instanceof GrIfStatement || psiParent instanceof GrLoopStatement) {
return new ChildAttributes(Indent.getNormalIndent(), null);
}
if (psiParent instanceof GrLabeledStatement && newChildIndex == 2) {
final Indent indent = getContext().getGroovySettings().INDENT_LABEL_BLOCKS ? Indent.getLabelIndent() : Indent.getNoneIndent();
return new ChildAttributes(indent, null);
}
return new ChildAttributes(Indent.getNoneIndent(), null);
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class GantUtils method isPlainIdentifier.
public static boolean isPlainIdentifier(final GrArgumentLabel label) {
final PsiElement elem = label.getNameElement();
final ASTNode node = elem.getNode();
if (node == null)
return false;
return node.getElementType() == GroovyTokenTypes.mIDENT;
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class ImportReferenceProvider method getReferencesByElement.
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
if (element instanceof XmlProcessingInstruction) {
final ASTNode importNode = element.getNode().findChildByType(XmlTokenType.XML_TAG_CHARACTERS);
if (importNode != null) {
final PsiElement importInstr = importNode.getPsi();
final String instructionTarget = JavaFxPsiUtil.getInstructionTarget("import", (XmlProcessingInstruction) element);
if (instructionTarget != null && instructionTarget.equals(importInstr.getText())) {
final PsiReference[] references = FxmlReferencesContributor.CLASS_REFERENCE_PROVIDER.getReferencesByString(instructionTarget, element, importInstr.getStartOffsetInParent());
if (instructionTarget.endsWith(".*")) {
return ArrayUtil.remove(references, references.length - 1);
} else {
return references;
}
}
}
}
return PsiReference.EMPTY_ARRAY;
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class JavaFxAnnotator method annotate.
@Override
public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) {
final PsiFile containingFile = element.getContainingFile();
if (!JavaFxFileTypeFactory.isFxml(containingFile))
return;
if (element instanceof XmlAttributeValue) {
final String value = ((XmlAttributeValue) element).getValue();
if (!JavaFxPsiUtil.isExpressionBinding(value) && !JavaFxPsiUtil.isIncorrectExpressionBinding(value)) {
final PsiReference[] references = element.getReferences();
for (PsiReference reference : references) {
if (reference instanceof JavaFxColorReference) {
attachColorIcon(element, holder, StringUtil.unquoteString(element.getText()));
continue;
}
final PsiElement resolve = reference.resolve();
if (resolve instanceof PsiMember) {
if (!JavaFxPsiUtil.isVisibleInFxml((PsiMember) resolve)) {
final String symbolPresentation = "'" + SymbolPresentationUtil.getSymbolPresentableText(resolve) + "'";
final Annotation annotation = holder.createErrorAnnotation(element, symbolPresentation + (resolve instanceof PsiClass ? " should be public" : " should be public or annotated with @FXML"));
if (!(resolve instanceof PsiClass)) {
annotation.registerUniversalFix(new AddAnnotationFix(JavaFxCommonNames.JAVAFX_FXML_ANNOTATION, (PsiMember) resolve, ArrayUtil.EMPTY_STRING_ARRAY), null, null);
}
}
}
}
}
} else if (element instanceof XmlAttribute) {
final XmlAttribute attribute = (XmlAttribute) element;
final String attributeName = attribute.getName();
if (!FxmlConstants.FX_BUILT_IN_ATTRIBUTES.contains(attributeName) && !attribute.isNamespaceDeclaration() && JavaFxPsiUtil.isReadOnly(attributeName, attribute.getParent())) {
holder.createErrorAnnotation(element.getNavigationElement(), "Property '" + attributeName + "' is read-only");
}
if (FxmlConstants.SOURCE.equals(attributeName)) {
final XmlAttributeValue valueElement = attribute.getValueElement();
if (valueElement != null) {
final XmlTag xmlTag = attribute.getParent();
if (xmlTag != null) {
final XmlTag referencedTag = JavaFxBuiltInTagDescriptor.getReferencedTag(xmlTag);
if (referencedTag != null) {
if (referencedTag.getTextOffset() > xmlTag.getTextOffset()) {
holder.createErrorAnnotation(valueElement.getValueTextRange(), valueElement.getValue() + " not found");
} else if (xmlTag.getParentTag() == referencedTag.getParentTag()) {
final Annotation annotation = holder.createErrorAnnotation(valueElement.getValueTextRange(), "Duplicate child added");
annotation.registerFix(new JavaFxWrapWithDefineIntention(referencedTag, valueElement.getValue()));
}
}
}
}
}
} else if (element instanceof XmlTag) {
if (FxmlConstants.FX_SCRIPT.equals(((XmlTag) element).getName())) {
final XmlTagValue tagValue = ((XmlTag) element).getValue();
if (!StringUtil.isEmptyOrSpaces(tagValue.getText())) {
final List<String> langs = JavaFxPsiUtil.parseInjectedLanguages((XmlFile) element.getContainingFile());
if (langs.isEmpty()) {
final ASTNode openTag = element.getNode().findChildByType(XmlTokenType.XML_NAME);
final Annotation annotation = holder.createErrorAnnotation(openTag != null ? openTag.getPsi() : element, "Page language not specified.");
annotation.registerFix(new JavaFxInjectPageLanguageIntention());
}
}
}
}
}
Aggregations