Java 类com.intellij.psi.xml.XmlElement 实例源码

项目:magento2-phpstorm-plugin    文件:PhpConstructorArgumentCompletionProvider.java   
@Override
protected void addCompletions(@NotNull CompletionParameters parameters,
                              ProcessingContext context,
                              @NotNull CompletionResultSet result) {
    PsiElement position = parameters.getPosition().getOriginalElement();
    if (position == null || !(position instanceof XmlElement)) {
        return;
    }


    DiIndex diIndex = DiIndex.getInstance(position.getProject());
    PhpClass phpClass = diIndex.getPhpClassOfArgument((XmlElement) position);
    if (phpClass != null) {
        Method constructor = phpClass.getConstructor();
        if (constructor != null) {
            for (Parameter parameter : constructor.getParameters()) {
                result.addElement(
                        LookupElementBuilder
                                .create(parameter.getName())
                                .withIcon(parameter.getIcon())
                );
            }
        }
    }
}
项目:magento2-phpstorm-plugin    文件:PhpServiceMethodCompletionContributor.java   
@Override
protected void addCompletions(@NotNull CompletionParameters parameters,
                              ProcessingContext context,
                              @NotNull CompletionResultSet result) {
    PsiElement position = parameters.getPosition().getOriginalElement();
    if (position == null) {
        return;
    }

    PhpClass phpClass = DiIndex.getPhpClassOfServiceMethod((XmlElement) position);
    if (phpClass != null) {
        for (Method method : phpClass.getMethods()) {
            result.addElement(
                    LookupElementBuilder
                            .create(method.getName())
                            .withIcon(method.getIcon())
            );
        }
    }
}
项目:magento2-phpstorm-plugin    文件:PhpServiceMethodReferenceProvider.java   
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    if (!(element instanceof XmlElement)) {
        return PsiReference.EMPTY_ARRAY;
    }

    List<PsiReference> psiReferences = new ArrayList<>();

    String methodName = StringUtil.unquoteString(element.getText());

    PhpClass phpClass = DiIndex.getPhpClassOfServiceMethod((XmlElement) element);
    if (phpClass != null) {
        Collection<Method> methods = phpClass.getMethods();
        methods.removeIf(m -> !m.getName().equalsIgnoreCase(methodName));
        psiReferences.add(new PolyVariantReferenceBase(element, methods));
    }

    return psiReferences.toArray(new PsiReference[psiReferences.size()]);
}
项目:magento2-phpstorm-plugin    文件:PhpConstructorArgumentReferenceProvider.java   
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {

    String parameterName = StringUtil.unquoteString(element.getText());
    if (parameterName.isEmpty() || !(element instanceof XmlElement)) {
        return PsiReference.EMPTY_ARRAY;
    }


    DiIndex diIndex = DiIndex.getInstance(element.getProject());
    PhpClass phpClass = diIndex.getPhpClassOfArgument((XmlElement) element);
    if (phpClass != null) {
        Method constructor = phpClass.getConstructor();
        if (constructor != null) {
            Collection<Parameter> parameterList = new THashSet<>(Arrays.asList(constructor.getParameters()));
            parameterList.removeIf(p -> !p.getName().contains(parameterName));
            if (parameterList.size() > 0) {
                return new PsiReference[] {new PolyVariantReferenceBase(element, parameterList)};
            }
        }
    }

    return PsiReference.EMPTY_ARRAY;
}
项目:hybris-integration-intellij-idea-plugin    文件:BeansUtils.java   
public static <T extends DomElement, V> GenericAttributeValue<V> expectDomAttributeValue(
    @NotNull final PsiElement element,
    @NotNull final Class<? extends T> domTagClass,
    @NotNull final Function<T, GenericAttributeValue<V>> domGetter
) {
    final DomManager domManager = DomManager.getDomManager(element.getProject());

    if (!(element instanceof XmlElement)) {
        return null;
    }

    final XmlAttribute xmlAttribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false);
    if (xmlAttribute == null) {
        return null;
    }

    final XmlTag xmlParentTag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
    DomElement domParentTag = domManager.getDomElement(xmlParentTag);

    return Optional.ofNullable(domParentTag)
                   .map(o -> ObjectUtils.tryCast(o, domTagClass))
                   .map(domGetter)
                   .filter(val -> val == domManager.getDomElement(xmlAttribute))
                   .orElse(null);
}
项目:hybris-integration-intellij-idea-plugin    文件:HybrisItemLineMakerProvider.java   
private void createTargetsWithGutterIcon(
    final Collection<? super RelatedItemLineMarkerInfo> result,
    final PsiClass psiClass,
    final Collection<XmlElement> list
) {
    final NavigationGutterIconBuilder builder
        = NavigationGutterIconBuilder.create(HybrisIcons.TYPE_SYSTEM).setTargets(list);

    builder.setEmptyPopupText(HybrisI18NBundleUtils.message(
        "hybris.gutter.navigate.no.matching.beans",
        new Object[0]
    ));

    builder.setPopupTitle(HybrisI18NBundleUtils.message(
        "hybris.bean.class.navigate.choose.class.title",
        new Object[0]
    ));
    builder.setTooltipText(HybrisI18NBundleUtils.message(
        "hybris.item.class.tooltip.navigate.declaration", new Object[0]
    ));
    result.add(builder.createLineMarkerInfo(psiClass.getNameIdentifier()));
}
项目:hybris-integration-intellij-idea-plugin    文件:TypeSystemGutterAnnotator.java   
private static Collection<XmlAttributeValue> findAlternativeDoms(@NotNull final ItemType source) {
    final String code = source.getCode().getStringValue();

    if (StringUtil.isEmpty(code)) {
        return Collections.emptyList();
    }
    final XmlElement element = source.getXmlElement();
    final PsiFile psiFile = element == null ? null : element.getContainingFile();

    if (psiFile == null) {
        return Collections.emptyList();
    }
    final TSMetaModel externalModel = TSMetaModelAccess.getInstance(psiFile.getProject()).
        getExternalTypeSystemMeta(psiFile);

    return Optional.ofNullable(externalModel.findMetaClassForDom(source))
                   .map(TSMetaClass::retrieveAllDomsStream)
                   .orElse(Stream.empty())
                   .filter(dom -> !dom.equals(source))
                   .map(ItemType::getCode)
                   .map(GenericAttributeValue::getXmlAttributeValue)
                   .collect(Collectors.toList());
}
项目:hybris-integration-intellij-idea-plugin    文件:TypeSystemGutterAnnotator.java   
@NotNull
private static Stream<TSMetaClass> getExtendingMetaClassNamesStream(@NotNull final ItemType source) {
    final String code = source.getCode().getStringValue();

    if (StringUtil.isEmpty(code)) {
        return Stream.empty();
    }
    final XmlElement xmlElement = source.getXmlElement();
    final PsiFile psiFile = xmlElement == null ? null : xmlElement.getContainingFile();

    if (psiFile == null) {
        return Stream.empty();
    }
    final TSMetaModel metaModel = TSMetaModelAccess.getInstance(psiFile.getProject()).getTypeSystemMeta(psiFile);
    final TSMetaClass sourceMeta = metaModel.findMetaClassForDom(source);

    if (sourceMeta == null) {
        return Stream.empty();
    }
    return metaModel
        .getMetaClassesStream()
        .map(TSMetaClass.class::cast)
        .filter(meta -> sourceMeta.getName().equals(meta.getExtendedMetaClassName()));
}
项目:ReactPropTypes-Plugin    文件:CommonAction.java   
@Nullable
private JSFunction getSelectStatelessComponent(String selectText, PsiFile file){
  return PsiTreeUtil.findChildrenOfType(file, JSFunction.class)
          .stream()
          .filter(o -> o.getName()!=null && o.getName().equals(selectText))
          .filter(o -> {
            XmlElement element = PsiTreeUtil.findChildrenOfType(o, XmlElement.class)
                    .stream()
                    .findFirst()
                    .orElse(null);
            return  element != null;
          })
          .findFirst()
          .orElse(null);

}
项目:catberry-idea-plugin    文件:CatberryAttributeDescriptor.java   
@Override
public PsiElement getValueDeclaration(XmlElement xmlElement, String value) {
  CatberryProjectConfigurationManager configurationManager = CatberryProjectConfigurationManager.getInstance(project);
  PsiDirectory directory = configurationManager.getStoresDirectory();
  if(directory == null)
    return super.getValueDeclaration(xmlElement, value);
  final String requiredPath = directory.getVirtualFile().getPath() + "/" + value+".js";

  int index = value.lastIndexOf('/');
  String className = index == -1 ? value : value.substring(index+1);
  Collection<JSElement> elements = StubIndex.getElements(JSClassIndex.KEY, className, project,
      GlobalSearchScope.allScope(project), JSElement.class);

  for(JSElement element : elements) {
    if (element instanceof JSClass &&  element.getContainingFile().getVirtualFile().getPath().equals(requiredPath))
      return element;
  }
  return super.getValueDeclaration(xmlElement, value);
}
项目:intellij-ce-playground    文件:BasicSelectioner.java   
public static boolean canSelectBasic(final PsiElement e) {
  return
    !(e instanceof PsiWhiteSpace) &&
    !(e instanceof PsiComment) &&
    !(e instanceof PsiCodeBlock) &&
    !(e instanceof PsiArrayInitializerExpression) &&
    !(e instanceof PsiParameterList) &&
    !(e instanceof PsiExpressionList) &&
    !(e instanceof PsiBlockStatement) &&
    !(e instanceof PsiJavaCodeReferenceElement) &&
    !(e instanceof PsiJavaToken &&
    !(e instanceof PsiKeyword)) &&
    !(e instanceof XmlToken) &&
    !(e instanceof XmlElement) &&
    !(e instanceof PsiDocTag);
}
项目:intellij-ce-playground    文件:XPathEvalAction.java   
/**
 * Opens an input box to input an XPath expression. The box will have a history dropdown from which
 * previously entered expressions can be selected.
 * @return The expression or <code>null</code> if the user hits the cancel button
 * @param project The project to take the history from
 */
@Nullable
private EvalExpressionDialog.Context inputXPathExpression(final Project project, XmlElement contextNode) {
    final XPathProjectComponent pc = XPathProjectComponent.getInstance(project);
    LOG.assertTrue(pc != null);

    // get expression history from project component
    final HistoryElement[] history = pc.getHistory();

    final EvalExpressionDialog dialog = new EvalExpressionDialog(project, myComponent.getConfig(), history);
    if (!dialog.show(contextNode)) {
        // cancel
        LOG.debug("Input canceled");
        return null;
    }

    final InputExpressionDialog.Context context = dialog.getContext();
    LOG.debug("expression = " + context.input.expression);

    pc.addHistory(context.input);

    return context;
}
项目:intellij-ce-playground    文件:XPathEvalAction.java   
private void showUsageView(final Editor editor, final XPath xPath, final XmlElement contextNode, final List<?> result) {
    final Project project = editor.getProject();

    //noinspection unchecked
    final List<?> _result = new ArrayList(result);
    final Factory<UsageSearcher> searcherFactory = new Factory<UsageSearcher>() {
        @Override
        public UsageSearcher create() {
            return new MyUsageSearcher(_result, xPath, contextNode);
        }
    };
    final MyUsageTarget usageTarget = new MyUsageTarget(xPath.toString(), contextNode);

    showUsageView(project, usageTarget, searcherFactory, new EditExpressionAction() {
        final Config config = myComponent.getConfig();

        @Override
        protected void execute() {
            XPathEvalAction.this.execute(editor);
        }
    });
}
项目:intellij-ce-playground    文件:MavenDomUtil.java   
public static int getCollectionIndex(@NotNull final MavenDomDependencies dependencies, @Nullable final Editor editor) {
  if (editor != null) {
    int offset = editor.getCaretModel().getOffset();

    List<MavenDomDependency> dependencyList = dependencies.getDependencies();

    for (int i = 0; i < dependencyList.size(); i++) {
      MavenDomDependency dependency = dependencyList.get(i);
      XmlElement xmlElement = dependency.getXmlElement();

      if (xmlElement != null && xmlElement.getTextRange().getStartOffset() >= offset) {
        return i;
      }
    }
  }
  return -1;
}
项目:intellij-ce-playground    文件:AntResolveInspection.java   
@NotNull
private static Collection<PropertiesFile> getPropertyFiles(@Nullable AntDomProject antDomProject, @NotNull XmlElement stopElement) {
  if (antDomProject == null) {
    return Collections.emptyList();
  }
  final Set<PropertiesFile> files = new java.util.HashSet<PropertiesFile>();
  final int stopOffset = stopElement.getTextOffset();

  for (Iterator<AntDomElement> iterator = antDomProject.getAntChildrenIterator(); iterator.hasNext(); ) {
    AntDomElement child = iterator.next();
    final XmlElement xmlElement = child.getXmlElement();
    if (xmlElement != null && xmlElement.getTextOffset() >= stopOffset) {
      break; // no need to offer to add properties to files that are imported after the property reference
    }
    if (child instanceof AntDomProperty) {
      final AntDomProperty property = (AntDomProperty)child;
      final PropertiesFile file = property.getPropertiesFile();
      if (file != null) {
        files.add(file);
      }
    }
  }
  return files;
}
项目:intellij-ce-playground    文件:XsdEnumerationDescriptor.java   
private boolean processEnumeration(XmlElement context, PairProcessor<PsiElement, String> processor, boolean forCompletion) {
  XmlTag contextTag = context != null ? PsiTreeUtil.getContextOfType(context, XmlTag.class, false) : null;
  final XmlElementDescriptorImpl elementDescriptor = (XmlElementDescriptorImpl)XmlUtil.findXmlDescriptorByType(getDeclaration(), contextTag);

  if (elementDescriptor!=null && elementDescriptor.getType() instanceof ComplexTypeDescriptor) {
    return processEnumerationImpl(((ComplexTypeDescriptor)elementDescriptor.getType()).getDeclaration(), processor, forCompletion);
  }

  final String namespacePrefix = getDeclaration().getNamespacePrefix();
  XmlTag type = getDeclaration().findFirstSubTag(
    ((namespacePrefix.length() > 0) ? namespacePrefix + ":" : "") + "simpleType"
  );

  if (type != null) {
    return processEnumerationImpl(type, processor, forCompletion);
  }

  return false;
}
项目:intellij-ce-playground    文件:XsltNamespaceContext.java   
public static Collection<String> getPrefixes(XmlElement context) {
    final XmlTag tag = PsiTreeUtil.getParentOfType(context, XmlTag.class);
    if (tag != null) {
        final HashSet<String> allPrefixes = new HashSet<String>();
        final String[] uris = tag.knownNamespaces();
        for (String uri : uris) {
            for (XmlTag p = tag; p != null; p = p.getParentTag()) {
                final Set<Map.Entry<String,String>> localPrefixes = p.getLocalNamespaceDeclarations().entrySet();
                for (Map.Entry<String,String> entry : localPrefixes) {
                    final String prefix = entry.getKey();
                    if (!prefix.isEmpty() && entry.getValue().equals(uri)) {
                        if (!allPrefixes.contains(prefix)) {
                            allPrefixes.add(prefix);
                        }
                    }
                }
            }
        }
        return allPrefixes;
    } else {
        return Collections.emptySet();
    }
}
项目:intellij-ce-playground    文件:XmlTextTest.java   
public void testInsertAtOffset() throws Exception {
  new WriteCommandAction(getProject()) {

    @Override
    protected void run(@NotNull final Result result) throws Throwable {
      String xml = "<root>0123456789</root>";
      XmlFile file = (XmlFile)PsiFileFactory.getInstance(getProject())
        .createFileFromText("foo.xml", StdFileTypes.XML, xml, (long)1, true, false);
      //System.out.println(DebugUtil.psiToString(file, false));
      XmlTag root = file.getDocument().getRootTag();
      final XmlText text1 = root.getValue().getTextElements()[0];

      assertFalse(CodeEditUtil.isNodeGenerated(root.getNode()));
      final XmlText text = text1;

      final XmlElement element = text.insertAtOffset(XmlElementFactory.getInstance(getProject()).createTagFromText("<bar/>"), 5);
      assertNotNull(element);
      assertTrue(element instanceof XmlText);
      assertEquals("01234", element.getText());
      assertEquals("<root>01234<bar/>56789</root>", text.getContainingFile().getText());
    }
  }.execute();
}
项目:intellij-ce-playground    文件:XmlElementImpl.java   
@Nullable
protected static String getNameFromEntityRef(final CompositeElement compositeElement, final IElementType xmlEntityDeclStart) {
  final ASTNode node = compositeElement.findChildByType(xmlEntityDeclStart);
  if (node == null) return null;
  ASTNode name = node.getTreeNext();

  if (name != null && name.getElementType() == TokenType.WHITE_SPACE) {
    name = name.getTreeNext();
  }

  if (name != null && name.getElementType() == XmlElementType.XML_ENTITY_REF) {
    final StringBuilder builder = new StringBuilder();

    ((XmlElement)name.getPsi()).processElements(new PsiElementProcessor() {
      @Override
      public boolean execute(@NotNull final PsiElement element) {
        builder.append(element.getText());
        return true;
      }
    }, name.getPsi());
    if (builder.length() > 0) return builder.toString();
  }
  return null;
}
项目:intellij-ce-playground    文件:InputExpressionDialog.java   
@SuppressWarnings({"unchecked"})
private void prepareShow(XmlElement contextElement) {

    final NamespaceCollector.CollectedInfo collectedInfo;
    if (contextElement != null) {
        collectedInfo = NamespaceCollector.collectInfo((XmlFile)contextElement.getContainingFile());
        myNamespaceCache = collectedInfo.namespaces;
    } else {
        collectedInfo = NamespaceCollector.empty();
        myNamespaceCache = null;
    }

    myContextProvider = new InteractiveContextProvider(contextElement, collectedInfo, myModel);
    myContextProvider.attachTo(myXPathFile);

    final HistoryElement historyElement = myModel.getSelectedItem();
    if (historyElement != null) {
        myContextProvider.getNamespaceContext().setMap(asMap(historyElement.namespaces));
    } else {
        myContextProvider.getNamespaceContext().setMap(asMap(null));
    }

    updateOkAction();
}
项目:AppleScript-IDEA    文件:DictionaryIdentifierImpl.java   
public DictionaryIdentifierImpl(@NotNull DictionaryComponent myParent, @NotNull String varIdentifierText,
                                @NotNull XmlElement myXmlAttributeValue) {
  super(myXmlAttributeValue, myParent);
  this.varIdentifierText = varIdentifierText;
  varIdentifierTextList = new ArrayList<>(Arrays.asList(varIdentifierText.split(" ")));
  myVarIdentifier = new DictionaryIdentifierImpl(myParent, varIdentifierTextList.get(0), myXmlElement);
}
项目:hybris-integration-intellij-idea-plugin    文件:TSStructureTreeElement.java   
private String localizeDescription(final DomElement dom) {
    if (dom instanceof Description) {
        final XmlElement xmlElement = dom.getXmlElement();
        if (xmlElement instanceof XmlTag) {
            final XmlTagValue value = ((XmlTag) xmlElement).getValue();
            if (value != null) {
                return value.getTrimmedText();
            }
        }
    }
    return null;
}
项目:intellij-ce-playground    文件:ExtendsClassChecker.java   
public static List<DomElementProblemDescriptor> checkExtendsClassInReferences(final GenericDomValue element, final DomElementAnnotationHolder holder) {
  if (!isPsiClassType(element)) {
    return Collections.emptyList();
  }

  final Object valueObject = element.getValue();
  if (!(valueObject instanceof PsiClass)) return Collections.emptyList();

  final XmlElement valueElement = DomUtil.getValueElement(element);
  if (valueElement == null) return Collections.emptyList();

  final PsiReference[] references = ourProvider.getReferencesByElement(valueElement, new ProcessingContext());
  for (PsiReference reference : references) {
    if (reference instanceof JavaClassReference) {
      final PsiReferenceProvider psiReferenceProvider = ((JavaClassReference)reference).getProvider();
      final String[] value = psiReferenceProvider instanceof JavaClassReferenceProvider ? JavaClassReferenceProvider.EXTEND_CLASS_NAMES
        .getValue(((JavaClassReferenceProvider)psiReferenceProvider).getOptions()) : null;
      if (value != null && value.length != 0) {
        for (String className : value) {
          final List<DomElementProblemDescriptor> problemDescriptors =
            checkExtendClass(element, ((PsiClass)valueObject), className, false, false, true, false, true, true, holder);
          if (!problemDescriptors.isEmpty()) {
            return problemDescriptors;
          }
        }
      }
    }
  }
  return Collections.emptyList();
}
项目:intellij-ce-playground    文件:InputExpressionDialog.java   
@SuppressWarnings({ "unchecked" })
public boolean show(XmlElement contextElement) {
    prepareShow(contextElement);

    show();

    return isOK();
}
项目:intellij-ce-playground    文件:DomElementAnnotationHolderImpl.java   
@Override
@NotNull
public Annotation createAnnotation(@NotNull DomElement element, HighlightSeverity severity, @Nullable String message) {
  final XmlElement xmlElement = element.getXmlElement();
  LOG.assertTrue(xmlElement != null, "No XML element for " + element);
  final TextRange range = xmlElement.getTextRange();
  final int startOffset = range.getStartOffset();
  final int endOffset = message == null ? startOffset : range.getEndOffset();
  final Annotation annotation = new Annotation(startOffset, endOffset, severity, message, null);
  myAnnotations.add(annotation);
  return annotation;
}
项目:intellij-ce-playground    文件:ShowXPathAction.java   
protected boolean isEnabledAt(XmlFile xmlFile, int offset) {
    final PsiElement element = xmlFile.findElementAt(offset);
    if (!(element instanceof XmlElement || element instanceof PsiWhiteSpace)) {
        return false;
    }

    final PsiElement node = XPathExpressionGenerator.transformToValidShowPathNode(element);
    return node != null;
}
项目:intellij-ce-playground    文件:CompletionLists.java   
private static void addNamespaceCompletions(NamespaceContext namespaceContext, Set<Lookup> list, XmlElement context) {
  if (namespaceContext != null) {
    final Collection<String> knownPrefixes = namespaceContext.getKnownPrefixes(context);
    for (String prefix : knownPrefixes) {
      if (prefix != null && prefix.length() > 0) {
        list.add(new NamespaceLookup(prefix));
      }
    }
  }
}
项目:intellij-ce-playground    文件: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    文件:EnumConverter.java   
@Override
@NotNull
public Collection<? extends T> getVariants(final ConvertContext context) {
  final XmlElement element = context.getXmlElement();
  if (element instanceof XmlTag) {
    final XmlTag simpleContent = XmlUtil.getSchemaSimpleContent((XmlTag)element);
    if (simpleContent != null && XmlUtil.collectEnumerationValues(simpleContent, new HashSet<String>())) {
      return Collections.emptyList();
    }
  }
  return Arrays.asList(myType.getEnumConstants());
}
项目:intellij-ce-playground    文件:IndexedElementInvocationHandler.java   
@Override
protected XmlElement recomputeXmlElement(@NotNull final DomInvocationHandler parentHandler) {
  final XmlTag tag = parentHandler.getXmlTag();
  if (tag == null) return null;

  final List<XmlTag> tags = DomImplUtil.findSubTags(tag, getXmlName(), parentHandler.getFile());
  if (tags.size() <= myIndex) return null;

  return tags.get(myIndex);
}
项目:intellij-ce-playground    文件:Xslt2ContextProvider.java   
@Override
@NotNull
public FunctionContext createFunctionContext() {
  final XmlElement contextElement = getContextElement();
  return contextElement != null && contextElement.isValid() ?
          functionContextCache.get((XmlFile)contextElement.getContainingFile(), null) :
          Xslt2FunctionContext.getInstance();
}
项目:intellij-ce-playground    文件:AntDomTargetDependsListConverter.java   
@NotNull
public PsiReference[] createReferences(GenericDomValue<TargetResolver.Result> value, PsiElement element, ConvertContext context) {
  final XmlElement xmlElement = value.getXmlElement();
  if (!(xmlElement instanceof XmlAttribute)) {
    return PsiReference.EMPTY_ARRAY;
  }
  final XmlAttributeValue valueElement = ((XmlAttribute)xmlElement).getValueElement();
  if (valueElement == null) {
    return PsiReference.EMPTY_ARRAY;
  }
  final String refsString = value.getStringValue();
  if (refsString == null) {
    return PsiReference.EMPTY_ARRAY;
  }
  final List<PsiReference> refs = new ArrayList<PsiReference>();
  final AntDomTargetReference.ReferenceGroup group = new AntDomTargetReference.ReferenceGroup();
  final TextRange wholeStringRange = ElementManipulators.getValueTextRange(valueElement);
  final StringTokenizer tokenizer = new StringTokenizer(refsString, ",", false);
  while (tokenizer.hasMoreTokens()) {
    final String token = tokenizer.nextToken();
    int tokenStartOffset = tokenizer.getCurrentPosition() - token.length();
    final String ref = token.trim();
    if (ref.length() != token.length()) {
      for (int idx = 0; idx < token.length(); idx++) {
        if (Character.isWhitespace(token.charAt(idx))) {
          tokenStartOffset++;
        }
        else {
          break;
        }
      }
    }
    refs.add(new AntDomTargetReference(element, TextRange.from(wholeStringRange.getStartOffset() + tokenStartOffset, ref.length()), group));
  }
  return refs.toArray(new PsiReference[refs.size()]);
}
项目:intellij-ce-playground    文件:DependencyConfigFileConverter.java   
@Override
public PathReference fromString(@Nullable String s, ConvertContext context) {
  final XmlElement element = context.getXmlElement();
  final Module module = context.getModule();
  if (s == null || element == null || module == null) {
    return null;
  }
  return PathReferenceManager.getInstance().getCustomPathReference(s, module, element, ourProvider);
}
项目:intellij-ce-playground    文件:ExtractManagedDependenciesAction.java   
private static PsiFile[] getFiles(@NotNull PsiFile file, @NotNull MavenDomProjectModel model, @NotNull Set<MavenDomDependency> usages) {
  Set<PsiFile> files = new HashSet<PsiFile>();

  files.add(file);
  XmlElement xmlElement = model.getXmlElement();
  if (xmlElement != null) files.add(xmlElement.getContainingFile());
  for (MavenDomDependency usage : usages) {
    XmlElement element = usage.getXmlElement();
    if (element != null) {
      files.add(element.getContainingFile());
    }
  }

  return PsiUtilCore.toPsiFileArray(files);
}
项目:intellij-ce-playground    文件:DomManagerImpl.java   
@Nullable
public final DomFileDescription<?> getDomFileDescription(PsiElement element) {
  if (element instanceof XmlElement) {
    final PsiFile psiFile = element.getContainingFile();
    if (psiFile instanceof XmlFile) {
      return getDomFileDescription((XmlFile)psiFile);
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:ResourceReferenceConverter.java   
@Nullable
static String getValue(XmlElement element) {
  if (element instanceof XmlAttribute) {
    return ((XmlAttribute)element).getValue();
  }
  else if (element instanceof XmlTag) {
    return ((XmlTag)element).getValue().getText();
  }
  return null;
}
项目:intellij-ce-playground    文件:AntDomProject.java   
@Nullable
public PsiElement getNavigationElement(String propertyName) {
  final DomTarget target = DomTarget.getTarget(this);
  final PsiElement nameElementPsi = target != null ? PomService.convertToPsi(target) : null;
  if (nameElementPsi != null) {
    return nameElementPsi;
  }
  final XmlElement xmlElement = getXmlElement();
  return xmlElement != null? xmlElement.getNavigationElement() : null;
}
项目:intellij-ce-playground    文件:PhysicalDomParentStrategy.java   
public static boolean strategyEquals(DomParentStrategy strategy, final Object o) {

    if (strategy == o) return true;
    if (!(o instanceof DomParentStrategy)) return false;
    final XmlElement thatElement = ((DomParentStrategy)o).getXmlElement();
    if (thatElement == null) return false;
    XmlElement element = strategy.getXmlElement();
    if (element == null) return false;

    if (xmlElementsEqual(element, thatElement)) {
      if (element != thatElement) {
        final PsiElement nav1 = element.getNavigationElement();
        final PsiElement nav2 = thatElement.getNavigationElement();
        if (nav1 != nav2) {
          PsiElement curContext = findIncluder(element);
          PsiElement navContext = findIncluder(nav1);
          LOG.error(LogMessageEx.createEvent(
            "x:include processing error",
            "nav1,nav2=" + nav1 + ", " + nav2 + ";\n" +
            nav1.getContainingFile() + ":" + nav1.getTextRange().getStartOffset() + "!=" + nav2.getContainingFile() + ":" + nav2.getTextRange().getStartOffset() + ";\n" +
            (nav1 == element) + ";" + (nav2 == thatElement) + ";\n" +
            "contexts equal: " +  (curContext == navContext) + ";\n" +
            "curContext?.physical=" + (curContext != null && curContext.isPhysical()) + ";\n" +
            "navContext?.physical=" + (navContext != null && navContext.isPhysical()) + ";\n" +
            "myElement.physical=" + element.isPhysical() + ";\n" +
            "thatElement.physical=" + thatElement.isPhysical() + "\n" + DebugUtil.currentStackTrace(),
            new Attachment("Including tag text 1.xml", curContext == null ? "null" : curContext.getText()),
            new Attachment("Including tag text 2.xml", navContext == null ? "null" : navContext.getText())
          ));
          throw new AssertionError();
        }
      }
      return true;
    }
    return false;
  }
项目:intellij-ce-playground    文件:DomPatterns.java   
/**
 * @deprecated use {@link #tagWithDom(String, ElementPattern)} and  {@link #attributeWithDom(String, ElementPattern)}
 */
public static XmlElementPattern.Capture withDom(final ElementPattern<? extends DomElement> pattern) {
  return new XmlElementPattern.Capture().with(new PatternCondition<XmlElement>("tagWithDom") {
    @Override
    public boolean accepts(@NotNull final XmlElement xmlElement, final ProcessingContext context) {
      final DomManager manager = DomManager.getDomManager(xmlElement.getProject());
      if (xmlElement instanceof XmlAttribute) {
        return pattern.accepts(manager.getDomElement((XmlAttribute)xmlElement), context);
      }
      return xmlElement instanceof XmlTag && pattern.accepts(manager.getDomElement((XmlTag)xmlElement), context);
    }
  });
}
项目:intellij-ce-playground    文件:QNameUtil.java   
public static QName createQName(@NotNull String qname, @NotNull PsiElement context) {
    final String[] strings = qname.split(":", 2);
    if (strings.length == 1) {
        return new QName(null, qname);
    }
    final XmlElement ctx = PsiTreeUtil.getParentOfType(context, XmlElement.class, false);
    if (ctx == null) return UNRESOLVED;
    final String uri = XsltNamespaceContext.getNamespaceUriStatic(strings[0], ctx);
    if (uri == null) return UNRESOLVED;

    return new QName(uri, strings[1], strings[0]);
}