use of org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase in project intellij-community by JetBrains.
the class GrJoinBlockStatementHandler method tryJoinLines.
@Override
public int tryJoinLines(Document document, PsiFile file, int start, int end) {
if (!(file instanceof GroovyFileBase))
return CANNOT_JOIN;
final PsiElement startElement = file.findElementAt(start);
if (startElement == null || startElement.getNode().getElementType() != GroovyTokenTypes.mLCURLY)
return CANNOT_JOIN;
final PsiElement parent = startElement.getParent();
if (!(parent instanceof GrOpenBlock))
return CANNOT_JOIN;
final GrStatement[] statements = ((GrOpenBlock) parent).getStatements();
if (statements.length != 1)
return CANNOT_JOIN;
final PsiElement parent1 = parent.getParent();
if (!(parent1 instanceof GrBlockStatement))
return CANNOT_JOIN;
final PsiElement parent2 = parent1.getParent();
if (!(parent2 instanceof GrIfStatement) && !(parent2 instanceof GrWhileStatement) && !(parent2 instanceof GrForStatement)) {
return CANNOT_JOIN;
}
final GrStatement statement = ((GrBlockStatement) parent1).replaceWithStatement(statements[0]);
return statement.getTextRange().getStartOffset();
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase in project intellij-community by JetBrains.
the class GrJoinControlStatementHandler method tryJoinLines.
@Override
public int tryJoinLines(Document document, PsiFile file, int start, int end) {
if (!(file instanceof GroovyFileBase))
return CANNOT_JOIN;
final PsiElement startElement = file.findElementAt(start);
if (startElement == null || !startElement.getNode().getElementType().equals(GroovyTokenTypes.mRPAREN))
return CANNOT_JOIN;
final PsiElement parent = startElement.getParent();
if (!(parent instanceof GrIfStatement || parent instanceof GrWhileStatement || parent instanceof GrForStatement))
return CANNOT_JOIN;
GrStatement inner;
if (parent instanceof GrIfStatement) {
inner = ((GrIfStatement) parent).getThenBranch();
} else if (parent instanceof GrWhileStatement) {
inner = ((GrWhileStatement) parent).getBody();
} else /*if (parent instanceof GrForStatement)*/
{
inner = ((GrForStatement) parent).getBody();
}
if (inner instanceof GrBlockStatement)
return CANNOT_JOIN;
document.replaceString(start + 1, end, " ");
return start + 2;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase in project intellij-community by JetBrains.
the class GrJoinLinesHandlerBase method tryJoinRawLines.
@Override
public int tryJoinRawLines(Document document, PsiFile file, int start, int end) {
if (!(file instanceof GroovyFileBase))
return CANNOT_JOIN;
final PsiElement element = file.findElementAt(end);
final GrStatementOwner statementOwner = PsiTreeUtil.getParentOfType(element, GrStatementOwner.class, true, GroovyFileBase.class);
if (statementOwner == null)
return CANNOT_JOIN;
GrStatement first = null;
GrStatement last = null;
for (PsiElement child = statementOwner.getFirstChild(); child != null; child = child.getNextSibling()) {
final TextRange range = child.getTextRange();
if (range.getEndOffset() == start) {
first = skipSemicolonsAndWhitespaces(child, BACK);
} else if (range.getStartOffset() == end) {
last = skipSemicolonsAndWhitespaces(child, FORWARD);
}
}
if (last == null || first == null)
return CANNOT_JOIN;
return tryJoinStatements(first, last);
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase in project intellij-community by JetBrains.
the class GrIntroduceValidatorEngine method isOKImpl.
private MultiMap<PsiElement, String> isOKImpl(String varName, boolean replaceAllOccurrences) {
PsiElement firstOccurrence = getFirstOccurrence(replaceAllOccurrences);
final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
assert varName != null;
final int offset = firstOccurrence.getTextRange().getStartOffset();
validateOccurrencesDown(myContext.getScope(), conflicts, varName, offset);
if (!(myContext.getScope() instanceof GroovyFileBase)) {
validateVariableOccurrencesUp(myContext.getScope(), conflicts, varName, offset);
}
if (replaceAllOccurrences) {
for (PsiElement element : myContext.getOccurrences()) {
if (element == firstOccurrence)
continue;
validateVariableOccurrencesUp(element, conflicts, varName, element.getTextRange().getStartOffset());
}
}
return conflicts;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase in project intellij-community by JetBrains.
the class MavenGroovyPomCompletionWeigher method weigh.
@Override
public Comparable weigh(@NotNull LookupElement element, @NotNull CompletionLocation location) {
PsiFile containingFile = location.getCompletionParameters().getPosition().getContainingFile();
if (!(containingFile instanceof GroovyFileBase)) {
return null;
}
if (!"pom.groovy".equals(containingFile.getName()))
return null;
Object o = element.getObject();
if (o instanceof ResolveResult) {
o = ((ResolveResult) o).getElement();
}
if (o instanceof DynamicMemberUtils.DynamicElement) {
return 1;
} else {
return -1;
}
}
Aggregations