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

项目: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;
}
项目: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()]);
}
项目: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;
}
项目: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    文件: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    文件: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    文件: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    文件:DomStubBuilder.java   
@Override
public Stub buildStubTree(FileContent fileContent) {
  PsiFile psiFile = fileContent.getPsiFile();
  if (!(psiFile instanceof XmlFile)) return null;

  Document document = FileDocumentManager.getInstance().getCachedDocument(fileContent.getFile());
  Project project = fileContent.getProject();
  if (project == null) {
    project = psiFile.getProject();
  }
  if (document != null) {
    PsiFile existingPsi = PsiDocumentManager.getInstance(project).getPsiFile(document);
    if (existingPsi instanceof XmlFile) {
      psiFile = existingPsi;
    }
  }

  XmlFile xmlFile = (XmlFile)psiFile;
  try {
    XmlUtil.BUILDING_DOM_STUBS.set(Boolean.TRUE);
    DomFileElement<? extends DomElement> fileElement = DomManager.getDomManager(project).getFileElement(xmlFile);
    if (fileElement == null || !fileElement.getFileDescription().hasStubs()) return null;

    XmlFileHeader header = DomService.getInstance().getXmlFileHeader(xmlFile);
    if (header.getRootTagLocalName() == null) {
      LOG.error("null root tag for " + fileElement + " for " + fileContent.getFile());
    }
    FileStub fileStub = new FileStub(header);
    XmlTag rootTag = xmlFile.getRootTag();
    if (rootTag != null) {
      new DomStubBuilderVisitor(DomManagerImpl.getDomManager(project)).visitXmlElement(rootTag, fileStub, 0);
    }
    return fileStub;
  }
  finally {
    XmlUtil.BUILDING_DOM_STUBS.set(Boolean.FALSE);
    SemService.getSemService(project).clearCache();
  }
}
项目:intellij-ce-playground    文件:DimensionConverterTest.java   
@SuppressWarnings("deprecation")
protected <T extends DomElement> T createElement(final String xml, final Class<T> aClass) throws IncorrectOperationException {
  final DomManagerImpl domManager = (DomManagerImpl)DomManager.getDomManager(getProject());
  final String name = "a.xml";
  final XmlFile file = (XmlFile)PsiFileFactory.getInstance(domManager.getProject()).createFileFromText(name, xml);
  assertNotNull(file);
  XmlDocument document = file.getDocument();
  assertNotNull(document);
  final XmlTag tag = document.getRootTag();
  final String rootTagName = tag != null ? tag.getName() : "root";
  final T element = domManager.getFileElement(file, aClass, rootTagName).getRootElement();
  assertNotNull(element);
  assertSame(tag, element.getXmlTag());
  return element;
}
项目: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 <T extends DomElement> T createElement(final String xml, final Class<T> aClass) throws IncorrectOperationException
{
    final DomManagerImpl domManager = getDomManager();
    T element = createElement(domManager, xml, aClass);
    myCallRegistry.clear();
    return element;
}
项目:intellij-ce-playground    文件:DomStubBuilderVisitor.java   
DomStubBuilderVisitor(DomManagerImpl manager) {
  myManager = manager;
}
项目:intellij-ce-playground    文件:DomIncludesTest.java   
private DomManagerImpl getDomManager() {
  return DomManagerImpl.getDomManager(getProject());
}
项目:intellij-ce-playground    文件:DomHardCoreTestCase.java   
protected DomManagerImpl getDomManager() {
  return DomManagerImpl.getDomManager(getProject());
}
项目:intellij-ce-playground    文件:DomStubTest.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  ((DomManagerImpl)DomManager.getDomManager(getProject())).registerFileDescription(DOM_FILE_DESCRIPTION, getTestRootDisposable());
}
项目: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    文件:DomIncludesTest.java   
private DomManagerImpl getDomManager() {
  return DomManagerImpl.getDomManager(getProject());
}
项目:tools-idea    文件:DomHardCoreTestCase.java   
protected DomManagerImpl getDomManager() {
  return DomManagerImpl.getDomManager(getProject());
}
项目:tools-idea    文件:DomStubTest.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  ((DomManagerImpl)DomManager.getDomManager(getProject())).registerFileDescription(DOM_FILE_DESCRIPTION, getTestRootDisposable());
}
项目:consulo-xml    文件:StubParentStrategy.java   
@NotNull
@Override
public DomParentStrategy setXmlElement(@NotNull XmlElement element)
{
    return new PhysicalDomParentStrategy(element, DomManagerImpl.getDomManager(element.getProject()));
}
项目:consulo-xml    文件:DomStubBuilder.java   
@Override
public Stub buildStubTree(FileContent fileContent)
{
    VirtualFile file = fileContent.getFile();
    Project project = fileContent.getProject();
    PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if(!(psiFile instanceof XmlFile))
    {
        return null;
    }

    XmlFile xmlFile = (XmlFile) psiFile;
    try
    {
        XmlUtil.BUILDING_DOM_STUBS.set(Boolean.TRUE);
        psiFile.putUserData(CONTENT_FOR_DOM_STUBS, fileContent);
        DomFileElement<? extends DomElement> fileElement = DomManager.getDomManager(project).getFileElement(xmlFile);
        if(fileElement == null || !fileElement.getFileDescription().hasStubs())
        {
            return null;
        }

        XmlFileHeader header = DomService.getInstance().getXmlFileHeader(xmlFile);
        if(header.getRootTagLocalName() == null)
        {
            LOG.error("null root tag for " + fileElement + " for " + file);
        }
        FileStub fileStub = new FileStub(header);
        XmlTag rootTag = xmlFile.getRootTag();
        if(rootTag != null)
        {
            new DomStubBuilderVisitor(DomManagerImpl.getDomManager(project)).visitXmlElement(rootTag, fileStub, 0);
        }
        return fileStub;
    }
    finally
    {
        XmlUtil.BUILDING_DOM_STUBS.set(Boolean.FALSE);
        psiFile.putUserData(CONTENT_FOR_DOM_STUBS, null);
    }
}
项目:consulo-xml    文件:DomStubBuilderVisitor.java   
DomStubBuilderVisitor(DomManagerImpl manager)
{
    myManager = manager;
}
项目:consulo-xml    文件:DomTestCase.java   
protected DomManagerImpl getDomManager()
{
    return (DomManagerImpl) DomManager.getDomManager(getProject());
}
项目: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);
}
项目:consulo-xml    文件:DomHardCoreTestCase.java   
protected DomManagerImpl getDomManager() {
  return DomManagerImpl.getDomManager(getProject());
}