Search in sources :

Example 36 with GrLiteral

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;
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrString(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString) GrLiteral(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral) Nullable(org.jetbrains.annotations.Nullable)

Example 37 with GrLiteral

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));
                }
            }
        }
    }
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) PsiLanguageInjectionHost(com.intellij.psi.PsiLanguageInjectionHost) GrLiteral(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral) PsiElement(com.intellij.psi.PsiElement)

Example 38 with GrLiteral

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;
}
Also used : GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) GrLiteral(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral) Nullable(org.jetbrains.annotations.Nullable)

Example 39 with GrLiteral

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);
}
Also used : GrLiteral(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral)

Example 40 with GrLiteral

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;
}
Also used : PropertyReference(com.intellij.lang.properties.references.PropertyReference) PsiReference(com.intellij.psi.PsiReference) GrLiteral(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GrLiteral (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral)45 Nullable (org.jetbrains.annotations.Nullable)14 PsiElement (com.intellij.psi.PsiElement)13 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)10 NonNls (org.jetbrains.annotations.NonNls)9 PsiType (com.intellij.psi.PsiType)6 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)6 GrString (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString)6 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)5 TextRange (com.intellij.openapi.util.TextRange)4 BigInteger (java.math.BigInteger)4 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)4 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)4 GrStringInjection (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringInjection)4 Document (com.intellij.openapi.editor.Document)3 Project (com.intellij.openapi.project.Project)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)3 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)3 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)3