本文整理汇总了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;
}
});
}
示例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();
}
示例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/>"));
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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");
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}