use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral in project android by JetBrains.
the class GradleDslLiteral method createLiteral.
@Nullable
private GrLiteral createLiteral() {
if (myUnsavedValue == null) {
return null;
}
CharSequence unsavedValueText = null;
if (myUnsavedValue instanceof String) {
unsavedValueText = GrStringUtil.getLiteralTextByValue((String) myUnsavedValue);
} else if (myUnsavedValue instanceof Integer || myUnsavedValue instanceof Boolean) {
unsavedValueText = myUnsavedValue.toString();
}
myUnsavedValue = null;
if (unsavedValueText == null) {
return null;
}
GroovyPsiElementFactory factory = getPsiElementFactory();
if (factory == null) {
return null;
}
GrExpression newExpression = factory.createExpressionFromText(unsavedValueText);
if (!(newExpression instanceof GrLiteral)) {
return null;
}
return (GrLiteral) newExpression;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral in project intellij-plugins by JetBrains.
the class GrCucumberStepDeclarationSearcher method findDeclarationsAt.
@Override
public void findDeclarationsAt(@NotNull PsiElement element, int offsetInElement, Consumer<PomTarget> consumer) {
PsiLanguageInjectionHost host = InjectedLanguageManager.getInstance(element.getProject()).getInjectionHost(element);
if (host != null) {
element = host;
}
if (element.getParent() instanceof GrLiteral) {
element = element.getParent();
}
if (element instanceof GrLiteral) {
//~literal
final PsiElement parent = element.getParent();
if (parent != null) {
//(~literal)
final PsiElement pparent = parent.getParent();
if (pparent != null) {
//When(~literal)
final PsiElement ppparent = pparent.getParent();
if (ppparent instanceof GrMethodCall && GrCucumberUtil.isStepDefinition(ppparent)) {
final GrMethodCall methodCall = (GrMethodCall) ppparent;
consumer.consume(GrStepDefinition.getStepDefinition(methodCall));
}
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral in project intellij-community by JetBrains.
the class ImportMavenRepositoriesTask method resolveUriFromSimpleExpression.
@Nullable
private static URI resolveUriFromSimpleExpression(@Nullable GrExpression expression) {
if (expression == null)
return null;
try {
if (expression instanceof PsiLiteral) {
URI uri = new URI(String.valueOf(PsiLiteral.class.cast(expression).getValue()));
if (uri.getScheme() != null && StringUtil.startsWith(uri.getScheme(), "http"))
return uri;
}
} catch (URISyntaxException ignored) {
// ignore it
}
try {
PsiReference reference = expression.getReference();
if (reference == null)
return null;
PsiElement element = reference.resolve();
if (element instanceof GrVariable) {
List<GrLiteral> grLiterals = PsiTreeUtil.getChildrenOfTypeAsList(element, GrLiteral.class);
if (grLiterals.isEmpty())
return null;
URI uri = new URI(String.valueOf(grLiterals.get(0).getValue()));
if (uri.getScheme() != null && StringUtil.startsWith("http", uri.getScheme()))
return uri;
}
} catch (URISyntaxException ignored) {
// ignore it
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral in project intellij-community by JetBrains.
the class GrConcatenationInjector method getLanguagesToInject.
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) {
assert context instanceof GrLiteral;
final GrLiteral literal = (GrLiteral) context;
processInPlace(registrar, literal);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral in project intellij-community by JetBrains.
the class PropertiesReferenceProvider method getReferencesByElement.
@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
Object value = null;
if (element instanceof GrLiteral) {
GrLiteral literalExpression = (GrLiteral) element;
value = literalExpression.getValue();
//final Map<String, Object> annotationParams = new HashMap<String, Object>();
//annotationParams.put(AnnotationUtil.PROPERTY_KEY_RESOURCE_BUNDLE_PARAMETER, null);
/*if (JavaI18nUtil.mustBePropertyKey(literalExpression, annotationParams)) {
soft = false;
final Object resourceBundleName = annotationParams.get(AnnotationUtil.PROPERTY_KEY_RESOURCE_BUNDLE_PARAMETER);
if (resourceBundleName instanceof PsiExpression) {
PsiExpression expr = (PsiExpression)resourceBundleName;
final Object bundleValue = expr.getManager().getConstantEvaluationHelper().computeConstantExpression(expr);
bundleName = bundleValue == null ? null : bundleValue.toString();
}
}*/
}
if (value instanceof String && !((String) value).contains("\n")) {
return new PsiReference[] { new PropertyReference((String) value, element, null, true) };
}
return PsiReference.EMPTY_ARRAY;
}
Aggregations