當前位置: 首頁>>代碼示例>>Java>>正文


Java ConvertContextFactory類代碼示例

本文整理匯總了Java中com.intellij.util.xml.impl.ConvertContextFactory的典型用法代碼示例。如果您正苦於以下問題:Java ConvertContextFactory類的具體用法?Java ConvertContextFactory怎麽用?Java ConvertContextFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ConvertContextFactory類屬於com.intellij.util.xml.impl包,在下文中一共展示了ConvertContextFactory類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getQuickFixes

import com.intellij.util.xml.impl.ConvertContextFactory; //導入依賴的package包/類
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()]);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:19,代碼來源:DomElementAnnotationHolderImpl.java

示例2: getVariants

import com.intellij.util.xml.impl.ConvertContextFactory; //導入依賴的package包/類
@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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:22,代碼來源:AndroidResourceReference.java

示例3: test

import com.intellij.util.xml.impl.ConvertContextFactory; //導入依賴的package包/類
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"));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:71,代碼來源:DimensionConverterTest.java


注:本文中的com.intellij.util.xml.impl.ConvertContextFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。