Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
301,300
void (Runnable runnable) { myOkAction = runnable; }
setOkAction
301,301
void () { super.doOKAction(); if (myOkAction != null) { myOkAction.run(); } }
doOKAction
301,302
String () { return "webservices.GenerateInstanceDocumentFromSchema"; }
getHelpId
301,303
void (@NotNull AnActionEvent e) { final VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE); final boolean enabled = isAcceptableFile(file); e.getPresentation().setEnabled(enabled); if (ActionPlaces.isPopupPlace(e.getPlace())) { e.getPresentation().setVisible(enabled); } }
update
301,304
ActionUpdateThread () { return ActionUpdateThread.BGT; }
getActionUpdateThread
301,305
void (@NotNull AnActionEvent e) { final Project project = e.getProject(); final VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE); final GenerateInstanceDocumentFromSchemaDialog dialog = new GenerateInstanceDocumentFromSchemaDialog(project, file); dialog.setOkAction(() -> doAction(project, dialog)); dialog.show(); }
actionPerformed
301,306
void (final Project project, final GenerateInstanceDocumentFromSchemaDialog dialog) { FileDocumentManager.getInstance().saveAllDocuments(); @NonNls List<String> parameters = new LinkedList<>(); final String url = dialog.getUrl().getText(); final VirtualFile relativeFile = VfsUtilCore.findRelativeFile(ExternalResourceManager.getInstance().getResourceLocation(url), null); if (relativeFile == null) { Messages.showErrorDialog(project, XmlBundle.message("file.doesnt.exist", url), XmlBundle.message("error")); return; } final PsiFile file = PsiManager.getInstance(project).findFile(relativeFile); if (!(file instanceof XmlFile)) { Messages.showErrorDialog(project, " (" + file.getFileType().getDescription() + ")", XmlBundle.message("error")); return; } VirtualFile relativeFileDir = relativeFile.getParent(); if (relativeFileDir == null) { Messages.showErrorDialog(project, XmlBundle.message("file.doesnt.exist", url), XmlBundle.message("error")); return; } if (!dialog.enableRestrictionCheck()) { parameters.add("-nopvr"); } if (!dialog.enableUniquenessCheck()) { parameters.add("-noupa"); } parameters.add("-dl"); String pathToUse; try { final File tempDir = FileUtil.createTempFile("xsd2inst", ""); tempDir.delete(); tempDir.mkdir(); pathToUse = tempDir.getPath() + File.separatorChar + Xsd2InstanceUtils.processAndSaveAllSchemas( (XmlFile)file, new HashMap<>(), new Xsd2InstanceUtils.SchemaReferenceProcessor() { @Override public void processSchema(String schemaFileName, byte[] schemaContent) { try { final String fullFileName = tempDir.getPath() + File.separatorChar + schemaFileName; FileUtils.saveStreamContentAsFile( fullFileName, new ByteArrayInputStream(schemaContent) ); } catch (IOException e) { throw new RuntimeException(e); } } } ); } catch (IOException e) { return; } parameters.add(pathToUse); parameters.add("-name"); parameters.add(dialog.getElementName()); String xml; try { xml = Xsd2InstanceUtils.generate(ArrayUtilRt.toStringArray(parameters)); } catch (Throwable e) { Messages.showErrorDialog(project, ExceptionUtil.getMessage(e), XmlBundle.message("error")); return; } String xmlFileName = relativeFileDir.getPath() + File.separatorChar + dialog.getOutputFileName(); try { // the generated XML doesn't have any XML declaration -> utf-8 final File xmlFile = new File(xmlFileName); FileUtil.writeToFile(xmlFile, xml); VirtualFile virtualFile = WriteAction.compute(() -> LocalFileSystem.getInstance().refreshAndFindFileByIoFile(xmlFile)); FileEditorManager.getInstance(project).openFile(virtualFile, true); } catch (IOException e) { Messages.showErrorDialog(project, XmlBundle.message("could.not.save.generated.xml.document.0", StringUtil.getMessage(e)), XmlBundle.message("error")); } }
doAction
301,307
void (String schemaFileName, byte[] schemaContent) { try { final String fullFileName = tempDir.getPath() + File.separatorChar + schemaFileName; FileUtils.saveStreamContentAsFile( fullFileName, new ByteArrayInputStream(schemaContent) ); } catch (IOException e) { throw new RuntimeException(e); } }
processSchema
301,308
boolean (VirtualFile virtualFile) { return virtualFile != null && "xsd".equalsIgnoreCase(virtualFile.getExtension()); }
isAcceptableFileForGenerateSchemaFromInstanceDocument
301,309
boolean (VirtualFile file) { return isAcceptableFileForGenerateSchemaFromInstanceDocument(file); }
isAcceptableFile
301,310
void (final Project myProject, final TextFieldWithBrowseButton wsdlUrl, final String[] _extensions, final @DialogTitle String selectFileDialogTitle, final boolean multipleFileSelection) { wsdlUrl.getButton().setToolTipText(XmlBundle.message("browse.button.tooltip")); wsdlUrl.getButton().addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { final FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, multipleFileSelection) { private final List<String> extensions = Arrays.asList(_extensions); @Override public boolean isFileSelectable(@Nullable VirtualFile virtualFile) { if (virtualFile == null) return false; return extensions.contains(virtualFile.getExtension()); } @Override public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || isFileSelectable(file)); } }; fileChooserDescriptor.setTitle(selectFileDialogTitle); VirtualFile initialFile = ProjectUtil.guessProjectDir(myProject); String selectedItem = wsdlUrl.getTextField().getText(); if (selectedItem != null && selectedItem.startsWith(LocalFileSystem.PROTOCOL_PREFIX)) { VirtualFile fileByPath = VfsUtilCore .findRelativeFile(ExternalResourceManager.getInstance().getResourceLocation(VfsUtilCore.fixURLforIDEA(selectedItem)), null); if (fileByPath != null) initialFile = fileByPath; } final VirtualFile[] virtualFiles = FileChooser.chooseFiles(fileChooserDescriptor, myProject, initialFile); if (virtualFiles.length == 1) { String url = VfsUtilCore.fixIDEAUrl(virtualFiles[0].getUrl()); wsdlUrl.setText(url); } } } ); }
configureBrowseButton
301,311
void (ActionEvent actionEvent) { final FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, multipleFileSelection) { private final List<String> extensions = Arrays.asList(_extensions); @Override public boolean isFileSelectable(@Nullable VirtualFile virtualFile) { if (virtualFile == null) return false; return extensions.contains(virtualFile.getExtension()); } @Override public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || isFileSelectable(file)); } }; fileChooserDescriptor.setTitle(selectFileDialogTitle); VirtualFile initialFile = ProjectUtil.guessProjectDir(myProject); String selectedItem = wsdlUrl.getTextField().getText(); if (selectedItem != null && selectedItem.startsWith(LocalFileSystem.PROTOCOL_PREFIX)) { VirtualFile fileByPath = VfsUtilCore .findRelativeFile(ExternalResourceManager.getInstance().getResourceLocation(VfsUtilCore.fixURLforIDEA(selectedItem)), null); if (fileByPath != null) initialFile = fileByPath; } final VirtualFile[] virtualFiles = FileChooser.chooseFiles(fileChooserDescriptor, myProject, initialFile); if (virtualFiles.length == 1) { String url = VfsUtilCore.fixIDEAUrl(virtualFiles[0].getUrl()); wsdlUrl.setText(url); } }
actionPerformed
301,312
boolean (@Nullable VirtualFile virtualFile) { if (virtualFile == null) return false; return extensions.contains(virtualFile.getExtension()); }
isFileSelectable
301,313
boolean (VirtualFile file, boolean showHiddenFiles) { return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || isFileSelectable(file)); }
isFileVisible
301,314
MyHost (@NotNull PsiFile file) { if (!(file instanceof XmlFile)) return null; final XmlDocument document = ((XmlFile)file).getDocument(); if (document == null) return null; XmlTag rootTag = document.getRootTag(); XmlNSDescriptor nsDescriptor = rootTag == null ? null : rootTag.getNSDescriptor(rootTag.getNamespace(), false); if (nsDescriptor instanceof Validator) { MyHost host = new MyHost(); ((Validator<XmlDocument>)nsDescriptor).validate(document, host); return host; } return null; }
collectInformation
301,315
MyHost (MyHost collectedInfo) { return collectedInfo; }
doAnnotate
301,316
void (@NotNull PsiFile file, MyHost annotationResult, @NotNull AnnotationHolder holder) { annotationResult.apply(holder); }
apply
301,317
void (PsiElement context, @InspectionMessage String message, @NotNull ErrorType type) { messages.add(Trinity.create(context, message, type)); }
addMessage
301,318
void (final PsiElement context, final @InspectionMessage String message, @NotNull final Validator.ValidationHost.ErrorType type, AnnotationHolder myHolder, final IntentionAction @NotNull ... fixes) { if (message != null && !message.isEmpty()) { HighlightSeverity severity = type == Validator.ValidationHost.ErrorType.ERROR ? HighlightSeverity.ERROR : HighlightSeverity.WARNING; if (context instanceof XmlTag) { addMessagesForTreeChild(XmlTagUtil.getStartTagNameElement((XmlTag)context), severity, message, myHolder, fixes); addMessagesForTreeChild(XmlTagUtil.getEndTagNameElement((XmlTag)context), severity, message, myHolder, fixes); } else { addMessagesForTreeChild(context, severity, message, myHolder,fixes); } } }
addMessageWithFixes
301,319
void (final PsiElement token, final HighlightSeverity type, final @InspectionMessage String message, AnnotationHolder myHolder, IntentionAction @NotNull ... actions) { if (token != null) { AnnotationBuilder builder = myHolder.newAnnotation(type, message).range(token); for (IntentionAction action : actions) { builder = builder.withFix(action); } builder.create(); } }
addMessagesForTreeChild
301,320
LocalQuickFixAndIntentionActionOnPsiElement (@NotNull XmlTag tag, @NotNull String attrName, String @NotNull ... values) { return QuickFixes.EMPTY_FIX; }
insertRequiredAttributeFix
301,321
LocalQuickFix (@NotNull PsiElement element, @NotNull String namespacePrefix, @Nullable XmlToken token) { return QuickFixes.EMPTY_ACTION; }
createNSDeclarationIntentionFix
301,322
LocalQuickFixAndIntentionActionOnPsiElement (@NotNull XmlAttribute attribute) { return QuickFixes.EMPTY_FIX; }
addAttributeValueFix
301,323
String () { return XmlAnalysisBundle.message("xml.quickfix.remove.extra.closing.tag"); }
getFamilyName
301,324
String () { return getName(); }
getText
301,325
boolean (@NotNull final Project project, final Editor editor, final PsiFile file) { PsiElement psiElement = file.findElementAt(editor.getCaretModel().getOffset()); return psiElement instanceof XmlToken && (psiElement.getParent() instanceof XmlTag || psiElement.getParent() instanceof PsiErrorElement); }
isAvailable
301,326
boolean () { return true; }
startInWriteAction
301,327
Document (@NotNull PsiElement tagElement) { return tagElement.getContainingFile().getViewProvider().getDocument(); }
getDocument
301,328
void (@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { final PsiElement element = descriptor.getPsiElement(); if (!(element instanceof XmlToken)) return; doFix(element.getParent()); }
applyFix
301,329
String () { return "HtmlExtraClosingTag"; }
getShortName
301,330
void (@NotNull final XmlTag tag, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) { final TextRange range = XmlTagUtil.getEndTagRange(tag); if (range != null && tag instanceof HtmlTag && HtmlUtil.isSingleHtmlTag(tag, true) && tag.getLanguage().isKindOf(HTMLLanguage.INSTANCE)) { holder.registerProblem(tag, XmlAnalysisBundle.message("html.inspections.extra.closing.tag.for.empty.element"), ProblemHighlightType.LIKE_UNUSED_SYMBOL, range.shiftRight(-tag.getTextRange().getStartOffset()), new RemoveExtraClosingTagIntentionAction()); } }
checkTag
301,331
boolean () { return true; }
isEnabledByDefault
301,332
void (@NotNull final XmlTag tag, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) { // should be overridden }
checkTag
301,333
void (@NotNull final XmlAttribute attribute, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) { // should be overridden }
checkAttribute
301,334
void (@NotNull final XmlAttributeValue attributeValue, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) { // should be overridden }
checkAttributeValue
301,335
void (@NotNull final XmlText text, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) { // should be overridden }
checkText
301,336
PsiElementVisitor (@NotNull final ProblemsHolder holder, final boolean isOnTheFly) { return new XmlElementVisitor() { @Override public void visitXmlToken(final @NotNull XmlToken token) { IElementType tokenType = token.getTokenType(); if (tokenType == XmlTokenType.XML_NAME || tokenType == XmlTokenType.XML_TAG_NAME) { PsiElement element = token.getPrevSibling(); while (element instanceof PsiWhiteSpace) element = element.getPrevSibling(); if (element instanceof XmlToken && ((XmlToken)element).getTokenType() == XmlTokenType.XML_START_TAG_START) { PsiElement parent = element.getParent(); if (parent instanceof XmlTag tag && !(token.getNextSibling() instanceof OuterLanguageElement)) { checkTag(tag, holder, isOnTheFly); } } } } @Override public void visitXmlText(@NotNull XmlText text) { checkText(text, holder, isOnTheFly); } @Override public void visitXmlAttribute(final @NotNull XmlAttribute attribute) { checkAttribute(attribute, holder, isOnTheFly); } @Override public void visitXmlAttributeValue(@NotNull XmlAttributeValue value) { checkAttributeValue(value, holder, isOnTheFly); } }; }
buildVisitor
301,337
void (final @NotNull XmlToken token) { IElementType tokenType = token.getTokenType(); if (tokenType == XmlTokenType.XML_NAME || tokenType == XmlTokenType.XML_TAG_NAME) { PsiElement element = token.getPrevSibling(); while (element instanceof PsiWhiteSpace) element = element.getPrevSibling(); if (element instanceof XmlToken && ((XmlToken)element).getTokenType() == XmlTokenType.XML_START_TAG_START) { PsiElement parent = element.getParent(); if (parent instanceof XmlTag tag && !(token.getNextSibling() instanceof OuterLanguageElement)) { checkTag(tag, holder, isOnTheFly); } } } }
visitXmlToken
301,338
void (@NotNull XmlText text) { checkText(text, holder, isOnTheFly); }
visitXmlText
301,339
void (final @NotNull XmlAttribute attribute) { checkAttribute(attribute, holder, isOnTheFly); }
visitXmlAttribute
301,340
void (@NotNull XmlAttributeValue value) { checkAttributeValue(value, holder, isOnTheFly); }
visitXmlAttributeValue
301,341
String () { return "XmlWrongRootElement"; }
getShortName
301,342
HighlightDisplayLevel () { return HighlightDisplayLevel.ERROR; }
getDefaultLevel
301,343
void (@NotNull final XmlTag tag, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) { if (!(tag.getParent() instanceof XmlTag)) { final PsiFile psiFile = tag.getContainingFile(); if (!(psiFile instanceof XmlFile xmlFile)) { return; } final XmlDocument document = xmlFile.getDocument(); if (document == null) { return; } XmlProlog prolog = document.getProlog(); if (prolog == null || XmlHighlightVisitor.skipValidation(prolog)) { return; } final XmlDoctype doctype = prolog.getDoctype(); if (doctype == null) { return; } XmlElement nameElement = doctype.getNameElement(); if (nameElement == null) { return; } String name = tag.getName(); String text = nameElement.getText(); if (tag instanceof HtmlTag) { name = StringUtil.toLowerCase(name); text = StringUtil.toLowerCase(text); } if (!name.equals(text)) { name = XmlUtil.findLocalNameByQualifiedName(name); if (!name.equals(text)) { if (tag instanceof HtmlTag) { return; // it is legal to have html / head / body omitted } final LocalQuickFix localQuickFix = new MyLocalQuickFix(doctype.getNameElement().getText()); holder.registerProblem(XmlChildRole.START_TAG_NAME_FINDER.findChild(tag.getNode()).getPsi(), XmlAnalysisBundle.message("xml.inspections.wrong.root.element"), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, localQuickFix ); final ASTNode astNode = XmlChildRole.CLOSING_TAG_NAME_FINDER.findChild(tag.getNode()); if (astNode != null) { holder.registerProblem(astNode.getPsi(), XmlAnalysisBundle.message("xml.inspections.wrong.root.element"), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, localQuickFix ); } } } } }
checkTag
301,344
String () { return XmlAnalysisBundle.message("xml.quickfix.change.root.element.to", myText); }
getFamilyName
301,345
void (@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { final XmlTag myTag = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), XmlTag.class); myTag.setName(myText); }
applyFix
301,346
String () { return myText; }
getName
301,347
String () { return XmlAnalysisBundle.message("html.quickfix.family"); }
getFamilyName
301,348
void (@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { final PsiElement element = descriptor.getPsiElement(); InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile(); profile.modifyToolSettings(myInspectionKey, element, tool -> tool.addEntry(myName)); }
applyFix
301,349
boolean () { return false; }
startInWriteAction
301,350
IntentionPreviewInfo (@NotNull Project project, @NotNull ProblemDescriptor previewDescriptor) { return generateXmlEntitiesInspectionDiffPreview(project, myInspectionKey.toString(), myName); }
generatePreview
301,351
IntentionPreviewInfo (@NotNull Project project, @NotNull String key, @NotNull String name) { InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile(); final var tool = profile.getInspectionTool(key, project); if (tool != null && tool.getTool() instanceof XmlEntitiesInspection inspection) { final String list = inspection.getAdditionalEntries(); return new IntentionPreviewInfo.CustomDiff(UnknownFileType.INSTANCE, list, list.isBlank() ? name : list + "," + name); } return IntentionPreviewInfo.EMPTY; }
generateXmlEntitiesInspectionDiffPreview
301,352
String () { return XmlAnalysisBundle.message("html.quickfix.switch.to.html5"); }
getFamilyName
301,353
String () { return getFamilyName(); }
getText
301,354
boolean (@NotNull Project project, Editor editor, PsiFile file) { return true; }
isAvailable
301,355
boolean () { return true; }
startInWriteAction
301,356
void (@NotNull Project project, @NotNull ProblemDescriptor descriptor) { applyFix(project); }
applyFix
301,357
PsiElement (@NotNull PsiFile file) { return null; }
getElementToMakeWritable
301,358
void (Project project) { ExternalResourceManagerEx.getInstanceEx().setDefaultHtmlDoctype(Html5SchemaProvider.getHtml5SchemaLocation(), project); DaemonCodeAnalyzer.getInstance(project).restart(); }
applyFix
301,359
String () { return XmlAnalysisBundle.message("html.quickfix.rename.attribute.family"); }
getFamilyName
301,360
String () { return XmlAnalysisBundle.message("html.quickfix.rename.attribute.text", name); }
getName
301,361
void (@NotNull Project project, @NotNull ProblemDescriptor descriptor) { XmlAttribute attribute = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), XmlAttribute.class); if (attribute == null) return; attribute.setName(name); }
applyFix
301,362
void (@NotNull XmlTag tag, @NotNull ProblemsHolder holder, boolean isOnTheFly) { if (!(tag instanceof HtmlTag) || !XmlHighlightVisitor.shouldBeValidated(tag)) { return; } final PsiElement child = tag.getLastChild(); if (child instanceof PsiErrorElement) { return; } if (child != null && child.getNode().getElementType() == XmlTokenType.XML_EMPTY_ELEMENT_END) { return; } final XmlToken tagNameElement = XmlTagUtil.getStartTagNameElement(tag); if (tagNameElement == null) { return; } final String tagName = tagNameElement.getText(); if (HtmlUtil.isSingleHtmlTag(tag, true) || XmlTagUtil.getEndTagNameElement(tag) != null) { return; } holder.registerProblem(tagNameElement, XmlAnalysisBundle.message("html.inspections.element.missing.end.tag"), new MissingClosingTagFix(tagName)); }
checkTag
301,363
String () { return XmlAnalysisBundle.message("html.quickfix.add.named.closing.tag", myName); }
getName
301,364
String () { return XmlAnalysisBundle.message("html.quickfix.add.closing.tag"); }
getFamilyName
301,365
void (@NotNull Project project, @NotNull ProblemDescriptor descriptor) { final PsiElement element = descriptor.getPsiElement(); if (!(element instanceof XmlToken)) { return; } final PsiElement parent = element.getParent(); if (!(parent instanceof XmlTag)) { return; } String text = parent.getText(); if (text.contains("\n")) { int cutoff = -1; for (int i = text.length() - 1; i > 0; i--) { final char c = text.charAt(i); if (c == ' ' || c == '\t') continue; if (c == '\n') cutoff = i; else break; } if (cutoff > 0) { text = text.substring(0, cutoff); } } final String replacementText = text + "</" + element.getText() + ">"; final XmlElementFactory factory = XmlElementFactory.getInstance(project); final XmlTag newTag = factory.createHTMLTagFromText(replacementText); final PsiElement child = parent.getLastChild().copy(); CodeStyleManager.getInstance(project).performActionWithFormatterDisabled((Runnable)() -> { final PsiElement replacement = parent.replace(newTag); if (child instanceof XmlText) { final PsiElement grandChild = child.getLastChild(); if (grandChild instanceof PsiWhiteSpace) { final XmlTag dummyTag = factory.createHTMLTagFromText("<dummy>" + grandChild.getText() + "</dummy>"); final XmlText whitespace = PsiTreeUtil.getChildOfType(dummyTag, XmlText.class); assert whitespace != null; replacement.getParent().addAfter(whitespace, replacement); } } }); }
applyFix
301,366
String () { return getName(); }
getFamilyName
301,367
String () { return getName(); }
getText
301,368
boolean (@NotNull final Project project, final Editor editor, final PsiFile file) { return true; }
isAvailable
301,369
PsiElement (PsiElement psiElement, final boolean start) { PsiElement target = null; PsiElement parent = psiElement.getParent(); if (parent instanceof PsiErrorElement) { parent = parent.getParent(); } if (parent instanceof XmlTag) { if (start) { target = XmlTagUtil.getStartTagNameElement((XmlTag)parent); } else { target = XmlTagUtil.getEndTagNameElement((XmlTag)parent); if (target == null) { final PsiErrorElement errorElement = PsiTreeUtil.getChildOfType(parent, PsiErrorElement.class); target = XmlWrongClosingTagNameInspection.findEndTagName(errorElement); } } } return target; }
findOtherSide
301,370
boolean () { return true; }
startInWriteAction
301,371
String () { return myText; }
getName
301,372
String () { return XmlAnalysisBundle.message("html.quickfix.family"); }
getFamilyName
301,373
void (@NotNull Project project, @NotNull ProblemDescriptor descriptor) { InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile(); profile.modifyToolSettings(myInspectionKey, descriptor.getPsiElement().getContainingFile(), entry -> { XmlEntitiesInspection xmlEntitiesInspection = (XmlEntitiesInspection) entry; xmlEntitiesInspection.addEntry(myName); }); }
applyFix
301,374
boolean () { return false; }
startInWriteAction
301,375
IntentionPreviewInfo (@NotNull Project project, @NotNull ProblemDescriptor previewDescriptor) { return AddCustomHtmlElementIntentionAction.generateXmlEntitiesInspectionDiffPreview(project, myInspectionKey.toString(), myName); }
generatePreview
301,376
JDOMExternalizableStringList (@NotNull final String properties) { final JDOMExternalizableStringList result = new JDOMExternalizableStringList(); final StringTokenizer tokenizer = new StringTokenizer(properties, ","); while (tokenizer.hasMoreTokens()) { result.add(tokenizer.nextToken()); } return result; }
reparseProperties
301,377
void (@NotNull XmlAttribute attribute, @InspectionMessage String message, @NotNull ProblemsHolder holder, @NotNull LocalQuickFix @NotNull ... quickfixes) { final ASTNode node = attribute.getNode(); assert node != null; final ASTNode nameNode = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild(node); if (nameNode != null) { final PsiElement nameElement = nameNode.getPsi(); if (nameElement.getTextLength() > 0) { holder.registerProblem(nameElement, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, quickfixes); } } }
registerProblemOnAttributeName
301,378
boolean (@NotNull String value) { return ContainerUtil.exists(myValues, val -> StringUtil.equalsIgnoreCase(val, value)); }
isCustomValue
301,379
void (@NotNull final String text) { final String s = text.trim(); if (!isCustomValue(s)) { myValues.add(s); } if (!isCustomValuesEnabled()) { myCustomValuesEnabled = true; } }
addEntry
301,380
boolean () { return myCustomValuesEnabled; }
isCustomValuesEnabled
301,381
String () { return StringUtil.join(myValues, ","); }
getAdditionalEntries
301,382
void (@NotNull final String values, Disposable disposable) { JDOMExternalizableStringList oldValue = myValues; myValues = reparseProperties(values); if (disposable != null) { Disposer.register(disposable, () -> { myValues = oldValue; }); } }
updateAdditionalEntries
301,383
boolean (XmlElementDescriptor descriptor) { return descriptor == null || descriptor instanceof AnyXmlElementDescriptor; }
isAbstractDescriptor
301,384
String () { return TAG_SHORT_NAME; }
getShortName
301,385
Logger () { return LOG; }
getLogger
301,386
void (@NotNull final XmlTag tag, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) { if (!(tag instanceof HtmlTag) || !XmlHighlightVisitor.shouldBeValidated(tag)) { return; } XmlElementDescriptor descriptorFromContext = XmlUtil.getDescriptorFromContext(tag); PsiElement parent = tag.getParent(); XmlElementDescriptor parentDescriptor = parent instanceof XmlTag ? ((XmlTag)parent).getDescriptor() : null; XmlElementDescriptor ownDescriptor = isAbstractDescriptor(descriptorFromContext) ? tag.getDescriptor() : descriptorFromContext; if (ownDescriptor instanceof XmlElementDescriptorEx) { ((XmlElementDescriptorEx)ownDescriptor).validateTagName(tag, holder, isOnTheFly); return; } if (descriptorFromContext instanceof XmlElementDescriptorEx) { ((XmlElementDescriptorEx)descriptorFromContext).validateTagName(tag, holder, isOnTheFly); return; } if (isAbstractDescriptor(ownDescriptor) || ((parentDescriptor instanceof HtmlElementDescriptorImpl || parentDescriptor instanceof WebSymbolElementDescriptor webSymbolElementDescriptor && !webSymbolElementDescriptor.isCustomElement()) && ownDescriptor instanceof HtmlElementDescriptorImpl && isAbstractDescriptor(descriptorFromContext))) { final String name = tag.getName(); if (!isCustomValuesEnabled() || !isCustomValue(name)) { final AddCustomHtmlElementIntentionAction action = new AddCustomHtmlElementIntentionAction(TAG_KEY, name, XmlAnalysisBundle.message( "html.quickfix.add.custom.html.tag", name)); // todo: support "element is not allowed" message for html5 // some tags in html5 cannot be found in xhtml5.xsd if they are located in incorrect context, so they get any-element descriptor (ex. "canvas: tag) final String message = isAbstractDescriptor(ownDescriptor) ? XmlAnalysisBundle.message("xml.inspections.unknown.html.tag", name) : XmlAnalysisBundle.message("xml.inspections.element.is.not.allowed.here", name); final PsiElement startTagName = XmlTagUtil.getStartTagNameElement(tag); assert startTagName != null; final PsiElement endTagName = XmlTagUtil.getEndTagNameElement(tag); List<LocalQuickFix> quickfixes = new ArrayList<>(); quickfixes.add(action); if (isOnTheFly) { PsiFile file = startTagName.getContainingFile(); if (file instanceof XmlFile) { quickfixes.add(XmlQuickFixFactory.getInstance().createNSDeclarationIntentionFix(startTagName, "", null)); } // People using non-HTML as their template data language (but having not changed this in the IDE) // will most likely see 'unknown html tag' error, because HTML is usually the default. // So if they check quick fixes for this error they'll discover Change Template Data Language feature. ContainerUtil.addIfNotNull(quickfixes, createChangeTemplateDataFix(file)); } if (HtmlUtil.isHtml5Tag(name) && !HtmlUtil.hasNonHtml5Doctype(tag)) { quickfixes.add(new SwitchToHtml5WithHighPriorityAction()); } ProblemHighlightType highlightType = isNotInjectedOrCustomHtmlFile(tag.getContainingFile()) ? ProblemHighlightType.GENERIC_ERROR_OR_WARNING : ProblemHighlightType.INFORMATION; if (isOnTheFly || highlightType != ProblemHighlightType.INFORMATION) { if (startTagName.getTextLength() > 0) { holder.registerProblem(startTagName, message, highlightType, quickfixes.toArray(LocalQuickFix.EMPTY_ARRAY)); } if (endTagName != null) { holder.registerProblem(endTagName, message, highlightType, quickfixes.toArray(LocalQuickFix.EMPTY_ARRAY)); } } } } }
checkTag
301,387
LocalQuickFix (PsiFile file) { return null; }
createChangeTemplateDataFix
301,388
String () { return BOOLEAN_ATTRIBUTE_SHORT_NAME; }
getShortName
301,389
Logger () { return LOG; }
getLogger
301,390
void (@NotNull final XmlAttribute attribute, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) { if (attribute.getValueElement() == null) { final XmlTag tag = attribute.getParent(); if (tag instanceof HtmlTag) { XmlElementDescriptor elementDescriptor = tag.getDescriptor(); if (elementDescriptor == null || elementDescriptor instanceof AnyXmlElementDescriptor) { return; } XmlAttributeDescriptor attributeDescriptor = attribute.getDescriptor(); if (attributeDescriptor != null && !(attributeDescriptor instanceof AnyXmlAttributeDescriptor)) { String name = attribute.getName(); if (!HtmlUtil.isBooleanAttribute(attributeDescriptor, null) && (!isCustomValuesEnabled() || !isCustomValue(name))) { final boolean html5 = HtmlUtil.isHtml5Context(tag); LocalQuickFix[] quickFixes = !html5 ? new LocalQuickFix[]{ new AddCustomHtmlElementIntentionAction(BOOLEAN_ATTRIBUTE_KEY, name, XmlAnalysisBundle.message( "html.quickfix.add.custom.html.boolean.attribute", name)), XmlQuickFixFactory.getInstance().addAttributeValueFix(attribute), new RemoveAttributeIntentionFix(name), } : new LocalQuickFix[] { XmlQuickFixFactory.getInstance().addAttributeValueFix(attribute) }; String error = null; if (html5) { if (attributeDescriptor instanceof XmlEnumerationDescriptor && ((XmlEnumerationDescriptor<?>)attributeDescriptor).getValueDeclaration(attribute, "") == null) { error = XmlPsiBundle.message("xml.inspections.attribute.requires.value", attribute.getName()); } } else { error = XmlAnalysisBundle.message("html.inspections.attribute.is.not.boolean", attribute.getName()); } if (error != null) { registerProblemOnAttributeName(attribute, error, holder, quickFixes); } } } } } }
checkAttribute
301,391
void (@NotNull PsiElement psiElement, @NotNull AnnotationHolder holder) { if (psiElement instanceof XmlToken) { PsiElement parent = psiElement.getParent(); if (parent instanceof XmlTag tag) { XmlToken start = XmlTagUtil.getStartTagNameElement(tag); XmlToken endTagName = XmlTagUtil.getEndTagNameElement(tag); if (start == psiElement) { if (endTagName != null && !(tag instanceof HtmlTag) && !tag.getName().equals(endTagName.getText())) { registerProblemStart(holder, tag, start, endTagName); } else if (endTagName == null && !(tag instanceof HtmlTag && HtmlUtil.isSingleHtmlTag(tag, true))) { PsiErrorElement errorElement = PsiTreeUtil.getChildOfType(tag, PsiErrorElement.class); endTagName = findEndTagName(errorElement); if (endTagName != null) { registerProblemStart(holder, tag, start, endTagName); } } } else if (endTagName == psiElement) { if (!(tag instanceof HtmlTag) && !tag.getName().equals(endTagName.getText())) { registerProblemEnd(holder, tag, endTagName); } } } } else if (psiElement instanceof PsiErrorElement) { PsiElement[] children = psiElement.getChildren(); for (PsiElement token : children) { if (token instanceof XmlToken && XmlTokenType.XML_NAME == ((XmlToken)token).getTokenType()) { PsiFile psiFile = holder.getCurrentAnnotationSession().getFile(); if (HTMLLanguage.INSTANCE == psiFile.getViewProvider().getBaseLanguage() || HTMLLanguage.INSTANCE == psiElement.getLanguage()) { String message = XmlPsiBundle.message("xml.parsing.closing.tag.matches.nothing"); if (message.equals(((PsiErrorElement)psiElement).getErrorDescription()) && psiFile.getContext() == null) { holder.newAnnotation(HighlightSeverity.WARNING, message).range(psiElement).withFix(new RemoveExtraClosingTagIntentionAction()).create(); } } } } } }
annotate
301,392
void (@NotNull AnnotationHolder holder, @NotNull XmlTag tag, @NotNull XmlToken start, @NotNull XmlToken end) { PsiElement context = tag.getContainingFile().getContext(); if (context != null) { ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(context.getLanguage()); if (parserDefinition != null) { ASTNode contextNode = context.getNode(); if (contextNode != null) { // TODO: we should check for concatenations here return; } } } String tagName = tag.getName(); String endTokenText = end.getText(); RenameTagBeginOrEndIntentionAction renameEndAction = new RenameTagBeginOrEndIntentionAction(tagName, endTokenText, false); RenameTagBeginOrEndIntentionAction renameStartAction = new RenameTagBeginOrEndIntentionAction(endTokenText, tagName, true); holder.newAnnotation(HighlightSeverity.ERROR, XmlAnalysisBundle.message("xml.inspections.tag.has.wrong.closing.tag.name")) .range(start) .withFix(renameEndAction) .withFix(renameStartAction) .create(); }
registerProblemStart
301,393
void (@NotNull AnnotationHolder holder, @NotNull XmlTag tag, @NotNull XmlToken end) { PsiElement context = tag.getContainingFile().getContext(); if (context != null) { ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(context.getLanguage()); if (parserDefinition != null) { ASTNode contextNode = context.getNode(); if (contextNode != null) { // TODO: we should check for concatenations here return; } } } String tagName = tag.getName(); String endTokenText = end.getText(); RenameTagBeginOrEndIntentionAction renameEndAction = new RenameTagBeginOrEndIntentionAction(tagName, endTokenText, false); RenameTagBeginOrEndIntentionAction renameStartAction = new RenameTagBeginOrEndIntentionAction(endTokenText, tagName, true); holder.newAnnotation(HighlightSeverity.ERROR, XmlAnalysisBundle.message("xml.inspections.wrong.closing.tag.name")) .range(end) .withFix(new RemoveExtraClosingTagIntentionAction()) .withFix(renameEndAction) .withFix(renameStartAction) .create(); }
registerProblemEnd
301,394
XmlToken (@Nullable PsiErrorElement element) { if (element == null) return null; ASTNode astNode = element.getNode(); if (astNode == null) return null; ASTNode current = astNode.getLastChildNode(); ASTNode prev = current; while (current != null) { IElementType elementType = prev.getElementType(); if ((elementType == XmlTokenType.XML_NAME || elementType == XmlTokenType.XML_TAG_NAME) && current.getElementType() == XmlTokenType.XML_END_TAG_START) { return (XmlToken)prev.getPsi(); } prev = current; current = current.getTreePrev(); } return null; }
findEndTagName
301,395
String () { return ATTRIBUTE_SHORT_NAME; }
getShortName
301,396
Logger () { return LOG; }
getLogger
301,397
void (@NotNull final XmlAttribute attribute, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) { final XmlTag tag = attribute.getParent(); if (tag instanceof HtmlTag) { XmlElementDescriptor elementDescriptor = tag.getDescriptor(); if (elementDescriptor == null || elementDescriptor instanceof AnyXmlElementDescriptor) { return; } XmlAttributeDescriptor attributeDescriptor = attribute.getDescriptor(); if (attributeDescriptor == null && !attribute.isNamespaceDeclaration()) { final String name = attribute.getName(); if (!XmlUtil.attributeFromTemplateFramework(name, tag) && (!isCustomValuesEnabled() || !isCustomValue(name))) { boolean maySwitchToHtml5 = HtmlUtil.isCustomHtml5Attribute(name) && !HtmlUtil.hasNonHtml5Doctype(tag); ArrayList<LocalQuickFix> quickfixes = new ArrayList<>(6); quickfixes .add(new AddCustomHtmlElementIntentionAction(ATTRIBUTE_KEY, name, XmlAnalysisBundle.message( "html.quickfix.add.custom.html.attribute", name))); quickfixes.add(new RemoveAttributeIntentionFix(name)); if (maySwitchToHtml5) { quickfixes.add(new SwitchToHtml5WithHighPriorityAction()); } addSimilarAttributesQuickFixes(tag, name, quickfixes); addRenameXmlAttributeQuickFixes(tag, name, quickfixes); registerProblemOnAttributeName(attribute, XmlAnalysisBundle.message("xml.inspections.attribute.is.not.allowed.here", attribute.getName()), holder, quickfixes.toArray(LocalQuickFix.EMPTY_ARRAY)); } } else if (attributeDescriptor instanceof XmlAttributeDescriptorEx) { ((XmlAttributeDescriptorEx)attributeDescriptor).validateAttributeName(attribute, holder, isOnTheFly); } } }
checkAttribute
301,398
void (XmlTag tag, String name, ArrayList<? super LocalQuickFix> quickfixes) { XmlElementDescriptor descriptor = tag.getDescriptor(); if (descriptor == null) return; XmlAttributeDescriptor[] descriptors = descriptor.getAttributesDescriptors(tag); int initialSize = quickfixes.size(); for (XmlAttributeDescriptor attr : descriptors) { if (EditDistance.optimalAlignment(name, attr.getName(), false, 1) <= 1) { quickfixes.add(new XmlAttributeRenameFix(attr)); } if (quickfixes.size() >= initialSize + 3) break; } }
addSimilarAttributesQuickFixes
301,399
void (XmlTag tag, String name, ArrayList<? super LocalQuickFix> quickfixes) { for (XmlAttributeRenameProvider renameProvider : XmlAttributeRenameProvider.EP_NAME.getExtensionList()) { quickfixes.addAll(renameProvider.getAttributeFixes(tag, name)); } }
addRenameXmlAttributeQuickFixes