当前位置: 首页>>代码示例>>Java>>正文


Java PsiLiteralExpression类代码示例

本文整理汇总了Java中com.intellij.psi.PsiLiteralExpression的典型用法代码示例。如果您正苦于以下问题:Java PsiLiteralExpression类的具体用法?Java PsiLiteralExpression怎么用?Java PsiLiteralExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PsiLiteralExpression类属于com.intellij.psi包,在下文中一共展示了PsiLiteralExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerReferenceProviders

import com.intellij.psi.PsiLiteralExpression; //导入依赖的package包/类
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class),
            new PsiReferenceProvider() {
                @NotNull
                @Override
                public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
                    if (isLiteralOfConfigurationAnnotation(element) || isCoffigMethod(element)) {
                        PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
                        String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null;
                        List<PsiReference> psiReferences = resolvePsiReferences(element, value, 1);
                        return psiReferences.toArray(new PsiReference[psiReferences.size()]);
                    }
                    return PsiReference.EMPTY_ARRAY;
                }
            });
}
 
开发者ID:seedstack,项目名称:intellij-plugin,代码行数:18,代码来源:CoffigJavaReferenceContributor.java

示例2: extractTextFromElement

import com.intellij.psi.PsiLiteralExpression; //导入依赖的package包/类
@Override
public Optional<String> extractTextFromElement(PsiElement element, boolean concatString, boolean stripWhitespace) {
    if (element instanceof PsiLiteralExpression) {
        // need the entire line so find the literal expression that would hold the entire string (java)
        PsiLiteralExpression literal = (PsiLiteralExpression) element;
        Object o = literal.getValue();
        String text = o != null ? o.toString() : null;
        if (text == null) {
            return Optional.empty();
        }
        if (concatString) {
            final PsiPolyadicExpression parentOfType = PsiTreeUtil.getParentOfType(element, PsiPolyadicExpression.class);
            if (parentOfType != null) {
                text = parentOfType.getText();
            }
        }
        // unwrap literal string which can happen in java too
        if (stripWhitespace) {
            return Optional.ofNullable(getInnerText(text));
        }
        return Optional.of(StringUtil.unquoteString(text.replace(QUOT, "\"")));
    }
    return Optional.empty();
}
 
开发者ID:camel-idea-plugin,项目名称:camel-idea-plugin,代码行数:25,代码来源:JavaIdeaUtils.java

示例3: testGenerateDoc

import com.intellij.psi.PsiLiteralExpression; //导入依赖的package包/类
public void testGenerateDoc() throws Exception {
    myFixture.configureByText(JavaFileType.INSTANCE, getJavaTestDataWithCursorAfterQuestionMark());

    PsiElement element = myFixture.findElementByText("\"file:inbox?\"", PsiLiteralExpression.class);
    String componentName = "file";
    String lookup = componentName + ":inbox?delete";
    PsiManager manager = myFixture.getPsiManager();

    PsiElement docInfo = new CamelDocumentationProvider().getDocumentationElementForLookupItem(manager, lookup, element);

    String doc = new CamelDocumentationProvider().generateDoc(docInfo, null);
    assertEquals(readExpectedFile(), doc);

    String documentation = new CamelDocumentationProvider().generateDoc(element, null);
    assertNotNull(documentation);
    assertTrue(documentation.startsWith("<b>File Component</b><br/>The file component is used for reading or writing files.<br/>"));
}
 
开发者ID:camel-idea-plugin,项目名称:camel-idea-plugin,代码行数:18,代码来源:CamelDocumentationProviderTestIT.java

示例4: tokenize

import com.intellij.psi.PsiLiteralExpression; //导入依赖的package包/类
@Override
public void tokenize(@NotNull PsiLiteralExpression element, TokenConsumer consumer) {
  PsiLiteralExpressionImpl literalExpression = (PsiLiteralExpressionImpl)element;
  if (literalExpression.getLiteralElementType() != JavaTokenType.STRING_LITERAL) return;  // not a string literal

  String text = literalExpression.getInnerText();
  if (StringUtil.isEmpty(text) || text.length() <= 2) { // optimisation to avoid expensive injection check
    return;
  }
  if (InjectedLanguageUtil.hasInjections(literalExpression)) return;

  final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(element, PsiModifierListOwner.class);
  if (listOwner != null && AnnotationUtil.isAnnotated(listOwner, Collections.singleton(AnnotationUtil.NON_NLS), false, false)) {
    return;
  }

  if (!text.contains("\\")) {
    consumer.consumeToken(element, PlainTextSplitter.getInstance());
  }
  else {
    processTextWithEscapeSequences(element, text, consumer);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:LiteralExpressionTokenizer.java

示例5: getTokenizer

import com.intellij.psi.PsiLiteralExpression; //导入依赖的package包/类
@NotNull
@Override
public Tokenizer getTokenizer(PsiElement element) {
  if (element instanceof PsiMethod) {
    return myMethodNameTokenizer;
  }
  if (element instanceof PsiDocComment) {
    return myDocCommentTokenizer;
  }
  if (element instanceof PsiLiteralExpression) {
    if (SuppressManager.isSuppressedInspectionName((PsiLiteralExpression)element)) {
      return EMPTY_TOKENIZER;
    }
    return myLiteralExpressionTokenizer;
  }
  if (element instanceof PsiNamedElement) {
    return myNamedElementTokenizer;
  }

  return super.getTokenizer(element);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:JavaSpellcheckingStrategy.java

示例6: isPowerOfTwo

import com.intellij.psi.PsiLiteralExpression; //导入依赖的package包/类
public static boolean isPowerOfTwo(PsiExpression rhs) {
  if (!(rhs instanceof PsiLiteralExpression)) {
    return false;
  }
  final PsiLiteralExpression literal = (PsiLiteralExpression)rhs;
  final Object value = literal.getValue();
  if (!(value instanceof Number)) {
    return false;
  }
  if (value instanceof Double || value instanceof Float) {
    return false;
  }
  int intValue = ((Number)value).intValue();
  if (intValue <= 1) {
    return false;
  }
  while (intValue % 2 == 0) {
    intValue >>= 1;
  }
  return intValue == 1;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:ShiftUtils.java

示例7: visitLiteralExpression

import com.intellij.psi.PsiLiteralExpression; //导入依赖的package包/类
@Override
public void visitLiteralExpression(@NotNull PsiLiteralExpression expression) {
  super.visitLiteralExpression(expression);
  final PsiType type = expression.getType();
  if (type == null || !TypeUtils.isJavaLangString(type) && !type.equals(PsiType.CHAR)) {
    return;
  }
  final String text = expression.getText();
  final Matcher matcher = newlines.matcher(text);
  int end = 0;
  while (matcher.find(end)) {
    final int start = matcher.start();
    end = matcher.end();
    registerErrorAtOffset(expression, start, end - start);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:HardcodedLineSeparatorsInspection.java

示例8: visitLiteralExpression

import com.intellij.psi.PsiLiteralExpression; //导入依赖的package包/类
@Override
public void visitLiteralExpression(
  @NotNull PsiLiteralExpression expression) {
  super.visitLiteralExpression(expression);
  final PsiType type = expression.getType();
  if (type == null) {
    return;
  }
  if (!type.equals(PsiType.CHAR)) {
    return;
  }
  final String text = expression.getText();
  if (text == null) {
    return;
  }
  if (text.equals(" ")) {
    return;
  }
  if (ExpressionUtils.isDeclaredConstant(expression)) {
    return;
  }
  if (NonNlsUtils.isNonNlsAnnotatedUse(expression)) {
    return;
  }
  registerError(expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:MagicCharacterInspectionBase.java

示例9: visitArrayInitializerExpression

import com.intellij.psi.PsiLiteralExpression; //导入依赖的package包/类
@Override
public void visitArrayInitializerExpression(
  PsiArrayInitializerExpression expression) {
  super.visitArrayInitializerExpression(expression);
  final PsiExpression[] initializers = expression.getInitializers();
  boolean hasDecimalLiteral = false;
  boolean hasOctalLiteral = false;
  for (final PsiExpression initializer : initializers) {
    if (initializer instanceof PsiLiteralExpression) {
      final PsiLiteralExpression literal =
        (PsiLiteralExpression)initializer;
      if (isDecimalLiteral(literal)) {
        hasDecimalLiteral = true;
      }
      if (isOctalLiteral(literal)) {
        hasOctalLiteral = true;
      }
    }
  }
  if (hasOctalLiteral && hasDecimalLiteral) {
    registerError(expression);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:OctalAndDecimalIntegersMixedInspection.java

示例10: visitLiteralExpression

import com.intellij.psi.PsiLiteralExpression; //导入依赖的package包/类
@Override
public void visitLiteralExpression(
  @NotNull PsiLiteralExpression expression) {
  super.visitLiteralExpression(expression);
  final PsiType type = expression.getType();
  if (type == null) {
    return;
  }
  if (!type.equals(PsiType.LONG)) {
    return;
  }
  final String text = expression.getText();
  if (text == null) {
    return;
  }
  final int length = text.length();
  if (length == 0) {
    return;
  }
  if (text.charAt(length - 1) != 'l') {
    return;
  }
  registerError(expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:LongLiteralsEndingWithLowercaseLInspection.java

示例11: satisfiedBy

import com.intellij.psi.PsiLiteralExpression; //导入依赖的package包/类
public boolean satisfiedBy(PsiElement element) {
  if (!(element instanceof PsiLiteralExpression)) {
    return false;
  }
  final PsiLiteralExpression expression = (PsiLiteralExpression)element;
  final PsiType type = expression.getType();
  if (!PsiType.DOUBLE.equals(type) && !PsiType.FLOAT.equals(type)) {
    return false;
  }
  String text = expression.getText();
  if (text == null) {
    return false;
  }
  text = text.toLowerCase();
  if (text.startsWith("-")) {
    text = text.substring(1);
  }
  if (!text.contains(".") && text.startsWith("0")) {
    return false; //Octal integer
  }
  return !text.contains("e");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ConvertToScientificNotationPredicate.java

示例12: satisfiedBy

import com.intellij.psi.PsiLiteralExpression; //导入依赖的package包/类
@Override
public boolean satisfiedBy(final PsiElement element) {
  if (!(element instanceof PsiLiteralExpression)) {
    return false;
  }

  if (!PsiUtil.isLanguageLevel7OrHigher(element)) {
    return false;
  }

  final PsiType type = ((PsiLiteralExpression)element).getType();
  if (PsiType.INT.equals(type) || PsiType.LONG.equals(type)) {
    final String text = element.getText();
    return !(text.startsWith("0b") || text.startsWith("0B"));
  }

  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ConvertIntegerToBinaryPredicate.java

示例13: satisfiedBy

import com.intellij.psi.PsiLiteralExpression; //导入依赖的package包/类
public boolean satisfiedBy(PsiElement element) {
  if (!(element instanceof PsiLiteralExpression)) {
    return false;
  }
  final PsiLiteralExpression expression = (PsiLiteralExpression)element;
  final PsiType type = expression.getType();
  if (!(PsiType.INT.equals(type) || PsiType.LONG.equals(type))) {
    return false;
  }
  @NonNls final String text = expression.getText();
  if (text.charAt(0) != '0') {
    return true;
  }
  if (text.length() < 2) {
    return true;
  }
  final char c1 = text.charAt(1);
  if (c1 != '_' && (c1 < '0' || c1 > '7')) {
    return true;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ConvertIntegerToOctalPredicate.java

示例14: isPowerOfTwo

import com.intellij.psi.PsiLiteralExpression; //导入依赖的package包/类
public static boolean isPowerOfTwo(PsiExpression rhs) {
  if (!(rhs instanceof PsiLiteralExpression)) {
    return false;
  }
  final PsiLiteralExpression literal = (PsiLiteralExpression)rhs;
  final Object value = literal.getValue();
  if (!(value instanceof Number)) {
    return false;
  }
  if (value instanceof Double || value instanceof Float) {
    return false;
  }
  int intValue = ((Number)value).intValue();
  if (intValue <= 0) {
    return false;
  }
  while (intValue % 2 == 0) {
    intValue >>= 1;
  }
  return intValue == 1;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:ShiftUtils.java

示例15: getNodeTypeText

import com.intellij.psi.PsiLiteralExpression; //导入依赖的package包/类
/**
 * Extract full node type text (i.e. namespace:nodeTypeName) from element, based on element class/type
 */
private String getNodeTypeText(@NotNull PsiElement element) {
    if (element instanceof  PsiLiteralExpression) { //Java
        PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
        return literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null;
    } else if (element instanceof CndSuperType) {   //Cnd super types
        return  element.getText();
    } else if (element instanceof CndExtension) {   //Cnd extends types
        return  element.getText();
    } else if (element instanceof CndSubNodeType) {   //Cnd subnode types
        return  element.getText();
    } else if (element instanceof CndSubNodeDefaultType) {   //Cnd subnode default type
        return  element.getText();
    } else if (element instanceof XmlAttributeValue) {    //XML
        return ((XmlAttributeValue) element).getValue();
    }
    return null;
}
 
开发者ID:Tolc,项目名称:IntelliJ_Jahia_plugin,代码行数:21,代码来源:CndReferenceProvider.java


注:本文中的com.intellij.psi.PsiLiteralExpression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。