use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class XmlTagImpl method getAttribute.
@Override
@Nullable
public XmlAttribute getAttribute(String qname) {
if (qname == null)
return null;
final XmlAttribute[] attributes = getAttributes();
final boolean caseSensitive = isCaseSensitive();
for (final XmlAttribute attribute : attributes) {
final ASTNode child = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild(attribute.getNode());
if (child instanceof LeafElement) {
final LeafElement attrNameElement = (LeafElement) child;
if ((caseSensitive && Comparing.equal(attrNameElement.getChars(), qname) || !caseSensitive && Comparing.equal(attrNameElement.getChars(), qname, false))) {
return attribute;
}
}
}
return null;
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class GroovyCompletionData method isControlStructure.
private static boolean isControlStructure(PsiElement context) {
final int offset = context.getTextRange().getStartOffset();
PsiElement prevSibling = context.getPrevSibling();
if (context.getParent() instanceof GrReferenceElement && prevSibling != null && prevSibling.getNode() != null) {
ASTNode node = prevSibling.getNode();
return !TokenSets.DOTS.contains(node.getElementType());
}
if (GroovyCompletionUtil.isNewStatement(context, true)) {
final PsiElement leaf = GroovyCompletionUtil.getLeafByOffset(offset - 1, context);
if (leaf != null && (leaf.getParent() instanceof GrStatementOwner || leaf.getParent() instanceof GrLabeledStatement)) {
return true;
}
}
if (context.getParent() != null) {
PsiElement parent = context.getParent();
if (parent instanceof GrExpression && parent.getParent() instanceof GroovyFile) {
return true;
}
if (parent instanceof GrReferenceExpression) {
PsiElement superParent = parent.getParent();
if (superParent instanceof GrStatementOwner || superParent instanceof GrLabeledStatement || superParent instanceof GrControlStatement || superParent instanceof GrMethodCall) {
return true;
}
}
return false;
}
return false;
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class GroovyCompletionData method suggestPrimitiveTypes.
private static boolean suggestPrimitiveTypes(PsiElement context) {
if (isInfixOperatorPosition(context))
return false;
if (isAfterForParameter(context))
return false;
final PsiElement parent = context.getParent();
if (parent == null)
return false;
PsiElement previous = PsiImplUtil.realPrevious(parent.getPrevSibling());
if (parent instanceof GrReferenceElement && parent.getParent() instanceof GrArgumentList) {
PsiElement prevSibling = context.getPrevSibling();
if (prevSibling != null && prevSibling.getNode() != null) {
if (!TokenSets.DOTS.contains(prevSibling.getNode().getElementType())) {
return true;
}
} else if (!(previous != null && GroovyTokenTypes.mAT.equals(previous.getNode().getElementType()))) {
return true;
}
}
if (GroovyCompletionUtil.isTupleVarNameWithoutTypeDeclared(context))
return true;
if (previous != null && GroovyTokenTypes.mAT.equals(previous.getNode().getElementType())) {
return false;
}
if (GroovyCompletionUtil.asSimpleVariable(context) || GroovyCompletionUtil.asTypedMethod(context) || GroovyCompletionUtil.asVariableInBlock(context) || asVariableAfterModifiers(context)) {
return true;
}
if ((parent instanceof GrParameter && ((GrParameter) parent).getTypeElementGroovy() == null) || parent instanceof GrReferenceElement && !(parent.getParent() instanceof GrImportStatement) && !(parent.getParent() instanceof GrPackageDefinition) && !(parent.getParent() instanceof GrArgumentList)) {
PsiElement prevSibling = context.getPrevSibling();
if (parent instanceof GrReferenceElement && prevSibling != null && prevSibling.getNode() != null) {
ASTNode node = prevSibling.getNode();
return !TokenSets.DOTS.contains(node.getElementType());
} else {
return true;
}
}
if (PsiImplUtil.realPrevious(parent.getPrevSibling()) instanceof GrModifierList) {
return true;
}
if (PsiImplUtil.realPrevious(context.getPrevSibling()) instanceof GrModifierList) {
return true;
}
return parent instanceof GrExpression && parent.getParent() instanceof GroovyFile && GroovyCompletionUtil.isNewStatement(context, false);
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class GroovySpacingProcessor method visitClosure.
@Override
public void visitClosure(@NotNull GrClosableBlock closure) {
ASTNode rBraceAtTheEnd = GeeseUtil.getClosureRBraceAtTheEnd(myChild1);
if (myGroovySettings.USE_FLYING_GEESE_BRACES && myType2 == GroovyTokenTypes.mRCURLY && rBraceAtTheEnd != null) {
String text = rBraceAtTheEnd.getTreeParent().getText();
if (text.indexOf('\n') < 0) {
/* the case:
foo {
bar {print x}<we are here>}
*/
myResult = Spacing.createSpacing(1, 1, 1, false, 1);
} else {
myResult = Spacing.createSpacing(0, 0, 0, true, 100, 0);
}
} else if (myType1 == GroovyTokenTypes.mLCURLY && myType2 == GroovyTokenTypes.mRCURLY) {
//empty closure
createSpaceInCode(false);
} else if (myType1 == GroovyTokenTypes.mLCURLY && myType2 != GroovyElementTypes.PARAMETERS_LIST && myType2 != GroovyTokenTypes.mCLOSABLE_BLOCK_OP || myType2 == GroovyTokenTypes.mRCURLY) {
//spaces between statements
boolean spacesWithinBraces = closure.getParent() instanceof GrStringInjection ? myGroovySettings.SPACE_WITHIN_GSTRING_INJECTION_BRACES : mySettings.SPACE_WITHIN_BRACES;
createDependentLFSpacing(true, spacesWithinBraces, closure.getTextRange());
} else if (myType1 == GroovyTokenTypes.mCLOSABLE_BLOCK_OP) {
myResult = GroovySpacingProcessorBasic.createDependentSpacingForClosure(mySettings, myGroovySettings, closure, true);
} else if (myType1 == GroovyTokenTypes.mLCURLY && (myType2 == GroovyElementTypes.PARAMETERS_LIST || myType2 == GroovyTokenTypes.mCLOSABLE_BLOCK_OP)) {
boolean spacesWithinBraces = closure.getParent() instanceof GrStringInjection ? myGroovySettings.SPACE_WITHIN_GSTRING_INJECTION_BRACES : mySettings.SPACE_WITHIN_BRACES;
createSpaceInCode(spacesWithinBraces);
}
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class GroovySpacingProcessor method _init.
private void _init(@Nullable final ASTNode child) {
if (child == null)
return;
ASTNode treePrev = child.getTreePrev();
while (treePrev != null && isWhiteSpace(treePrev)) {
treePrev = treePrev.getTreePrev();
}
if (treePrev == null) {
_init(child.getTreeParent());
} else {
myChild2 = child;
myType2 = myChild2.getElementType();
myChild1 = treePrev;
myType1 = myChild1.getElementType();
final CompositeElement parent = (CompositeElement) treePrev.getTreeParent();
myParent = SourceTreeToPsiMap.treeElementToPsi(parent);
}
}
Aggregations