Java 类com.intellij.util.xml.impl.ConvertContextFactory 实例源码

项目:intellij-ce-playground    文件:DomElementAnnotationHolderImpl.java   
private LocalQuickFix[] getQuickFixes(final GenericDomValue element, PsiReference reference) {
  if (!myOnTheFly) return LocalQuickFix.EMPTY_ARRAY;

  final List<LocalQuickFix> result = new SmartList<LocalQuickFix>();
  final Converter converter = WrappingConverter.getDeepestConverter(element.getConverter(), element);
  if (converter instanceof ResolvingConverter) {
    final ResolvingConverter resolvingConverter = (ResolvingConverter)converter;
    ContainerUtil
      .addAll(result, resolvingConverter.getQuickFixes(ConvertContextFactory.createConvertContext(DomManagerImpl.getDomInvocationHandler(element))));
  }
  if (reference instanceof LocalQuickFixProvider) {
    final LocalQuickFix[] localQuickFixes = ((LocalQuickFixProvider)reference).getQuickFixes();
    if (localQuickFixes != null) {
      ContainerUtil.addAll(result, localQuickFixes);
    }
  }
  return result.isEmpty() ? LocalQuickFix.EMPTY_ARRAY : result.toArray(new LocalQuickFix[result.size()]);
}
项目:intellij-ce-playground    文件:AndroidResourceReference.java   
@Override
@NotNull
public Object[] getVariants() {
  final Converter converter = WrappingConverter.getDeepestConverter(myValue.getConverter(), myValue);
  if (converter instanceof EnumConverter || converter == AndroidDomUtil.BOOLEAN_CONVERTER) {
    if (DomCompletionContributor.isSchemaEnumerated(getElement())) return ArrayUtil.EMPTY_OBJECT_ARRAY;
  }
  if (converter instanceof ResolvingConverter) {
    final ResolvingConverter resolvingConverter = (ResolvingConverter)converter;
    ArrayList<Object> result = new ArrayList<Object>();
    final ConvertContext convertContext = ConvertContextFactory.createConvertContext(myValue);
    for (Object variant : resolvingConverter.getVariants(convertContext)) {
      String name = converter.toString(variant, convertContext);
      if (name != null) {
        result.add(ElementPresentationManager.getInstance().createVariant(variant, name, resolvingConverter.getPsiElement(variant)));
      }
    }
    return result.toArray();
  }
  return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
项目:tools-idea    文件:DomElementAnnotationHolderImpl.java   
private LocalQuickFix[] getQuickFixes(final GenericDomValue element, PsiReference reference) {
  if (!myOnTheFly) return LocalQuickFix.EMPTY_ARRAY;

  final List<LocalQuickFix> result = new SmartList<LocalQuickFix>();
  final Converter converter = WrappingConverter.getDeepestConverter(element.getConverter(), element);
  if (converter instanceof ResolvingConverter) {
    final ResolvingConverter resolvingConverter = (ResolvingConverter)converter;
    ContainerUtil
      .addAll(result, resolvingConverter.getQuickFixes(ConvertContextFactory.createConvertContext(DomManagerImpl.getDomInvocationHandler(element))));
  }
  if (reference instanceof LocalQuickFixProvider) {
    final LocalQuickFix[] localQuickFixes = ((LocalQuickFixProvider)reference).getQuickFixes();
    if (localQuickFixes != null) {
      ContainerUtil.addAll(result, localQuickFixes);
    }
  }
  return result.isEmpty() ? LocalQuickFix.EMPTY_ARRAY : result.toArray(new LocalQuickFix[result.size()]);
}
项目:consulo-xml    文件:DomElementAnnotationHolderImpl.java   
private LocalQuickFix[] getQuickFixes(final GenericDomValue element, PsiReference reference) {
  if (!myOnTheFly) return LocalQuickFix.EMPTY_ARRAY;

  final List<LocalQuickFix> result = new SmartList<LocalQuickFix>();
  final Converter converter = WrappingConverter.getDeepestConverter(element.getConverter(), element);
  if (converter instanceof ResolvingConverter) {
    final ResolvingConverter resolvingConverter = (ResolvingConverter)converter;
    ContainerUtil
      .addAll(result, resolvingConverter.getQuickFixes(ConvertContextFactory.createConvertContext(DomManagerImpl.getDomInvocationHandler(element))));
  }
  if (reference instanceof LocalQuickFixProvider) {
    final LocalQuickFix[] localQuickFixes = ((LocalQuickFixProvider)reference).getQuickFixes();
    if (localQuickFixes != null) {
      ContainerUtil.addAll(result, localQuickFixes);
    }
  }
  return result.isEmpty() ? LocalQuickFix.EMPTY_ARRAY : result.toArray(new LocalQuickFix[result.size()]);
}
项目:intellij-ce-playground    文件:DimensionConverterTest.java   
public void test() {
  DimensionConverter converter = new DimensionConverter();
  StyleItem element = createElement("<item>10dp</item>", StyleItem.class);

  DomInvocationHandler handler = DomManagerImpl.getDomInvocationHandler(element);
  assertNotNull(handler);
  ConvertContext context = ConvertContextFactory.createConvertContext(handler);

  List<String> variants = new ArrayList<String>(converter.getVariants(context));
  Collections.sort(variants);
  assertEquals(Arrays.asList("10dp", "10in", "10mm", "10pt", "10px", "10sp"), variants);

  // Valid units
  assertEquals("1dip", converter.fromString("1dip", context));
  assertEquals("1dp", converter.fromString("1dp", context));
  assertEquals("1px", converter.fromString("1px", context));
  assertEquals("1in", converter.fromString("1in", context));
  assertEquals("1mm", converter.fromString("1mm", context));
  assertEquals("1sp", converter.fromString("1sp", context));
  assertEquals("1pt", converter.fromString("1pt", context));

  // Invalid dimensions (missing units)
  assertNull(converter.fromString("not_a_dimension", context));
  assertNull(converter.fromString("", context));
  assertEquals("Cannot resolve symbol ''", converter.getErrorMessage("", context));
  assertNull(converter.fromString("1", context));
  assertEquals("Cannot resolve symbol '1'", converter.getErrorMessage("1", context));
  assertNull(converter.fromString("1.5", context));
  assertEquals("Cannot resolve symbol '1.5'", converter.getErrorMessage("1.5", context));

  // Unknown units
  assertNull(converter.fromString("15d", context));
  assertEquals("Unknown unit 'd'", converter.getErrorMessage("15d", context));
  assertNull(converter.fromString("15wrong", context));
  assertEquals("Unknown unit 'wrong'", converter.getErrorMessage("15wrong", context));

  // Normal conversions
  assertEquals("15px", converter.fromString("15px", context));
  assertEquals("15", DimensionConverter.getIntegerPrefix("15px"));
  assertEquals("px", DimensionConverter.getUnitFromValue("15px"));

  // Make sure negative numbers work
  assertEquals("-10px", converter.fromString("-10px", context));
  assertEquals("-10", DimensionConverter.getIntegerPrefix("-10px"));
  assertEquals("px", DimensionConverter.getUnitFromValue("-10px"));

  // Make sure decimals work
  assertEquals("1.5sp", converter.fromString("1.5sp", context));
  assertEquals("1.5", DimensionConverter.getIntegerPrefix("1.5sp"));
  assertEquals("sp", DimensionConverter.getUnitFromValue("1.5sp"));
  assertEquals(".5sp", converter.fromString(".5sp", context));
  assertEquals(".5", DimensionConverter.getIntegerPrefix(".5sp"));
  assertEquals("sp", DimensionConverter.getUnitFromValue(".5sp"));

  // Make sure the right type of decimal separator is used
  assertNull(converter.fromString("1,5sp", context));
  assertEquals("Use a dot instead of a comma as the decimal mark", converter.getErrorMessage("1,5sp", context));

  // Documentation
  assertEquals("<html><body>" +
               "<b>Density-independent Pixels</b> - an abstract unit that is based on the physical density of the screen." +
               "</body></html>", converter.getDocumentation("1dp"));
  assertEquals("<html><body>" +
               "<b>Pixels</b> - corresponds to actual pixels on the screen. Not recommended." +
               "</body></html>", converter.getDocumentation("-10px"));
  assertEquals("<html><body>" +
               "<b>Scale-independent Pixels</b> - this is like the dp unit, but " +
               "it is also scaled by the user's font size preference." +
               "</body></html>", converter.getDocumentation("1.5sp"));
}