use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class GrBracesSurrounder method doSurroundElements.
@Override
protected GroovyPsiElement doSurroundElements(PsiElement[] elements, PsiElement context) throws IncorrectOperationException {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(elements[0].getProject());
final PsiElement e0 = elements[0];
final PsiElement parent = e0.getParent();
final GrCodeBlock block;
if (parent instanceof GrControlStatement) {
block = factory.createMethodBodyFromText("\n");
final PsiElement prev = e0.getPrevSibling();
if (prev != null && prev.getNode().getElementType().equals(GroovyTokenTypes.mNLS)) {
final ASTNode parentNode = e0.getParent().getNode();
parentNode.addLeaf(TokenType.WHITE_SPACE, " ", prev.getNode());
parentNode.removeChild(prev.getNode());
}
} else {
block = factory.createClosureFromText("{}");
}
GroovyManyStatementsSurrounder.addStatements(block, elements);
return block;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class IfSurrounder method getSurroundSelectionRange.
@Override
protected TextRange getSurroundSelectionRange(GroovyPsiElement element) {
assert element instanceof GrIfStatement;
GrCondition condition = ((GrIfStatement) element).getCondition();
int endOffset = element.getTextRange().getEndOffset();
if (condition != null) {
PsiElement child = condition.getFirstChild();
assert child != null;
endOffset = child.getTextRange().getStartOffset();
condition.getParent().getNode().removeChild(condition.getNode());
}
return new TextRange(endOffset, endOffset);
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project android by JetBrains.
the class GradleEditorValueExtractor method visitGStringExpression.
@Override
public void visitGStringExpression(GrString expression) {
GroovyPsiElement[] parts = expression.getAllContentParts();
boolean registeredAssignment = false;
for (GroovyPsiElement part : parts) {
if (part instanceof GrStringContent) {
if (!myInterestedInReferencesOnly && !registeredAssignment && !part.getTextRange().isEmpty()) {
registeredAssignment = true;
String text = expression.getText();
TextRange range = expression.getTextRange();
if (text.startsWith("'") || text.startsWith("\"")) {
text = text.substring(1);
range = TextRange.create(range.getStartOffset() + 1, range.getEndOffset());
}
if (text.endsWith("'") || text.endsWith("\"")) {
text = text.substring(0, text.length() - 1);
range = TextRange.create(range.getStartOffset(), range.getEndOffset() - 1);
}
myContext.addCachedValue(text, range);
}
} else if (part instanceof GrStringInjection) {
GrExpression injectedExpression = ((GrStringInjection) part).getExpression();
if (injectedExpression != null) {
injectedExpression.accept(myVisitor);
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project android by JetBrains.
the class ApplyPluginTest method verifyAppliedPlugins.
private static void verifyAppliedPlugins(GradleBuildModel buildModel, String buildText) {
assertEquals("apply", ImmutableList.of("com.android.application", "com.android.library"), buildModel.appliedPlugins());
GroovyPsiElement buildFilePsiElement = buildModel.getPsiElement();
assertNotNull(buildFilePsiElement);
assertEquals("buildText", buildText, buildFilePsiElement.getText());
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project android by JetBrains.
the class GradleFileModelTestCase method verifyGradleValue.
public static void verifyGradleValue(@NotNull GradleNullableValue gradleValue, @NotNull String propertyName, @NotNull String propertyText, @NotNull String propertyFilePath) {
GroovyPsiElement psiElement = gradleValue.getPsiElement();
assertNotNull(psiElement);
assertEquals(propertyText, psiElement.getText());
assertEquals(propertyFilePath, toSystemIndependentName(gradleValue.getFile().getPath()));
assertEquals(propertyName, gradleValue.getPropertyName());
assertEquals(propertyText, gradleValue.getDslText());
}
Aggregations