本文整理汇总了Java中com.intellij.psi.xml.XmlProlog类的典型用法代码示例。如果您正苦于以下问题:Java XmlProlog类的具体用法?Java XmlProlog怎么用?Java XmlProlog使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XmlProlog类属于com.intellij.psi.xml包,在下文中一共展示了XmlProlog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerPageLanguage
import com.intellij.psi.xml.XmlProlog; //导入依赖的package包/类
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();
}
示例2: registerPageLanguage
import com.intellij.psi.xml.XmlProlog; //导入依赖的package包/类
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();
}
示例3: registerPageLanguage
import com.intellij.psi.xml.XmlProlog; //导入依赖的package包/类
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();
}
示例4: parseInstructions
import com.intellij.psi.xml.XmlProlog; //导入依赖的package包/类
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;
}
示例5: insertImportWhenNeeded
import com.intellij.psi.xml.XmlProlog; //导入依赖的package包/类
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());
}
}
}
示例6: is23
import com.intellij.psi.xml.XmlProlog; //导入依赖的package包/类
private static boolean is23(final ConvertContext context) {
final DomElement element = DomUtil.getFileElement(context.getInvocationElement()).getRootElement();
final XmlTag tag = element.getXmlTag();
if (tag != null && "web-app".equals(element.getXmlElementName()) && tag.getAttribute("version") == null) {
XmlDocument document = (XmlDocument)tag.getParent();
final XmlProlog prolog = document.getProlog();
if (prolog != null) {
final XmlDoctype doctype = prolog.getDoctype();
if (doctype != null) {
final String uri = doctype.getDtdUri();
if (uri != null && uri.contains("2_3")) return true;
}
}
return false;
}
return true;
}
示例7: invoke
import com.intellij.psi.xml.XmlProlog; //导入依赖的package包/类
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
final XmlTag anchor = getAnchor(element);
if (anchor == null) return;
PsiElement prevSibling = anchor.getPrevSibling();
while (prevSibling instanceof PsiWhiteSpace || prevSibling instanceof XmlText) {
prevSibling = prevSibling.getPrevSibling();
}
if (prevSibling instanceof XmlProlog) {
prevSibling = prevSibling.getLastChild();
if (prevSibling != null && !(prevSibling instanceof XmlComment)) {
prevSibling = PsiTreeUtil.getPrevSiblingOfType(prevSibling, XmlComment.class);
}
}
if (prevSibling instanceof XmlComment) {
final XmlComment comment = (XmlComment)prevSibling;
final String text = XmlUtil.getCommentText(comment);
if (text != null && InspectionUtil.SUPPRESSION_PATTERN.matcher(text).matches()) {
final String s = text.trim() + ", " + myToolId;
final XmlComment newComment = createComment(project, s);
CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(comment.replace(newComment));
} else {
addNoinspectionComment(project, anchor);
}
} else {
addNoinspectionComment(project, anchor);
}
}
示例8: addNoinspectionComment
import com.intellij.psi.xml.XmlProlog; //导入依赖的package包/类
private void addNoinspectionComment(Project project, XmlTag anchor) throws IncorrectOperationException {
final XmlComment newComment = createComment(project, "noinspection " + myToolId);
PsiElement parent = anchor.getParentTag();
if (parent == null) {
parent = PsiTreeUtil.getPrevSiblingOfType(anchor, XmlProlog.class);
if (parent != null) {
CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(parent.add(newComment));
}
} else {
CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(parent.addBefore(newComment, anchor));
}
}
示例9: getHandler
import com.intellij.psi.xml.XmlProlog; //导入依赖的package包/类
@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;
}
};
}
示例10: invoke
import com.intellij.psi.xml.XmlProlog; //导入依赖的package包/类
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
final XmlTag anchor = getAnchor(element);
if (anchor == null) return;
PsiElement prevSibling = anchor.getPrevSibling();
while (prevSibling instanceof PsiWhiteSpace || prevSibling instanceof XmlText) {
prevSibling = prevSibling.getPrevSibling();
}
if (prevSibling instanceof XmlProlog) {
prevSibling = prevSibling.getLastChild();
if (prevSibling != null && !(prevSibling instanceof XmlComment)) {
prevSibling = PsiTreeUtil.getPrevSiblingOfType(prevSibling, XmlComment.class);
}
}
if (prevSibling instanceof XmlComment) {
final XmlComment comment = (XmlComment)prevSibling;
final String text = XmlUtil.getCommentText(comment);
if (text != null && InspectionUtil.SUPPRESSION_PATTERN.matcher(text).matches()) {
final String s = text.trim() + ", " + myToolId;
final XmlComment newComment = createComment(project, s);
CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(comment.replace(newComment));
} else {
addNoinspectionComment(project, anchor);
}
} else {
addNoinspectionComment(project, anchor);
}
}
示例11: addNoinspectionComment
import com.intellij.psi.xml.XmlProlog; //导入依赖的package包/类
private void addNoinspectionComment(Project project, XmlTag anchor) throws IncorrectOperationException {
final XmlComment newComment = createComment(project, "noinspection " + myToolId);
PsiElement parent = anchor.getParentTag();
if (parent == null) {
parent = PsiTreeUtil.getPrevSiblingOfType(anchor, XmlProlog.class);
if (parent != null) {
CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(parent.add(newComment));
}
} else {
CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(parent.addBefore(newComment, anchor));
}
}
示例12: hasDtdDeclaration
import com.intellij.psi.xml.XmlProlog; //导入依赖的package包/类
private boolean hasDtdDeclaration() {
XmlDocument document = myFile.getDocument();
if (document == null) return false;
XmlProlog prolog = document.getProlog();
if (prolog == null) return false;
XmlDoctype doctype = prolog.getDoctype();
if (doctype == null) return false;
return true;
}
示例13: hasNonHtml5Doctype
import com.intellij.psi.xml.XmlProlog; //导入依赖的package包/类
public static boolean hasNonHtml5Doctype(XmlElement context)
{
XmlDocument doc = PsiTreeUtil.getParentOfType(context, XmlDocument.class);
if(doc == null)
{
return false;
}
XmlProlog prolog = doc.getProlog();
XmlDoctype doctype = prolog != null ? prolog.getDoctype() : null;
return doctype != null && !isHtml5Doctype(doctype);
}
示例14: getRootElementsDescriptors
import com.intellij.psi.xml.XmlProlog; //导入依赖的package包/类
@Override
@NotNull
public XmlElementDescriptor[] getRootElementsDescriptors(@Nullable final XmlDocument document)
{
// Suggest more appropriate variant if DOCTYPE <element_name> exists
final XmlProlog prolog = document != null ? document.getProlog() : null;
if(prolog != null)
{
final XmlDoctype doctype = prolog.getDoctype();
if(doctype != null)
{
final XmlElement element = doctype.getNameElement();
if(element != null)
{
final XmlElementDescriptor descriptor = getElementDescriptor(element.getText());
if(descriptor != null)
{
return new XmlElementDescriptor[]{descriptor};
}
}
}
}
return getElements();
}
示例15: getChildrenBase
import com.intellij.psi.xml.XmlProlog; //导入依赖的package包/类
@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
final XmlDocument document = getElement().getDocument();
List<XmlTag> rootTags = new ArrayList<XmlTag>();
if (document != null) {
for (PsiElement element : document.getChildren())
if (element instanceof XmlTag) rootTags.add((XmlTag)element);
}
Collection<StructureViewTreeElement> structureViewTreeElements =
AbstractXmlTagTreeElement.getStructureViewTreeElements(rootTags.toArray(new XmlTag[rootTags.size()]));
Collection<StructureViewTreeElement> dtdStructureViewTreeElements = null;
final XmlProlog prolog = document != null ? document.getProlog():null;
if (prolog != null) {
final XmlDoctype doctype = prolog.getDoctype();
if (doctype != null) {
final XmlMarkupDecl xmlMarkupDecl = doctype.getMarkupDecl();
if (xmlMarkupDecl != null) {
dtdStructureViewTreeElements = DtdFileTreeElement.collectElements(xmlMarkupDecl);
}
}
}
if (dtdStructureViewTreeElements != null) {
final ArrayList<StructureViewTreeElement> result = new ArrayList<StructureViewTreeElement>(
dtdStructureViewTreeElements.size() + structureViewTreeElements.size()
);
result.addAll(dtdStructureViewTreeElements);
result.addAll(structureViewTreeElements);
structureViewTreeElements = result;
}
return structureViewTreeElements;
}