public void testLeafExpressionsMoreComplex() throws Exception { SliceTreeStructure treeStructure = configureTree("Duplicate"); SliceNode root = (SliceNode)treeStructure.getRootElement(); Collection<PsiElement> leaves = SliceLeafAnalyzer.calcLeafExpressions(root, treeStructure, SliceLeafAnalyzer.createMap()); assertNotNull(leaves); assertEquals(2, leaves.size()); List<PsiElement> list = new ArrayList<PsiElement>(leaves); Collections.sort(list, new Comparator<PsiElement>() { @Override public int compare(PsiElement o1, PsiElement o2) { return o1.getText().compareTo(o2.getText()); } }); assertTrue(list.get(0) instanceof PsiLiteralExpression); assertEquals(false, ((PsiLiteral)list.get(0)).getValue()); assertTrue(list.get(1) instanceof PsiLiteralExpression); assertEquals(true, ((PsiLiteral)list.get(1)).getValue()); }
@Nullable public static String inferStringAttribute(@NotNull PsiAnnotation annotation, @NotNull String attributeName) { final PsiAnnotationMemberValue targetValue = annotation.findAttributeValue(attributeName); if (targetValue instanceof PsiLiteral) { final Object value = ((PsiLiteral)targetValue).getValue(); if (value instanceof String) return (String)value; } return null; }
@Nullable public static Integer inferIntegerAttribute(@NotNull PsiAnnotation annotation, @NotNull String attributeName) { final PsiAnnotationMemberValue targetValue = annotation.findAttributeValue(attributeName); if (targetValue instanceof PsiLiteral) { final Object value = ((PsiLiteral)targetValue).getValue(); if (value instanceof Integer) return (Integer)value; } return null; }
@NotNull @Override public PsiReference[] createReferences(JamStringAttributeElement<T> context) { final PsiLiteral literal = context.getPsiLiteral(); if (literal == null) return PsiReference.EMPTY_ARRAY; return new PsiReference[]{createReference(context)}; }
public void testLeafExpressionsSimple() throws Exception { SliceTreeStructure treeStructure = configureTree("DupSlice"); SliceNode root = (SliceNode)treeStructure.getRootElement(); Collection<PsiElement> leaves = SliceLeafAnalyzer.calcLeafExpressions(root, treeStructure, SliceLeafAnalyzer.createMap()); assertNotNull(leaves); PsiElement element = assertOneElement(leaves); assertTrue(element instanceof PsiLiteralExpression); assertEquals(1111111111, ((PsiLiteral)element).getValue()); }
@Override @NotNull public PsiLiteral createLiteralValue(@NotNull String value, @NotNull PsiElement context) { return (PsiLiteral)JavaPsiFacade.getInstance(context.getProject()).getElementFactory().createExpressionFromText("\"" + StringUtil.escapeStringCharacters(value) + "\"", null); }
public StringLiteralReference(PsiLiteral value) { myValue = value; }
public LanguageReference(PsiLiteral value) { super(value); }
public void visitPsiLiteral(@NotNull PsiLiteral o) { visitElement(o); }
@Nullable public TextRange getNameIdentifierRange() { final PsiLiteral psiLiteral = myNameAttr.getPsiLiteral(); return psiLiteral == null ? null : ElementManipulators.getValueTextRange(psiLiteral); }