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

项目:intellij-ce-playground    文件:DomAttributeXmlDescriptor.java   
static String getQualifiedAttributeName(PsiElement context, XmlName xmlName) {
  final String localName = xmlName.getLocalName();
  if (context instanceof XmlTag) {
    final XmlTag tag = (XmlTag)context;
    final DomInvocationHandler handler = DomManagerImpl.getDomManager(context.getProject()).getDomHandler(tag);
    if (handler != null) {
      final String ns = handler.createEvaluatedXmlName(xmlName).getNamespace(tag, handler.getFile());
      if (!ns.equals(XmlUtil.EMPTY_URI) && !ns.equals(tag.getNamespace())) {
        final String prefix = tag.getPrefixByNamespace(ns);
        if (StringUtil.isNotEmpty(prefix)) {
          return prefix + ":" + localName;
        }
      }
    }
  }

  return localName;
}
项目:tools-idea    文件:DomAttributeXmlDescriptor.java   
static String getQualifiedAttributeName(PsiElement context, XmlName xmlName) {
  final String localName = xmlName.getLocalName();
  if (context instanceof XmlTag) {
    final XmlTag tag = (XmlTag)context;
    final DomInvocationHandler handler = DomManagerImpl.getDomManager(context.getProject()).getDomHandler(tag);
    if (handler != null) {
      final String ns = handler.createEvaluatedXmlName(xmlName).getNamespace(tag, handler.getFile());
      if (!ns.equals(XmlUtil.EMPTY_URI) && !ns.equals(tag.getNamespace())) {
        final String prefix = tag.getPrefixByNamespace(ns);
        if (StringUtil.isNotEmpty(prefix)) {
          return prefix + ":" + localName;
        }
      }
    }
  }

  return localName;
}
项目:consulo-xml    文件:DomAttributeXmlDescriptor.java   
static String getQualifiedAttributeName(PsiElement context, XmlName xmlName) {
  final String localName = xmlName.getLocalName();
  if (context instanceof XmlTag) {
    final XmlTag tag = (XmlTag)context;
    final DomInvocationHandler handler = DomManagerImpl.getDomManager(context.getProject()).getDomHandler(tag);
    if (handler != null) {
      final String ns = handler.createEvaluatedXmlName(xmlName).getNamespace(tag, handler.getFile());
      if (!ns.equals(XmlUtil.EMPTY_URI) && !ns.equals(tag.getNamespace())) {
        final String prefix = tag.getPrefixByNamespace(ns);
        if (StringUtil.isNotEmpty(prefix)) {
          return prefix + ":" + localName;
        }
      }
    }
  }

  return localName;
}
项目:intellij-ce-playground    文件:DomAttributeXmlDescriptor.java   
@Override
@Nullable
public String getNamespace(@NotNull XmlTag context) {
  final DomInvocationHandler handler = DomManagerImpl.getDomManager(myProject).getDomHandler(context);

  if (handler == null) {
    return null;
  }
  return handler.createEvaluatedXmlName(myDescription.getXmlName()).getNamespace(context, handler.getFile());
}
项目:intellij-ce-playground    文件:DomStubBuilderVisitor.java   
void visitXmlElement(XmlElement element, ElementStub parent, int index) {
  DomInvocationHandler handler = myManager.getDomHandler(element);
  if (handler == null || handler.getAnnotation(Stubbed.class) == null && !handler.getChildDescription().isStubbed()) return;

  AbstractDomChildrenDescription description = handler.getChildDescription();
  String nsKey = description instanceof DomChildrenDescription ? ((DomChildrenDescription)description).getXmlName().getNamespaceKey() : "";
  if (element instanceof XmlTag) {
    XmlTag tag = (XmlTag)element;

    String elementClass = null;
    if (handler.getAnnotation(StubbedOccurrence.class) != null) {
      final Type type = description.getType();
      elementClass = ((Class)type).getName();
    }
    ElementStub stub = new ElementStub(parent,
                                       StringRef.fromString(tag.getName()),
                                       StringRef.fromNullableString(nsKey),
                                       index,
                                       description instanceof CustomDomChildrenDescription,
                                       elementClass == null ? null : StringRef.fromNullableString(elementClass),
                                       tag.getSubTags().length == 0 ? tag.getValue().getTrimmedText() : "");

    for (XmlAttribute attribute : tag.getAttributes()) {
      visitXmlElement(attribute, stub, 0);
    }
    Map<String, Integer> indices = new HashMap<String, Integer>();
    for (final XmlTag subTag : tag.getSubTags()) {
      String name = subTag.getName();
      Integer i = indices.get(name);
      i = i == null ? 0 : i + 1;
      visitXmlElement(subTag, stub, i);
      indices.put(name, i);
    }
  } else if (element instanceof XmlAttribute) {
    new AttributeStub(parent, StringRef.fromString(((XmlAttribute)element).getLocalName()), 
                      StringRef.fromNullableString(nsKey), 
                      ((XmlAttribute)element).getValue());
  }
}
项目:tools-idea    文件:DomAttributeXmlDescriptor.java   
@Nullable
public String getNamespace(@NotNull XmlTag context) {
  final DomInvocationHandler handler = DomManagerImpl.getDomManager(myProject).getDomHandler(context);

  if (handler == null) {
    return null;
  }
  return handler.createEvaluatedXmlName(myDescription.getXmlName()).getNamespace(context, handler.getFile());
}
项目:consulo-xml    文件:DomAttributeXmlDescriptor.java   
@Nullable
public String getNamespace(@NotNull XmlTag context) {
  final DomInvocationHandler handler = DomManagerImpl.getDomManager(myProject).getDomHandler(context);

  if (handler == null) {
    return null;
  }
  return handler.createEvaluatedXmlName(myDescription.getXmlName()).getNamespace(context, handler.getFile());
}
项目:consulo-xml    文件:DomTestCase.java   
protected void assertCached(final DomElement element, final XmlElement xmlElement)
{
    assertNotNull(xmlElement);
    assertSame(element.getXmlTag(), xmlElement);
    final DomInvocationHandler cachedElement = getCachedHandler(xmlElement);
    assertNotNull(cachedElement);
    assertEquals(element, cachedElement.getProxy());
}
项目:intellij-ce-playground    文件:DomStub.java   
public DomInvocationHandler getHandler() {
  return myHandler;
}
项目:intellij-ce-playground    文件:DomStub.java   
public void setHandler(DomInvocationHandler handler) {
  myHandler = handler;
}
项目: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"));
}
项目:tools-idea    文件:DomStub.java   
public DomInvocationHandler getHandler() {
  return myHandler;
}
项目:tools-idea    文件:DomStub.java   
public void setHandler(DomInvocationHandler handler) {
  myHandler = handler;
}
项目:consulo-xml    文件:DomStub.java   
public DomInvocationHandler getHandler()
{
    return myHandler;
}
项目:consulo-xml    文件:DomStub.java   
public void setHandler(DomInvocationHandler handler)
{
    myHandler = handler;
}
项目:consulo-xml    文件:StubParentStrategy.java   
@Override
public DomInvocationHandler getParentHandler()
{
    DomStub parentStub = myStub.getParentStub();
    return parentStub == null ? null : parentStub.getHandler();
}
项目:consulo-xml    文件:StubParentStrategy.java   
@NotNull
@Override
public DomParentStrategy refreshStrategy(DomInvocationHandler handler)
{
    return this;
}
项目:consulo-xml    文件:StubParentStrategy.java   
@Override
public XmlFile getContainingFile(DomInvocationHandler handler)
{
    return getParentHandler().getFile();
}
项目:consulo-xml    文件:StubParentStrategy.java   
@Override
public DomInvocationHandler getParentHandler()
{
    return myParent.getHandler();
}
项目:consulo-xml    文件:DomStubBuilderVisitor.java   
void visitXmlElement(XmlElement element, ElementStub parent, int index)
{
    DomInvocationHandler handler = myManager.getDomHandler(element);
    if(handler == null || handler.getAnnotation(Stubbed.class) == null && !handler.getChildDescription().isStubbed())
    {
        return;
    }

    AbstractDomChildrenDescription description = handler.getChildDescription();
    String nsKey = description instanceof DomChildrenDescription ? ((DomChildrenDescription) description).getXmlName().getNamespaceKey() : "";
    if(element instanceof XmlTag)
    {
        XmlTag tag = (XmlTag) element;

        String elementClass = null;
        if(handler.getAnnotation(StubbedOccurrence.class) != null)
        {
            final Type type = description.getType();
            elementClass = ((Class) type).getName();
        }

        ElementStub stub = new ElementStub(parent, StringRef.fromString(tag.getName()), StringRef.fromNullableString(nsKey), index,
                description instanceof CustomDomChildrenDescription, elementClass == null ? null : StringRef.fromNullableString(elementClass));
        for(XmlAttribute attribute : tag.getAttributes())
        {
            visitXmlElement(attribute, stub, 0);
        }
        Map<String, Integer> indices = new HashMap<String, Integer>();
        for(final XmlTag subTag : tag.getSubTags())
        {
            String name = subTag.getName();
            Integer i = indices.get(name);
            i = i == null ? 0 : i + 1;
            visitXmlElement(subTag, stub, i);
            indices.put(name, i);
        }
    }
    else if(element instanceof XmlAttribute)
    {
        new AttributeStub(parent, StringRef.fromString(((XmlAttribute) element).getLocalName()), StringRef.fromNullableString(nsKey),
                ((XmlAttribute) element).getValue());
    }
}
项目:consulo-xml    文件:DomTestCase.java   
@Nullable
public DomInvocationHandler getCachedHandler(XmlElement element)
{
    final List<DomInvocationHandler> option = getDomManager().getSemService().getCachedSemElements(DomManagerImpl.DOM_HANDLER_KEY, element);
    return option == null || option.isEmpty() ? null : option.get(0);
}