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


Java PsiLiteralExpression.getValue方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: getReferencesByElement

import com.intellij.psi.PsiLiteralExpression; //导入方法依赖的package包/类
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
  final PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
  final String value = (String) literalExpression.getValue();

  final String text;
  if (value == null) {
    text = "";
  }
  else {
    text = value.replace(Util.INTELLIJ_MAGIC_STRING, "");
  }

  return new PsiReference[] {
     new DataFieldReference(false, literalExpression, TextRange.create(1, text.length() + 1))
  };
}
 
开发者ID:errai,项目名称:errai-intellij-idea-plugin,代码行数:19,代码来源:DataFieldReferenceProvider.java

示例6: configureLocalInspectionTools

import com.intellij.psi.PsiLiteralExpression; //导入方法依赖的package包/类
@NotNull
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
  return new LocalInspectionTool[]{new DefUseInspection(), new LocalInspectionTool() {
    @Override
    @Nls
    @NotNull
    public String getGroupDisplayName() {
      return "MyGroup";
    }

    @Override
    @Nls
    @NotNull
    public String getDisplayName() {
      return "My";
    }

    @Override
    @NonNls
    @NotNull
    public String getShortName() {
      return getDisplayName();
    }

    @Override
    @NotNull
    public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
      return new JavaElementVisitor() {
        @Override public void visitLiteralExpression(PsiLiteralExpression expression) {
          final String s = (String)expression.getValue();
          if (s.contains("a")) holder.registerProblem(expression, "Look ma! This String contains 'a'");
          if (s.contains("b")) holder.registerProblem(expression, "Look ma! This String contains 'b'");
        }
      };
    }
  }};
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:EmptyIntentionInspectionQuickFixTest.java

示例7: getLogBaseTwo

import com.intellij.psi.PsiLiteralExpression; //导入方法依赖的package包/类
public static int getLogBaseTwo(PsiLiteralExpression rhs) {
  final Object value = rhs.getValue();
  int log = 0;
  if (value == null) {
    return log;
  }
  int intValue = ((Number)value).intValue();
  while (intValue % 2 == 0) {
    intValue >>= 1;
    log++;
  }
  return log;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:ShiftUtils.java

示例8: getEnclosingStringLiteral

import com.intellij.psi.PsiLiteralExpression; //导入方法依赖的package包/类
@Nullable
public static PsiLiteralExpression getEnclosingStringLiteral(final PsiFile psiFile, final Editor editor) {
  PsiElement psiElement = psiFile.findElementAt(editor.getCaretModel().getOffset());
  if (psiElement == null) return null;
  PsiLiteralExpression expression = PsiTreeUtil.getParentOfType(psiElement, PsiLiteralExpression.class);
  if (expression == null || !(expression.getValue() instanceof String)) return null;
  return expression;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:I18nizeAction.java

示例9: getLogBase2

import com.intellij.psi.PsiLiteralExpression; //导入方法依赖的package包/类
public static int getLogBase2(PsiExpression rhs) {
  final PsiLiteralExpression literal = (PsiLiteralExpression)rhs;
  final Object value = literal.getValue();
  int intValue = ((Number)value).intValue();
  int log = 0;
  while (intValue % 2 == 0) {
    intValue >>= 1;
    log++;
  }
  return log;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:ShiftUtils.java

示例10: getExpBase2

import com.intellij.psi.PsiLiteralExpression; //导入方法依赖的package包/类
public static int getExpBase2(PsiExpression rhs) {
  final PsiLiteralExpression literal = (PsiLiteralExpression)rhs;
  final Object value = literal.getValue();
  if (value == null) {
    return 0;
  }
  final int intValue = ((Number)value).intValue() & 31;
  int exp = 1;
  for (int i = 0; i < intValue; i++) {
    exp <<= 1;
  }
  return exp;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:ShiftUtils.java

示例11: isIntLiteral

import com.intellij.psi.PsiLiteralExpression; //导入方法依赖的package包/类
public static boolean isIntLiteral(PsiExpression rhs) {
  if (!(rhs instanceof PsiLiteralExpression)) {
    return false;
  }
  final PsiLiteralExpression literal = (PsiLiteralExpression)rhs;
  final Object value = literal.getValue();
  if (!(value instanceof Number)) {
    return false;
  }
  return !(value instanceof Double) && !(value instanceof Float);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:ShiftUtils.java

示例12: collectNavigationMarkers

import com.intellij.psi.PsiLiteralExpression; //导入方法依赖的package包/类
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, Collection<? super RelatedItemLineMarkerInfo> result) {
    if (element instanceof PsiLiteralExpression) {
        PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
        String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null;
        NodeTypeModel nodeTypeModel = null;
        try {
            nodeTypeModel = new NodeTypeModel(value);
        } catch (IllegalArgumentException e) {
            //Nothing to do
        }

        if (nodeTypeModel != null) {
            String namespace = nodeTypeModel.getNamespace();
            String nodeTypeName = nodeTypeModel.getNodeTypeName();

            Project project = element.getProject();
            CndNodeType nodeType = CndUtil.findNodeType(project, namespace, nodeTypeName);
            if (nodeType != null) {
                Icon icon;
                if (nodeType.isMixin()) {
                    icon = CndIcons.MIXIN;
                } else {
                    icon = CndIcons.NODE_TYPE;
                }
                NavigationGutterIconBuilder<PsiElement> builder =
                        NavigationGutterIconBuilder.create(icon).
                                setTarget(nodeType).
                                setTooltipText("Navigate to node type definition");
                result.add(builder.createLineMarkerInfo(element));
            }
        }
    }
}
 
开发者ID:Tolc,项目名称:IntelliJ_Jahia_plugin,代码行数:35,代码来源:CndJavaLineMarkerProvider.java

示例13: getVersionField

import com.intellij.psi.PsiLiteralExpression; //导入方法依赖的package包/类
private String getVersionField(PsiClass old) {
    String versionIdentifier = null;
    for (PsiField psiField : old.getFields()) {
        if (psiField.getName().equals("VERSION")) {
            PsiLiteralExpression initializer = (PsiLiteralExpression) psiField.getInitializer();
            if (initializer != null) {
                Object value = initializer.getValue();
                if (value instanceof String) {
                    versionIdentifier = (String) value;
                }
            }
        }
    }
    return versionIdentifier;
}
 
开发者ID:maxifier,项目名称:mxcache,代码行数:16,代码来源:InstrumentatorFinder.java

示例14: getLogBaseTwo

import com.intellij.psi.PsiLiteralExpression; //导入方法依赖的package包/类
public static int getLogBaseTwo(PsiExpression rhs) {
  final PsiLiteralExpression literal = (PsiLiteralExpression)rhs;
  final Object value = literal.getValue();
  int log = 0;
  if (value == null) {
    return log;
  }
  int intValue = ((Number)value).intValue();
  while (intValue % 2 == 0) {
    intValue >>= 1;
    log++;
  }
  return log;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:15,代码来源:ShiftUtils.java

示例15: getReferencesByElement

import com.intellij.psi.PsiLiteralExpression; //导入方法依赖的package包/类
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
  final List<PsiReference> referenceList = new ArrayList<PsiReference>();

  final PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
  final String value = (String) literalExpression.getValue();

  final String text;
  if (value == null) {
    text = "";
  }
  else {
    text = value.replace(Util.INTELLIJ_MAGIC_STRING, "");
  }

  final TemplateExpression templateExpression = TemplateUtil.parseReference(text);

  final int start = text.indexOf(templateExpression.getFileName());
  final TextRange textRange = TextRange.create(start + 1, start + templateExpression.getFileName().length() + 1);

  final int hashIdx = text.indexOf('#');
  referenceList.add(new TemplateFileReference(literalExpression, textRange));

  if (hashIdx != -1) {
    final int nodeStart = hashIdx + 2;
    final TextRange range = TextRange.create(nodeStart, text.length() + 1);
    referenceList.add(new DataFieldReference(true, literalExpression, range));
  }

  return referenceList.toArray(new PsiReference[referenceList.size()]);
}
 
开发者ID:errai,项目名称:errai-intellij-idea-plugin,代码行数:33,代码来源:TemplatedReferenceProvider.java


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