use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringInjection in project intellij-community by JetBrains.
the class GrIntroduceHandlerBase method findAnchor.
@Nullable
public static PsiElement findAnchor(@NotNull PsiElement[] occurrences, @NotNull PsiElement container) {
if (occurrences.length == 0)
return null;
PsiElement candidate;
if (occurrences.length == 1) {
candidate = findContainingStatement(occurrences[0]);
} else {
candidate = occurrences[0];
while (candidate != null && candidate.getParent() != container) {
candidate = candidate.getParent();
}
}
final GrStringInjection injection = PsiTreeUtil.getParentOfType(candidate, GrStringInjection.class);
if (injection != null && !injection.getText().contains("\n")) {
candidate = findContainingStatement(injection);
}
if (candidate == null)
return null;
if ((container instanceof GrWhileStatement) && candidate.equals(((GrWhileStatement) container).getCondition())) {
return container;
}
if ((container instanceof GrIfStatement) && candidate.equals(((GrIfStatement) container).getCondition())) {
return container;
}
if ((container instanceof GrForStatement) && candidate.equals(((GrForStatement) container).getClause())) {
return container;
}
while (candidate instanceof GrIfStatement && candidate.getParent() instanceof GrIfStatement && ((GrIfStatement) candidate.getParent()).getElseBranch() == candidate) {
candidate = candidate.getParent();
}
return candidate;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringInjection in project android by JetBrains.
the class GradleDslLiteral method getValue.
@Override
@Nullable
public Object getValue() {
if (myUnsavedValue != null) {
return myUnsavedValue;
}
if (myExpression == null) {
return null;
}
Object value = ((GrLiteral) myExpression).getValue();
if (value != null) {
return value;
}
if (myExpression instanceof GrString) {
// String literal with variables. ex: compileSdkVersion = "$ANDROID-${VERSION}"
String literalText = myExpression.getText();
if (isQuotedString(literalText)) {
literalText = unquoteString(literalText);
}
List<GradleResolvedVariable> resolvedVariables = Lists.newArrayList();
GrStringInjection[] injections = ((GrString) myExpression).getInjections();
for (GrStringInjection injection : injections) {
String variableName = null;
GrClosableBlock closableBlock = injection.getClosableBlock();
if (closableBlock != null) {
String blockText = closableBlock.getText();
variableName = blockText.substring(1, blockText.length() - 1);
} else {
GrExpression expression = injection.getExpression();
if (expression != null) {
variableName = expression.getText();
}
}
if (!isEmpty(variableName)) {
GradleDslExpression resolvedExpression = resolveReference(variableName, GradleDslExpression.class);
if (resolvedExpression != null) {
Object resolvedValue = resolvedExpression.getValue();
if (resolvedValue != null) {
resolvedVariables.add(new GradleResolvedVariable(variableName, resolvedValue, resolvedExpression));
literalText = literalText.replace(injection.getText(), resolvedValue.toString());
}
}
}
}
setResolvedVariables(resolvedVariables);
return literalText;
}
return null;
}
Aggregations