Java 类com.intellij.psi.impl.source.xml.SchemaPrefixReference 实例源码

项目:intellij-ce-playground    文件:XmlPrefixReferenceProvider.java   
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
  XmlAttributeValue attributeValue = (XmlAttributeValue)element;
  String value = attributeValue.getValue();
  if (value == null) return PsiReference.EMPTY_ARRAY;
  int i = value.indexOf(':');
  if (i <= 0) return PsiReference.EMPTY_ARRAY;
  PsiElement parent = attributeValue.getParent();
  if (parent instanceof XmlAttribute && !XmlNSDescriptorImpl.checkSchemaNamespace(((XmlAttribute)parent).getParent())) {
    XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor();
    if (descriptor instanceof XmlAttributeDescriptorImpl) {
      String type = ((XmlAttributeDescriptorImpl)descriptor).getType();
      if (type != null && type.endsWith(":QName")) {
        String prefix = XmlUtil.findPrefixByQualifiedName(type);
        String ns = ((XmlTag)descriptor.getDeclaration()).getNamespaceByPrefix(prefix);
        if (XmlNSDescriptorImpl.checkSchemaNamespace(ns)) {
          return new PsiReference[] {
            new SchemaPrefixReference(attributeValue, TextRange.from(1, i), value.substring(0, i), null)
          };
        }
      }
    }
  }
  return PsiReference.EMPTY_ARRAY;
}
项目:intellij-ce-playground    文件:TagNameReferenceCompletionProvider.java   
@Override
protected void addCompletions(@NotNull CompletionParameters parameters,
                              ProcessingContext context,
                              @NotNull final CompletionResultSet result) {
  LegacyCompletionContributor.processReferences(parameters, result, new PairConsumer<PsiReference, CompletionResultSet>() {
    @Override
    public void consume(PsiReference reference, CompletionResultSet set) {
      if (reference instanceof TagNameReference) {
        collectCompletionVariants((TagNameReference)reference, set);
      }
      else if (reference instanceof SchemaPrefixReference) {
        TagNameReference tagNameReference = ((SchemaPrefixReference)reference).getTagNameReference();
        if (tagNameReference != null && !tagNameReference.isStartTagFlag()) {
          set.consume(createClosingTagLookupElement((XmlTag)tagNameReference.getElement(), true, tagNameReference.getNameElement()));
        }
      }
    }
  });
}
项目:intellij-ce-playground    文件:ConvertSchemaPrefixToDefaultIntention.java   
@Nullable
private static XmlAttribute getXmlnsDeclaration(PsiElement element) {
  final PsiElement parent = element.getParent();
  if (parent == null) return null;
  for (PsiReference ref : parent.getReferences()) {
    if (ref instanceof SchemaPrefixReference) {
      final PsiElement elem = ref.resolve();
      if (elem != null) {
        final PsiElement attr = elem.getParent();
        if (attr instanceof XmlAttribute) {
          final PsiElement tag = attr.getParent();
          if (tag instanceof XmlTag && ((XmlTag)tag).getAttribute("xmlns") == null) {
            return (XmlAttribute)attr;
          }
        }
      }
    }
  }
  return null;
}
项目:tools-idea    文件:TagNameReferenceCompletionProvider.java   
@Override
protected void addCompletions(@NotNull CompletionParameters parameters,
                              ProcessingContext context,
                              @NotNull final CompletionResultSet result) {
  LegacyCompletionContributor.processReferences(parameters, result, new PairConsumer<PsiReference, CompletionResultSet>() {
    @Override
    public void consume(PsiReference reference, CompletionResultSet set) {
      if (reference instanceof TagNameReference) {
        collectCompletionVariants((TagNameReference)reference, set);
      }
      else if (reference instanceof SchemaPrefixReference) {
        TagNameReference tagNameReference = ((SchemaPrefixReference)reference).getTagNameReference();
        if (tagNameReference != null && !tagNameReference.isStartTagFlag()) {
          set.consume(createClosingTagLookupElement((XmlTag)tagNameReference.getElement(), true, tagNameReference.getNameElement()));
        }
      }
    }
  });
}
项目:tools-idea    文件:ConvertSchemaPrefixToDefaultIntention.java   
@Nullable
private static XmlAttribute getXmlnsDeclaration(PsiElement element) {
  final PsiElement parent = element.getParent();
  if (parent == null) return null;
  for (PsiReference ref : parent.getReferences()) {
    if (ref instanceof SchemaPrefixReference) {
      final PsiElement elem = ref.resolve();
      if (elem != null) {
        final PsiElement attr = elem.getParent();
        if (attr instanceof XmlAttribute) {
          final PsiElement tag = attr.getParent();
          if (tag instanceof XmlTag && ((XmlTag)tag).getAttribute("xmlns") == null) {
            return (XmlAttribute)attr;
          }
        }
      }
    }
  }
  return null;
}
项目:consulo-xml    文件:TagNameReferenceCompletionProvider.java   
@Override
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull final CompletionResultSet result)
{
    LegacyCompletionContributor.processReferences(parameters, result, (reference, set) ->
    {
        if(reference instanceof TagNameReference)
        {
            collectCompletionVariants((TagNameReference) reference, set);
        }
        else if(reference instanceof SchemaPrefixReference)
        {
            TagNameReference tagNameReference = ((SchemaPrefixReference) reference).getTagNameReference();
            if(tagNameReference != null && !tagNameReference.isStartTagFlag())
            {
                set.consume(createClosingTagLookupElement((XmlTag) tagNameReference.getElement(), true, tagNameReference.getNameElement()));
            }
        }
    });
}
项目:consulo-xml    文件:XmlNsPrefixAnnotator.java   
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder)
{
    if(element instanceof XmlTag || element instanceof XmlAttribute)
    {
        List<SchemaPrefixReference> references = ContainerUtil.findAll(element.getReferences(), SchemaPrefixReference.class);
        for(SchemaPrefixReference reference : references)
        {
            TextRange rangeInElement = reference.getRangeInElement();
            if(!rangeInElement.isEmpty())
            {
                TextRange range = rangeInElement.shiftRight(element.getTextRange().getStartOffset());
                holder.createInfoAnnotation(range, null).setTextAttributes(XmlHighlighterColors.XML_NS_PREFIX);
            }
        }
    }
}
项目:consulo-xml    文件:ConvertSchemaPrefixToDefaultIntention.java   
@Nullable
private static XmlAttribute getXmlnsDeclaration(PsiElement element) {
  final PsiElement parent = element.getParent();
  if (parent == null) return null;
  for (PsiReference ref : parent.getReferences()) {
    if (ref instanceof SchemaPrefixReference) {
      final PsiElement elem = ref.resolve();
      if (elem != null) {
        final PsiElement attr = elem.getParent();
        if (attr instanceof XmlAttribute) {
          final PsiElement tag = attr.getParent();
          if (tag instanceof XmlTag && ((XmlTag)tag).getAttribute("xmlns") == null) {
            return (XmlAttribute)attr;
          }
        }
      }
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:XmlNsPrefixAnnotator.java   
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
  if (element instanceof XmlTag || element instanceof XmlAttribute) {
    List<SchemaPrefixReference> references = ContainerUtil.findAll(element.getReferences(), SchemaPrefixReference.class);
    for (SchemaPrefixReference reference : references) {
      TextRange rangeInElement = reference.getRangeInElement();
      if (!rangeInElement.isEmpty()) {
        TextRange range = rangeInElement.shiftRight(element.getTextRange().getStartOffset());
        holder.createInfoAnnotation(range, null).setTextAttributes(XmlHighlighterColors.XML_NS_PREFIX);
      }
    }
  }
}
项目:intellij-ce-playground    文件:SchemaReferencesProvider.java   
@Nullable
private static PsiReference createSchemaPrefixReference(final PsiElement element) {
  if (element instanceof XmlAttributeValue) {
    final XmlAttributeValue attributeValue = (XmlAttributeValue)element;
    final String prefix = XmlUtil.findPrefixByQualifiedName(attributeValue.getValue());
    if (!prefix.isEmpty()) {
      return new SchemaPrefixReference(attributeValue, TextRange.from(1, prefix.length()), prefix, null);
    }
  }
  return null;
}
项目:tools-idea    文件:SchemaReferencesProvider.java   
@Nullable
private static PsiReference createSchemaPrefixReference(final PsiElement element) {
  if (element instanceof XmlAttributeValue) {
    final XmlAttributeValue attributeValue = (XmlAttributeValue)element;
    final String prefix = XmlUtil.findPrefixByQualifiedName(attributeValue.getValue());
    if (prefix.length() > 0) {
      return new SchemaPrefixReference(attributeValue, TextRange.from(1, prefix.length()), prefix, null);
    }
  }
  return null;
}
项目:tools-idea    文件:XmlPrefixReferenceProvider.java   
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
  XmlAttributeValue attributeValue = (XmlAttributeValue)element;
  PsiElement parent = attributeValue.getParent();
  if (parent instanceof XmlAttribute && !XmlNSDescriptorImpl.checkSchemaNamespace(((XmlAttribute)parent).getParent())) {
    XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor();
    if (descriptor instanceof XmlAttributeDescriptorImpl) {
      String type = ((XmlAttributeDescriptorImpl)descriptor).getType();
      if (type != null && type.endsWith(":QName")) {
        String prefix = XmlUtil.findPrefixByQualifiedName(type);
        String ns = ((XmlTag)descriptor.getDeclaration()).getNamespaceByPrefix(prefix);
        if (XmlNSDescriptorImpl.checkSchemaNamespace(ns)) {
          String value = attributeValue.getValue();
          if (value != null) {
            int i = value.indexOf(':');
            if (i > 0) {
              return new PsiReference[] {
                new SchemaPrefixReference(attributeValue, TextRange.from(1, i), value.substring(0, i), null)
              };
            }
          }
        }
      }
    }
  }
  return PsiReference.EMPTY_ARRAY;
}
项目:consulo-xml    文件:SchemaReferencesProvider.java   
@Nullable
private static PsiReference createSchemaPrefixReference(final PsiElement element)
{
    if(element instanceof XmlAttributeValue)
    {
        final XmlAttributeValue attributeValue = (XmlAttributeValue) element;
        final String prefix = XmlUtil.findPrefixByQualifiedName(attributeValue.getValue());
        if(!prefix.isEmpty())
        {
            return new SchemaPrefixReference(attributeValue, TextRange.from(1, prefix.length()), prefix, null);
        }
    }
    return null;
}
项目:consulo-xml    文件:XmlPrefixReferenceProvider.java   
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
  XmlAttributeValue attributeValue = (XmlAttributeValue)element;
  PsiElement parent = attributeValue.getParent();
  if (parent instanceof XmlAttribute && !XmlNSDescriptorImpl.checkSchemaNamespace(((XmlAttribute)parent).getParent())) {
    XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor();
    if (descriptor instanceof XmlAttributeDescriptorImpl) {
      String type = ((XmlAttributeDescriptorImpl)descriptor).getType();
      if (type != null && type.endsWith(":QName")) {
        String prefix = XmlUtil.findPrefixByQualifiedName(type);
        String ns = ((XmlTag)descriptor.getDeclaration()).getNamespaceByPrefix(prefix);
        if (XmlNSDescriptorImpl.checkSchemaNamespace(ns)) {
          String value = attributeValue.getValue();
          if (value != null) {
            int i = value.indexOf(':');
            if (i > 0) {
              return new PsiReference[] {
                new SchemaPrefixReference(attributeValue, TextRange.from(1, i), value.substring(0, i), null)
              };
            }
          }
        }
      }
    }
  }
  return PsiReference.EMPTY_ARRAY;
}
项目:intellij-ce-playground    文件:XmlRefCountHolder.java   
@Override
public void visitXmlAttributeValue(final XmlAttributeValue value) {
  final PsiElement element = value.getParent();
  if (!(element instanceof XmlAttribute)) return;

  final XmlAttribute attribute = (XmlAttribute)element;

  final XmlTag tag = attribute.getParent();
  if (tag == null) return;

  final XmlElementDescriptor descriptor = tag.getDescriptor();
  if (descriptor == null) return;

  final XmlAttributeDescriptor attributeDescriptor = descriptor.getAttributeDescriptor(attribute);
  if (attributeDescriptor != null) {
    if (attributeDescriptor.hasIdType()) {
      updateMap(attribute, value, false);
    }
    else {
      final PsiReference[] references = value.getReferences();
      for (PsiReference r : references) {
        if (r instanceof IdReferenceProvider.GlobalAttributeValueSelfReference /*&& !r.isSoft()*/) {
          updateMap(attribute, value, r.isSoft());
        }
        else if (r instanceof SchemaPrefixReference) {
          SchemaPrefix prefix = ((SchemaPrefixReference)r).resolve();
          if (prefix != null) {
            myHolder.addUsedPrefix(prefix.getName());
          }
        }
      }
    }

    if (attributeDescriptor.hasIdRefType() && PsiTreeUtil.getChildOfType(value, OuterLanguageElement.class) == null) {
      myHolder.registerIdReference(value);
    }
  }

  String s = value.getValue();
  detectPrefix(s);
  super.visitXmlAttributeValue(value);
}
项目:tools-idea    文件:XmlRefCountHolder.java   
@Override
public void visitXmlAttributeValue(final XmlAttributeValue value) {
  final PsiElement element = value.getParent();
  if (!(element instanceof XmlAttribute)) return;

  final XmlAttribute attribute = (XmlAttribute)element;

  final XmlTag tag = attribute.getParent();
  if (tag == null) return;

  final XmlElementDescriptor descriptor = tag.getDescriptor();
  if (descriptor == null) return;

  final XmlAttributeDescriptor attributeDescriptor = descriptor.getAttributeDescriptor(attribute);
  if (attributeDescriptor == null) return;

  if (attributeDescriptor.hasIdType()) {
    updateMap(attribute, value, false);
  }
  else {
    final PsiReference[] references = value.getReferences();
    for (PsiReference r : references) {
      if (r instanceof IdReferenceProvider.GlobalAttributeValueSelfReference /*&& !r.isSoft()*/) {
        updateMap(attribute, value, r.isSoft());
      }
      else if (r instanceof SchemaPrefixReference) {
        SchemaPrefix prefix = ((SchemaPrefixReference)r).resolve();
        if (prefix != null) {
          myHolder.addUsedPrefix(prefix.getName());
        }
      }
    }
  }

  if (attributeDescriptor.hasIdRefType() && PsiTreeUtil.getChildOfType(value, OuterLanguageElement.class) == null) {
    myHolder.registerIdReference(value);
  }

  String s = value.getValue();
  detectPrefix(s);
  super.visitXmlAttributeValue(value);
}
项目:consulo-xml    文件:XmlRefCountHolder.java   
@Override
public void visitXmlAttributeValue(final XmlAttributeValue value) {
  final PsiElement element = value.getParent();
  if (!(element instanceof XmlAttribute)) return;

  final XmlAttribute attribute = (XmlAttribute)element;

  final XmlTag tag = attribute.getParent();
  if (tag == null) return;

  final XmlElementDescriptor descriptor = tag.getDescriptor();
  if (descriptor == null) return;

  final XmlAttributeDescriptor attributeDescriptor = descriptor.getAttributeDescriptor(attribute);
  if (attributeDescriptor != null) {
    if (attributeDescriptor.hasIdType()) {
      updateMap(attribute, value, false);
    }
    else {
      final PsiReference[] references = value.getReferences();
      for (PsiReference r : references) {
        if (r instanceof IdReferenceProvider.GlobalAttributeValueSelfReference /*&& !r.isSoft()*/) {
          updateMap(attribute, value, r.isSoft());
        }
        else if (r instanceof SchemaPrefixReference) {
          SchemaPrefix prefix = ((SchemaPrefixReference)r).resolve();
          if (prefix != null) {
            myHolder.addUsedPrefix(prefix.getName());
          }
        }
      }
    }

    if (attributeDescriptor.hasIdRefType() && PsiTreeUtil.getChildOfType(value, OuterLanguageElement.class) == null) {
      myHolder.registerIdReference(value);
    }
  }

  String s = value.getValue();
  detectPrefix(s);
  super.visitXmlAttributeValue(value);
}