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

项目:rythm_plugin    文件:ImportReferenceProvider.java   
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    if (element instanceof RythmRythmImpl) {
        final ASTNode importNode = element.getNode().findChildByType(RythmTypes.RYTHM_IMPORT);
        if (importNode != null) {
            final PsiElement importInstr = importNode.getPsi();
            final String instructionTarget = RythmJavPsiUtil.getInstructionTarget("@import", (XmlProcessingInstruction /*XmlProcessingInstruction*/) element);
            if (instructionTarget != null && instructionTarget.equals(importInstr.getText())) {
                final PsiReference[] references = RythmReferenceContributor.CLASS_REFERENCE_PROVIDER.getReferencesByString(instructionTarget, element, importInstr.getStartOffsetInParent());
                if (instructionTarget.endsWith(".*")) {
                    return ArrayUtil.remove(references, references.length - 1);
                } else {
                    return references;
                }
            }
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
项目:intellij-ce-playground    文件:JavaFxInjectPageLanguageIntention.java   
public void registerPageLanguage(final Project project, final XmlFile containingFile, final String languageName) {
  new WriteCommandAction.Simple(project, getFamilyName()) {
    @Override
    protected void run() {
      final PsiFileFactory factory = PsiFileFactory.getInstance(project);
      final XmlFile dummyFile = (XmlFile)factory.createFileFromText("_Dummy_.fxml", StdFileTypes.XML,
                                                                    "<?language " + languageName + "?>");
      final XmlDocument document = dummyFile.getDocument();
      if (document != null) {
        final XmlProlog prolog = document.getProlog();
        final Collection<XmlProcessingInstruction> instructions = PsiTreeUtil.findChildrenOfType(prolog, XmlProcessingInstruction.class);
        LOG.assertTrue(instructions.size() == 1);
        final XmlDocument xmlDocument = containingFile.getDocument();
        if (xmlDocument != null) {
          final XmlProlog xmlProlog = xmlDocument.getProlog();
          if (xmlProlog != null) {
            final PsiElement element = xmlProlog.addBefore(instructions.iterator().next(), xmlProlog.getFirstChild());
            xmlProlog.addAfter(PsiParserFacade.SERVICE.getInstance(project).createWhiteSpaceFromText("\n\n"), element);
          }
        }
      }
    }
  }.execute();
}
项目:intellij-ce-playground    文件:ImportReferenceProvider.java   
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
  if (element instanceof XmlProcessingInstruction) {
    final ASTNode importNode = element.getNode().findChildByType(XmlTokenType.XML_TAG_CHARACTERS);
    if (importNode != null) {
      final PsiElement importInstr = importNode.getPsi();
      final String instructionTarget = JavaFxPsiUtil.getInstructionTarget("import", (XmlProcessingInstruction)element);
      if (instructionTarget != null && instructionTarget.equals(importInstr.getText())) {
        final PsiReference[] references =
          FxmlReferencesContributor.CLASS_REFERENCE_PROVIDER.getReferencesByString(instructionTarget, element, importInstr.getStartOffsetInParent());
        if (instructionTarget.endsWith(".*")) {
          return ArrayUtil.remove(references, references.length - 1);
        }
        else {
          return references;
        }
      }
    }
  }
  return PsiReference.EMPTY_ARRAY;
}
项目:tools-idea    文件:JavaFxInjectPageLanguageIntention.java   
private void registerPageLanguage(final Project project, final XmlFile containingFile, final String languageName) {
  new WriteCommandAction.Simple(project, getFamilyName()) {
    @Override
    protected void run() {
      final PsiFileFactory factory = PsiFileFactory.getInstance(project);
      final XmlFile dummyFile = (XmlFile)factory.createFileFromText("_Dummy_.fxml", StdFileTypes.XML,
                                                                    "<?language " + languageName + "?>");
      final XmlDocument document = dummyFile.getDocument();
      if (document != null) {
        final XmlProlog prolog = document.getProlog();
        final Collection<XmlProcessingInstruction> instructions = PsiTreeUtil.findChildrenOfType(prolog, XmlProcessingInstruction.class);
        LOG.assertTrue(instructions.size() == 1);
        final XmlDocument xmlDocument = containingFile.getDocument();
        if (xmlDocument != null) {
          final XmlProlog xmlProlog = xmlDocument.getProlog();
          if (xmlProlog != null) {
            final PsiElement element = xmlProlog.addBefore(instructions.iterator().next(), xmlProlog.getFirstChild());
            xmlProlog.addAfter(PsiParserFacade.SERVICE.getInstance(project).createWhiteSpaceFromText("\n\n"), element);
          }
        }
      }
    }
  }.execute();
}
项目:tools-idea    文件:ImportReferenceProvider.java   
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
  if (element instanceof XmlProcessingInstruction) {
    final ASTNode importNode = element.getNode().findChildByType(XmlTokenType.XML_TAG_CHARACTERS);
    if (importNode != null) {
      final PsiElement importInstr = importNode.getPsi();
      final String instructionTarget = JavaFxPsiUtil.getInstructionTarget("import", (XmlProcessingInstruction)element);
      if (instructionTarget != null && instructionTarget.equals(importInstr.getText())) {
        final PsiReference[] references =
          FxmlReferencesContributor.CLASS_REFERENCE_PROVIDER.getReferencesByString(instructionTarget, element, importInstr.getStartOffsetInParent());
        if (instructionTarget.endsWith(".*")) {
          return ArrayUtil.remove(references, references.length - 1);
        }
        else {
          return references;
        }
      }
    }
  }
  return PsiReference.EMPTY_ARRAY;
}
项目:consulo-javafx    文件:JavaFxInjectPageLanguageIntention.java   
private void registerPageLanguage(final Project project, final XmlFile containingFile, final String languageName) {
  new WriteCommandAction.Simple(project, getFamilyName()) {
    @Override
    protected void run() {
      final PsiFileFactory factory = PsiFileFactory.getInstance(project);
      final XmlFile dummyFile = (XmlFile)factory.createFileFromText("_Dummy_.fxml", XmlFileType.INSTANCE,
                                                                    "<?language " + languageName + "?>");
      final XmlDocument document = dummyFile.getDocument();
      if (document != null) {
        final XmlProlog prolog = document.getProlog();
        final Collection<XmlProcessingInstruction> instructions = PsiTreeUtil.findChildrenOfType(prolog, XmlProcessingInstruction.class);
        LOG.assertTrue(instructions.size() == 1);
        final XmlDocument xmlDocument = containingFile.getDocument();
        if (xmlDocument != null) {
          final XmlProlog xmlProlog = xmlDocument.getProlog();
          if (xmlProlog != null) {
            final PsiElement element = xmlProlog.addBefore(instructions.iterator().next(), xmlProlog.getFirstChild());
            xmlProlog.addAfter(PsiParserFacade.SERVICE.getInstance(project).createWhiteSpaceFromText("\n\n"), element);
          }
        }
      }
    }
  }.execute();
}
项目:consulo-javafx    文件:ImportReferenceProvider.java   
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
  if (element instanceof XmlProcessingInstruction) {
    final ASTNode importNode = element.getNode().findChildByType(XmlTokenType.XML_TAG_CHARACTERS);
    if (importNode != null) {
      final PsiElement importInstr = importNode.getPsi();
      final String instructionTarget = JavaFxPsiUtil.getInstructionTarget("import", (XmlProcessingInstruction)element);
      if (instructionTarget != null && instructionTarget.equals(importInstr.getText())) {
        final PsiReference[] references =
          FxmlReferencesContributor.CLASS_REFERENCE_PROVIDER.getReferencesByString(instructionTarget, element, importInstr.getStartOffsetInParent());
        if (instructionTarget.endsWith(".*")) {
          return ArrayUtil.remove(references, references.length - 1);
        }
        else {
          return references;
        }
      }
    }
  }
  return PsiReference.EMPTY_ARRAY;
}
项目:consulo-javafx    文件:JavaFxPsiUtil.java   
private static List<String> parseInstructions(XmlFile file, String instructionName) {
  List<String> definedImports = new ArrayList<String>();
  XmlDocument document = file.getDocument();
  if (document != null) {
    XmlProlog prolog = document.getProlog();

    final Collection<XmlProcessingInstruction>
      instructions = new ArrayList<XmlProcessingInstruction>(PsiTreeUtil.findChildrenOfType(prolog, XmlProcessingInstruction.class));
    for (final XmlProcessingInstruction instruction : instructions) {
      final String instructionTarget = getInstructionTarget(instructionName, instruction);
      if (instructionTarget != null) {
        definedImports.add(instructionTarget);
      }
    }
  }
  return definedImports;
}
项目:consulo-javafx    文件:JavaFxPsiUtil.java   
public static void insertImportWhenNeeded(XmlFile xmlFile,
                                          String shortName,
                                          String qualifiedName) {
  if (shortName != null && findPsiClass(shortName, xmlFile.getRootTag()) == null) {
    final XmlDocument document = xmlFile.getDocument();
    if (document != null) {
      final XmlProcessingInstruction processingInstruction = createSingleImportInstruction(qualifiedName, xmlFile.getProject());
      final XmlProlog prolog = document.getProlog();
      if (prolog != null) {
        prolog.add(processingInstruction);
      } else {
        document.addBefore(processingInstruction, document.getRootTag());
      }
      PostprocessReformattingAspect.getInstance(xmlFile.getProject()).doPostponedFormatting(xmlFile.getViewProvider());
    }
  }
}
项目:tools-idea    文件:GenerateDTDAction.java   
@NotNull
protected CodeInsightActionHandler getHandler(){
  return new CodeInsightActionHandler(){
    public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
      final XmlDocument document = findSuitableXmlDocument(file);
      if (document != null) {
        final @NonNls StringBuffer buffer = new StringBuffer();
        buffer.append("<!DOCTYPE " + document.getRootTag().getName() + " [\n");
        buffer.append(XmlUtil.generateDocumentDTD(document, true));
        buffer.append("]>\n");
        XmlFile tempFile;
          try{
            final XmlProlog prolog = document.getProlog();
            final PsiElement childOfType = PsiTreeUtil.getChildOfType(prolog, XmlProcessingInstruction.class);
            if (childOfType != null) {
              final String text = childOfType.getText();
              buffer.insert(0,text);
              final PsiElement nextSibling = childOfType.getNextSibling();
              if (nextSibling instanceof PsiWhiteSpace) {
                buffer.insert(text.length(),nextSibling.getText());
              }
            }
            tempFile = (XmlFile)PsiFileFactory.getInstance(file.getProject()).createFileFromText("dummy.xml", buffer.toString());
            prolog.replace(tempFile.getDocument().getProlog());
          }
        catch (IncorrectOperationException e) {
          LOG.error(e);
        }
      }
    }

    public boolean startInWriteAction(){
      return true;
    }
  };
}
项目:consulo-javafx    文件:JavaFxPsiUtil.java   
@Nullable
public static String getInstructionTarget(String instructionName, XmlProcessingInstruction instruction) {
  final ASTNode node = instruction.getNode();
  ASTNode xmlNameNode = node.findChildByType(XmlTokenType.XML_NAME);
  ASTNode importNode = node.findChildByType(XmlTokenType.XML_TAG_CHARACTERS);
  if (!(xmlNameNode == null || !instructionName.equals(xmlNameNode.getText()) || importNode == null)) {
    return importNode.getText();
  }
  return null;
}
项目:consulo-xml    文件:XmlAttributeValuePattern.java   
public XmlAttributeValuePattern withLocalName(ElementPattern<String> namePattern)
{
    return with(new PsiNamePatternCondition<XmlAttributeValue>("withLocalName", namePattern)
    {
        @Override
        public String getPropertyValue(@NotNull final Object o)
        {
            if(o instanceof XmlAttributeValue)
            {
                final XmlAttributeValue value = (XmlAttributeValue) o;
                final PsiElement parent = value.getParent();
                if(parent instanceof XmlAttribute)
                {
                    return ((XmlAttribute) parent).getLocalName();
                }
                if(parent instanceof XmlProcessingInstruction)
                {
                    PsiElement prev = value.getPrevSibling();
                    if(!(prev instanceof XmlToken) || ((XmlToken) prev).getTokenType() != XmlTokenType.XML_EQ)
                    {
                        return null;
                    }
                    prev = prev.getPrevSibling();
                    if(!(prev instanceof XmlToken) || ((XmlToken) prev).getTokenType() != XmlTokenType.XML_NAME)
                    {
                        return null;
                    }
                    return prev.getText();
                }
            }
            return null;
        }
    });
}
项目:consulo-xml    文件:GenerateDTDAction.java   
@NotNull
protected CodeInsightActionHandler getHandler(){
  return new CodeInsightActionHandler(){
    public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
      final XmlDocument document = findSuitableXmlDocument(file);
      if (document != null) {
        final @NonNls StringBuffer buffer = new StringBuffer();
        buffer.append("<!DOCTYPE " + document.getRootTag().getName() + " [\n");
        buffer.append(XmlUtil.generateDocumentDTD(document, true));
        buffer.append("]>\n");
        XmlFile tempFile;
          try{
            final XmlProlog prolog = document.getProlog();
            final PsiElement childOfType = PsiTreeUtil.getChildOfType(prolog, XmlProcessingInstruction.class);
            if (childOfType != null) {
              final String text = childOfType.getText();
              buffer.insert(0,text);
              final PsiElement nextSibling = childOfType.getNextSibling();
              if (nextSibling instanceof PsiWhiteSpace) {
                buffer.insert(text.length(),nextSibling.getText());
              }
            }
            tempFile = (XmlFile)PsiFileFactory.getInstance(file.getProject()).createFileFromText("dummy.xml", buffer.toString());
            prolog.replace(tempFile.getDocument().getProlog());
          }
        catch (IncorrectOperationException e) {
          LOG.error(e);
        }
      }
    }

    public boolean startInWriteAction(){
      return true;
    }
  };
}
项目:intellij-ce-playground    文件:XmlProcessingInstructionManipulator.java   
@Override
public XmlProcessingInstruction handleContentChange(@NotNull XmlProcessingInstruction element, @NotNull TextRange range, String newContent) throws IncorrectOperationException {
  return XmlAttributeValueManipulator.handleContentChange(element, range, newContent, XmlTokenType.XML_TAG_CHARACTERS);
}
项目:intellij-ce-playground    文件:FxmlReferencesContributor.java   
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
  final XmlAttributeValuePattern attributeValueInFxml = XmlPatterns.xmlAttributeValue().inVirtualFile(
    virtualFile().withExtension(JavaFxFileTypeFactory.FXML_EXTENSION));
  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_CONTROLLER))
                                        .and(attributeValueInFxml),
                                      CLASS_REFERENCE_PROVIDER);

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue()
                                        .withParent(XmlPatterns.xmlAttribute().withName("type")
                                                      .withParent(XmlPatterns.xmlTag().withName(FxmlConstants.FX_ROOT)))
                                        .and(attributeValueInFxml),
                                      new MyJavaClassReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlTag().inVirtualFile(virtualFile().withExtension(JavaFxFileTypeFactory.FXML_EXTENSION)),
                                      new MyJavaClassReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_ID))
                                        .and(attributeValueInFxml),
                                      new JavaFxFieldIdReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_ELEMENT_SOURCE)
                                                                                   .withParent(XmlPatterns.xmlTag()
                                                                                                 .withName(FxmlConstants.FX_INCLUDE)))
                                        .and(attributeValueInFxml),
                                      new JavaFxSourceReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_ELEMENT_SOURCE)
                                                                                   .withParent(XmlPatterns.xmlTag()
                                                                                                 .withName(FxmlConstants.FX_SCRIPT)))
                                        .and(attributeValueInFxml),
                                      new JavaFxSourceReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_ELEMENT_SOURCE)
                                                                                   .withParent(XmlPatterns.xmlTag()
                                                                                                 .withName(string().oneOf(FxmlConstants.FX_REFERENCE, FxmlConstants.FX_COPY))))
                                        .and(attributeValueInFxml),
                                      new JavaFxComponentIdReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_FACTORY))
                                        .and(attributeValueInFxml),
                                      new JavaFxFactoryReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withValue(string().startsWith("#"))
                                        .and(attributeValueInFxml),
                                      new JavaFxEventHandlerReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withValue(string().startsWith("@")).and(attributeValueInFxml),
                                      new JavaFxLocationReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withValue(string().startsWith("$")).and(attributeValueInFxml),
                                      new JavaFxComponentIdReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName("url")).and(attributeValueInFxml),
                                      new JavaFxLocationReferenceProvider(false, "png"));
  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.STYLESHEETS)).and(attributeValueInFxml),
                                      new JavaFxLocationReferenceProvider(true, "css"));

  registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlProcessingInstruction.class).inVirtualFile(virtualFile().withExtension(JavaFxFileTypeFactory.FXML_EXTENSION)),
                                      new ImportReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().and(attributeValueInFxml),
                                      new JavaFxColorReferenceProvider()); 

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue()
                                        .withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_VALUE)
                                                      .withParent(XmlPatterns.xmlTag().withParent(XmlPatterns.xmlTag().withName(FxmlConstants.STYLESHEETS))))
                                        .and(attributeValueInFxml),
                                      new JavaFxLocationReferenceProvider(true, "css"));
}
项目:tools-idea    文件:XmlProcessingInstructionManipulator.java   
@Override
public XmlProcessingInstruction handleContentChange(XmlProcessingInstruction element, TextRange range, String newContent) throws IncorrectOperationException {
  return XmlAttributeValueManipulator.handleContentChange(element, range, newContent, XmlTokenType.XML_TAG_CHARACTERS);
}
项目:tools-idea    文件:FxmlReferencesContributor.java   
@Override
public void registerReferenceProviders(PsiReferenceRegistrar registrar) {
  final XmlAttributeValuePattern attributeValueInFxml = XmlPatterns.xmlAttributeValue().inVirtualFile(
    virtualFile().withExtension(JavaFxFileTypeFactory.FXML_EXTENSION));
  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_CONTROLLER))
                                        .and(attributeValueInFxml),
                                      CLASS_REFERENCE_PROVIDER);

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue()
                                        .withParent(XmlPatterns.xmlAttribute().withName("type")
                                                      .withParent(XmlPatterns.xmlTag().withName(FxmlConstants.FX_ROOT)))
                                        .and(attributeValueInFxml),
                                      CLASS_REFERENCE_PROVIDER);

  registrar.registerReferenceProvider(XmlPatterns.xmlTag().inVirtualFile(virtualFile().withExtension(JavaFxFileTypeFactory.FXML_EXTENSION)),
                                      new MyJavaClassReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_ID))
                                        .and(attributeValueInFxml),
                                      new JavaFxFieldIdReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_ELEMENT_SOURCE)
                                                                                   .withParent(XmlPatterns.xmlTag()
                                                                                                 .withName(FxmlConstants.FX_INCLUDE)))
                                        .and(attributeValueInFxml),
                                      new JavaFxSourceReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_ELEMENT_SOURCE)
                                                                                   .withParent(XmlPatterns.xmlTag()
                                                                                                 .withName(FxmlConstants.FX_SCRIPT)))
                                        .and(attributeValueInFxml),
                                      new JavaFxSourceReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_ELEMENT_SOURCE)
                                                                                   .withParent(XmlPatterns.xmlTag()
                                                                                                 .withName(string().oneOf(FxmlConstants.FX_REFERENCE, FxmlConstants.FX_COPY))))
                                        .and(attributeValueInFxml),
                                      new JavaFxComponentIdReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_FACTORY))
                                        .and(attributeValueInFxml),
                                      new JavaFxFactoryReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withValue(string().startsWith("#"))
                                        .and(attributeValueInFxml),
                                      new JavaFxEventHandlerReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withValue(string().startsWith("@")).and(attributeValueInFxml),
                                      new JavaFxLocationReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withValue(string().startsWith("$")).and(attributeValueInFxml),
                                      new JavaFxComponentIdReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName("url")).and(attributeValueInFxml),
                                      new JavaFxLocationReferenceProvider(false, "png"));
  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.STYLESHEETS)).and(attributeValueInFxml),
                                      new JavaFxLocationReferenceProvider(true, "css"));

  registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlProcessingInstruction.class).inVirtualFile(virtualFile().withExtension(JavaFxFileTypeFactory.FXML_EXTENSION)),
                                      new ImportReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().and(attributeValueInFxml),
                                      new EnumeratedAttributeReferenceProvider()); 

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().and(attributeValueInFxml),
                                      new JavaFxColorReferenceProvider()); 

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue()
                                        .withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_VALUE)
                                                      .withParent(XmlPatterns.xmlTag().withParent(XmlPatterns.xmlTag().withName(FxmlConstants.STYLESHEETS))))
                                        .and(attributeValueInFxml),
                                      new JavaFxLocationReferenceProvider(true, "css"));
}
项目:consulo-javafx    文件:JavaFxImportsOptimizer.java   
@NotNull
@Override
public Runnable processFile(final PsiFile file) {
  VirtualFile vFile = file.getVirtualFile();
  if (vFile instanceof VirtualFileWindow) vFile = ((VirtualFileWindow)vFile).getDelegate();
  final Project project = file.getProject();
  if (vFile == null || !ProjectRootManager.getInstance(project).getFileIndex().isInSourceContent(vFile)) {
    return EmptyRunnable.INSTANCE;
  }
  final List<Pair<String, Boolean>> names = new ArrayList<Pair<String, Boolean>>();
  collectNamesToImport(names, (XmlFile)file);
  Collections.sort(names, new Comparator<Pair<String, Boolean>>() {
    @Override
    public int compare(Pair<String, Boolean> o1, Pair<String, Boolean> o2) {
      return StringUtil.compare(o1.first, o2.first, true);
    }
  });
  final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
  final List<Pair<String, Boolean>> sortedNames = ImportHelper.sortItemsAccordingToSettings(names, settings);
  final HashSet<String> onDemand = new HashSet<String>();
  ImportHelper.collectOnDemandImports(sortedNames, onDemand, settings);
  final Set<String> imported = new HashSet<String>();
  final List<String> imports = new ArrayList<String>();
  for (Pair<String, Boolean> pair : sortedNames) {
    final String qName = pair.first;
    final String packageName = StringUtil.getPackageName(qName);
    if (imported.contains(packageName) || imported.contains(qName)) {
      continue;
    }
    if (onDemand.contains(packageName)) {
      imported.add(packageName);
      imports.add("<?import " + packageName + ".*?>");
    } else {
      imported.add(qName);
      imports.add("<?import " + qName + "?>");
    }
  }
  final PsiFileFactory factory = PsiFileFactory.getInstance(file.getProject());

  final XmlFile dummyFile = (XmlFile)factory.createFileFromText("_Dummy_.fxml", XmlFileType.INSTANCE, StringUtil.join(imports, "\n"));
  final XmlDocument document = dummyFile.getDocument();
  final XmlProlog newImportList = document.getProlog();
  if (newImportList == null) return EmptyRunnable.getInstance();
  return new Runnable() {
    @Override
    public void run() {
      final XmlDocument xmlDocument = ((XmlFile)file).getDocument();
      final XmlProlog prolog = xmlDocument.getProlog();
      if (prolog != null) {
        final Collection<XmlProcessingInstruction> instructions = PsiTreeUtil.findChildrenOfType(prolog, XmlProcessingInstruction.class);
        for (final XmlProcessingInstruction instruction : instructions) {
          final ASTNode node = instruction.getNode();
          final ASTNode nameNode = node.findChildByType(XmlTokenType.XML_NAME);
          if (nameNode != null && nameNode.getText().equals("import")) {
            instruction.delete();
          }
        }
        prolog.add(newImportList);
      } else {
        document.addBefore(newImportList, document.getRootTag());
      }
    }
  };
}
项目:consulo-javafx    文件:JavaFxImportsOptimizer.java   
@Override
public void visitXmlProcessingInstruction(XmlProcessingInstruction processingInstruction) {}
项目:consulo-javafx    文件:FxmlReferencesContributor.java   
@Override
public void registerReferenceProviders(PsiReferenceRegistrar registrar) {
  final XmlAttributeValuePattern attributeValueInFxml = XmlPatterns.xmlAttributeValue().inVirtualFile(
    virtualFile().withExtension(JavaFxFileTypeFactory.FXML_EXTENSION));
  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_CONTROLLER))
                                        .and(attributeValueInFxml),
                                      CLASS_REFERENCE_PROVIDER);

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue()
                                        .withParent(XmlPatterns.xmlAttribute().withName("type")
                                                      .withParent(XmlPatterns.xmlTag().withName(FxmlConstants.FX_ROOT)))
                                        .and(attributeValueInFxml),
                                      CLASS_REFERENCE_PROVIDER);

  registrar.registerReferenceProvider(XmlPatterns.xmlTag().inVirtualFile(virtualFile().withExtension(JavaFxFileTypeFactory.FXML_EXTENSION)),
                                      new MyJavaClassReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_ID))
                                        .and(attributeValueInFxml),
                                      new JavaFxFieldIdReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_ELEMENT_SOURCE)
                                                                                   .withParent(XmlPatterns.xmlTag()
                                                                                                 .withName(FxmlConstants.FX_INCLUDE)))
                                        .and(attributeValueInFxml),
                                      new JavaFxSourceReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_ELEMENT_SOURCE)
                                                                                   .withParent(XmlPatterns.xmlTag()
                                                                                                 .withName(FxmlConstants.FX_SCRIPT)))
                                        .and(attributeValueInFxml),
                                      new JavaFxSourceReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_ELEMENT_SOURCE)
                                                                                   .withParent(XmlPatterns.xmlTag()
                                                                                                 .withName(string().oneOf(FxmlConstants.FX_REFERENCE, FxmlConstants.FX_COPY))))
                                        .and(attributeValueInFxml),
                                      new JavaFxComponentIdReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_FACTORY))
                                        .and(attributeValueInFxml),
                                      new JavaFxFactoryReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withValue(string().startsWith("#"))
                                        .and(attributeValueInFxml),
                                      new JavaFxEventHandlerReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withValue(string().startsWith("@")).and(attributeValueInFxml),
                                      new JavaFxLocationReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withValue(string().startsWith("$")).and(attributeValueInFxml),
                                      new JavaFxComponentIdReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName("url")).and(attributeValueInFxml),
                                      new JavaFxLocationReferenceProvider(false, "png"));
  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.STYLESHEETS)).and(attributeValueInFxml),
                                      new JavaFxLocationReferenceProvider(true, "css"));

  registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlProcessingInstruction.class).inVirtualFile(virtualFile().withExtension(JavaFxFileTypeFactory.FXML_EXTENSION)),
                                      new ImportReferenceProvider());

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().and(attributeValueInFxml),
                                      new JavaFxColorReferenceProvider()); 

  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue()
                                        .withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_VALUE)
                                                      .withParent(XmlPatterns.xmlTag().withParent(XmlPatterns.xmlTag().withName(FxmlConstants.STYLESHEETS))))
                                        .and(attributeValueInFxml),
                                      new JavaFxLocationReferenceProvider(true, "css"));
}
项目:consulo-javafx    文件:JavaFxPsiUtil.java   
public static XmlProcessingInstruction createSingleImportInstruction(String qualifiedName, Project project) {
  final String importText = "<?import " + qualifiedName + "?>";
  final PsiElement child =
    PsiFileFactory.getInstance(project).createFileFromText("a.fxml", XMLLanguage.INSTANCE, importText).getFirstChild();
  return PsiTreeUtil.findChildOfType(child, XmlProcessingInstruction.class);
}
项目:consulo-xml    文件:XmlReferenceContributor.java   
@Override
public void registerReferenceProviders(@NotNull final PsiReferenceRegistrar registrar)
{

    final IdReferenceProvider idReferenceProvider = new IdReferenceProvider();

    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, idReferenceProvider.getIdForAttributeNames(), idReferenceProvider.getIdForFilter(), true, idReferenceProvider,
            PsiReferenceRegistrar.DEFAULT_PRIORITY);

    final DtdReferencesProvider dtdReferencesProvider = new DtdReferencesProvider();
    //registerReferenceProvider(null, XmlEntityDecl.class,dtdReferencesProvider);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlEntityRef.class), dtdReferencesProvider);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlDoctype.class), dtdReferencesProvider);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlElementDecl.class), dtdReferencesProvider);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlAttlistDecl.class), dtdReferencesProvider);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlElementContentSpec.class), dtdReferencesProvider);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlToken.class), dtdReferencesProvider);
    registrar.registerReferenceProvider(xmlAttributeValue(), new ArbitraryPlaceUrlReferenceProvider(), PsiReferenceRegistrar.LOWER_PRIORITY);


    URIReferenceProvider uriProvider = new URIReferenceProvider();
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, null, dtdReferencesProvider.getSystemReferenceFilter(), uriProvider);

    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[]{"href"}, new ScopeFilter(new ParentElementFilter(new AndFilter(new AndFilter(XmlTagFilter.INSTANCE, new
            XmlTextFilter("include")), new NamespaceFilter(XmlUtil.XINCLUDE_URI)), 2)), true, new XmlBaseReferenceProvider(true));

    registrar.registerReferenceProvider(xmlAttributeValue().withLocalName("base").withNamespace(XmlUtil.XML_NAMESPACE_URI), new XmlBaseReferenceProvider(false));

    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[]{MicrodataUtil.ITEM_TYPE}, null, new MicrodataReferenceProvider());

    final SchemaReferencesProvider schemaReferencesProvider = new SchemaReferencesProvider();

    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, schemaReferencesProvider.getCandidateAttributeNamesForSchemaReferences(), new ScopeFilter(new ParentElementFilter(new
            NamespaceFilter(XmlUtil.SCHEMA_URIS), 2)), schemaReferencesProvider);

    registrar.registerReferenceProvider(xmlAttributeValue(xmlAttribute().withNamespace(XmlUtil.XML_SCHEMA_INSTANCE_URI)).
            withLocalName("type"), schemaReferencesProvider);

    registrar.registerReferenceProvider(xmlAttributeValue(xmlAttribute().withNamespace(XmlUtil.XML_SCHEMA_INSTANCE_URI)).
            withLocalName("noNamespaceSchemaLocation", "schemaLocation"), uriProvider);

    registrar.registerReferenceProvider(xmlAttributeValue().withLocalName("schemaLocation", "namespace").
            withSuperParent(2, xmlTag().withNamespace(XmlUtil.SCHEMA_URIS).withLocalName("import", "include", "redefine")), uriProvider);

    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, null, URIReferenceProvider.ELEMENT_FILTER, true, uriProvider);

    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[]{"encoding"}, new ScopeFilter(new ParentElementFilter(new ClassFilter(XmlProcessingInstruction.class))), true, new
            XmlEncodingReferenceProvider());

    registrar.registerReferenceProvider(xmlAttributeValue(), new XmlPrefixReferenceProvider());
    registrar.registerReferenceProvider(xmlAttributeValue(), new XmlEnumeratedValueReferenceProvider(), PsiReferenceRegistrar.LOWER_PRIORITY);
    registrar.registerReferenceProvider(xmlTag(), XmlEnumeratedValueReferenceProvider.forTags(), PsiReferenceRegistrar.LOWER_PRIORITY);

    registrar.registerReferenceProvider(xmlAttributeValue().withLocalName("source").withSuperParent(2, xmlTag().withLocalName("documentation").withNamespace(XmlUtil.SCHEMA_URIS)), new
            PsiReferenceProvider()
    {
        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context)
        {
            return new PsiReference[]{new WebReference(element)};
        }
    });
}
项目:consulo-xml    文件:XmlProcessingInstructionManipulator.java   
@Override
public XmlProcessingInstruction handleContentChange(XmlProcessingInstruction element, TextRange range, String newContent) throws IncorrectOperationException {
  return XmlAttributeValueManipulator.handleContentChange(element, range, newContent, XmlTokenType.XML_TAG_CHARACTERS);
}