Java 类com.intellij.psi.impl.source.html.HtmlFileImpl 实例源码
项目:GravSupport
文件:ConvertTwigResource.java
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
if (!element.isWritable()) return false;
boolean isTwigFile = GravFileTemplateUtil.isTwigTemplateFile(element.getContainingFile()) || element.getContainingFile() instanceof HtmlFileImpl;
boolean isXmlAttribute = false;
if (!isTwigFile) return false;
if (element.getParent() instanceof XmlAttributeValueImpl) {
XmlAttributeValueImpl parent0 = ((XmlAttributeValueImpl) element.getParent());
boolean hasTwigElement = PsiTreeUtil.findChildOfType(parent0, OuterLanguageElement.class) != null;
if (!hasTwigElement && parent0.getParent() instanceof XmlAttributeImpl) {
XmlAttributeImpl parent1 = (XmlAttributeImpl) parent0.getParent();
if (parent1.getName().equalsIgnoreCase("href") || parent1.getName().equalsIgnoreCase("src"))
isXmlAttribute = true;
}
}
return isXmlAttribute;
}
项目:hybris-integration-intellij-idea-plugin
文件:BpDiagramElementManagerIml.java
@Nullable
@Override
public BpGraphNode findInDataContext(final DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final CommonIdeaService commonIdeaService = ServiceManager.getService(CommonIdeaService.class);
if (!commonIdeaService.isHybrisProject(project)) {
return null;
}
final VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
if (null == virtualFile) {
return null;
}
if (!virtualFile.getName().endsWith("process.xml")) {
return null;
}
final PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(dataContext);
if (!(psiFile instanceof XmlFile) ||
psiFile instanceof HtmlFileImpl) { // but psiFile must not be html.
return null;
}
final BpGraphService bpGraphService = ServiceManager.getService(BpGraphService.class);
try {
return bpGraphService.buildGraphFromXmlFile(virtualFile);
} catch (UnmarshalException e) {
return null;
}
}
项目:idea-php-symfony2-plugin
文件:ProfilerUtil.java
/**
* "_controller" and "_route"
* "/_profiler/242e61?panel=request"
*
* <tr>
* <th>_route</th>
* <td>foo_route</td>
* </tr>
*/
@NotNull
public static Map<String, String> getRequestAttributes(@NotNull Project project, @NotNull String html) {
HtmlFileImpl htmlFile = (HtmlFileImpl) PsiFileFactory.getInstance(project).createFileFromText(HTMLLanguage.INSTANCE, html);
String[] keys = new String[] {"_controller", "_route"};
Map<String, String> map = new HashMap<>();
PsiTreeUtil.processElements(htmlFile, psiElement -> {
if(!(psiElement instanceof XmlTag) || !"th".equals(((XmlTag) psiElement).getName())) {
return true;
}
XmlTagValue keyTag = ((XmlTag) psiElement).getValue();
String key = StringUtils.trim(keyTag.getText());
if(!ArrayUtils.contains(keys, key)) {
return true;
}
XmlTag tdTag = PsiTreeUtil.getNextSiblingOfType(psiElement, XmlTag.class);
if(tdTag == null || !"td".equals(tdTag.getName())) {
return true;
}
XmlTagValue valueTag = tdTag.getValue();
String value = valueTag.getText();
if(StringUtils.isBlank(value)) {
return true;
}
// Symfony 3.2 profiler debug? strip html
map.put(key, stripHtmlTags(value));
// exit if all item found
return map.size() != keys.length;
});
return map;
}
项目:idea-php-symfony2-plugin
文件:TwigTranslationGeneratorAction.java
@Override
protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
return Symfony2ProjectComponent.isEnabled(project) && (
file instanceof TwigFile
|| (file instanceof HtmlFileImpl && file.getName().toLowerCase().endsWith(".twig"))
|| getInjectedTwigElement(file, editor) != null
);
}
项目:intellij-ce-playground
文件:XmlCodeFoldingBuilder.java
private static boolean isAttributeShouldBeFolded(XmlAttribute child) {
return child.getContainingFile() instanceof HtmlFileImpl &&
HtmlUtil.STYLE_ATTRIBUTE_NAME.equalsIgnoreCase(child.getName());
}
项目:intellij-ce-playground
文件:HTMLParserDefinition.java
@Override
public PsiFile createFile(FileViewProvider viewProvider) {
return new HtmlFileImpl(viewProvider);
}
项目:tools-idea
文件:XmlCodeFoldingBuilder.java
private static boolean isAttributeShouldBeFolded(XmlAttribute child) {
return child.getContainingFile() instanceof HtmlFileImpl &&
STYLE_ATTRIBUTE.equalsIgnoreCase(child.getName());
}
项目:tools-idea
文件:HTMLParserDefinition.java
public PsiFile createFile(FileViewProvider viewProvider) {
return new HtmlFileImpl(viewProvider);
}
项目:idea-php-symfony2-plugin
文件:ProfilerUtil.java
/**
* ["foo/foo.html.twig": 1]
*
* <tr>
* <td>@Twig/Exception/traces_text.html.twig</td>
* <td class="font-normal">1</td>
* </tr>
*/
public static Map<String, Integer> getRenderedElementTwigTemplates(@NotNull Project project, @NotNull String html) {
HtmlFileImpl htmlFile = (HtmlFileImpl) PsiFileFactory.getInstance(project).createFileFromText(HTMLLanguage.INSTANCE, html);
final XmlTag[] xmlTag = new XmlTag[1];
PsiTreeUtil.processElements(htmlFile, psiElement -> {
if(!(psiElement instanceof XmlTag) || !"h2".equals(((XmlTag) psiElement).getName())) {
return true;
}
XmlTagValue keyTag = ((XmlTag) psiElement).getValue();
String contents = StringUtils.trim(keyTag.getText());
if(!"Rendered Templates".equalsIgnoreCase(contents)) {
return true;
}
xmlTag[0] = (XmlTag) psiElement;
return true;
});
if(xmlTag[0] == null) {
return Collections.emptyMap();
}
XmlTag tableTag = PsiTreeUtil.getNextSiblingOfType(xmlTag[0], XmlTag.class);
if(tableTag == null || !"table".equals(tableTag.getName())) {
return Collections.emptyMap();
}
XmlTag tbody = tableTag.findFirstSubTag("tbody");
if(tbody == null) {
return Collections.emptyMap();
}
Map<String, Integer> templates = new HashMap<>();
for (XmlTag tag : PsiTreeUtil.getChildrenOfTypeAsList(tbody, XmlTag.class)) {
if(!"tr".equals(tag.getName())) {
continue;
}
XmlTag[] tds = tag.findSubTags("td");
if(tds.length < 2) {
continue;
}
String template = stripHtmlTags(StringUtils.trim(tds[0].getValue().getText()));
if(StringUtils.isBlank(template)) {
continue;
}
Integer count;
try {
count = Integer.valueOf(stripHtmlTags(StringUtils.trim(tds[1].getValue().getText())));
} catch (NumberFormatException e) {
count = 0;
}
templates.put(template, count);
}
return templates;
}
项目:consulo-xml
文件:HTMLParserDefinition.java
@Override
public PsiFile createFile(FileViewProvider viewProvider) {
return new HtmlFileImpl(viewProvider);
}
项目:consulo-xml
文件:XmlCodeFoldingBuilder.java
private static boolean isAttributeShouldBeFolded(XmlAttribute child) {
return child.getContainingFile() instanceof HtmlFileImpl &&
STYLE_ATTRIBUTE.equalsIgnoreCase(child.getName());
}