Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBIDE-18387 HTML Validation: Ability to ignore custom htm tags (e.g. <io... #451

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body ng-tro-lo-lo="yeah">

<body ng-tro-lo-lo-attribute="yeah">
<ng-tro-lo-lo-element />
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
package org.jboss.tools.jst.web.ui.editor.test.quickassist;

import junit.framework.TestCase;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
Expand All @@ -24,7 +23,6 @@
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.Workbench;
import org.eclipse.ui.part.FileEditorInput;
import org.jboss.tools.jst.web.ui.internal.editor.jspeditor.JSPMultiPageEditor;
import org.jboss.tools.jst.web.ui.internal.editor.jspeditor.JSPTextEditor;
Expand All @@ -33,8 +31,10 @@
public class JstJspQuickAssistTest extends TestCase {
private static final String PROJECT_NAME = "StaticWebProject";
private static final String PAGE_NAME = "WebContent/quickassist/html5.html";
private static final String TEST_STRING = "ng-tro-lo-lo";
private static final String TEST_QUICKQIX_CLASSNAME = "org.eclipse.wst.html.ui.internal.text.correction.IgnoreAttributeNameCompletionProposal";
private static final String TEST_ATTRIBUTE_STRING = "ng-tro-lo-lo-attribute";
private static final String TEST_ATTRIBUTE_QUICKQIX_CLASSNAME = "org.eclipse.wst.html.ui.internal.text.correction.IgnoreAttributeNameCompletionProposal";
private static final String TEST_ELEMENT_STRING = "ng-tro-lo-lo-element";
private static final String TEST_ELEMENT_QUICKQIX_CLASSNAME = "org.eclipse.wst.html.ui.internal.text.correction.IgnoreElementNameCompletionProposal";
private IProject project;

public void setUp() throws Exception {
Expand All @@ -48,56 +48,65 @@ public void setUp() throws Exception {
*
* @throws CoreException
*/
public void testWSTQuickAssistProcessors() throws CoreException {
checkProposalExistance(project, PAGE_NAME, TEST_STRING, 0,
TEST_QUICKQIX_CLASSNAME);
public void testWSTQuickAssistProcessorsForAttrubutes()
throws CoreException {
checkProposalExistance(project, PAGE_NAME, TEST_ATTRIBUTE_STRING, 0,
TEST_ATTRIBUTE_QUICKQIX_CLASSNAME);
}


/**
* Test case for the following issue:
* (JBIDE-18724) HTML Validation: Ability to ignore custom htm tags (e.g. <ion-*>)
*
* @throws CoreException
*/
public void testWSTQuickAssistProcessorsForElements() throws CoreException {
checkProposalExistance(project, PAGE_NAME, TEST_ELEMENT_STRING, 0,
TEST_ELEMENT_QUICKQIX_CLASSNAME);
}

private void checkProposalExistance(IProject project, String fileName, String str, int id,
String proposalClassName) throws CoreException {
IFile file = project.getFile(fileName);
assertTrue("File '"+file.getFullPath()+"' not found!", file.exists());
assertTrue("File '" + file.getFullPath() + "' not found!", file.exists());

IEditorInput input = new FileEditorInput(file);
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, "org.jboss.tools.jst.jsp.jspeditor.HTMLTextEditor", true);
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, "org.jboss.tools.jst.jsp.jspeditor.HTMLTextEditor", true);
final ISourceViewer viewer = getViewer(editor);

try{
try {
IDocument document = viewer.getDocument();

String text = document.get();
final int offset = text.indexOf(str);
final int length = str.length();
assertTrue("String - "+str+" not found", offset > 0);

IQuickAssistAssistant assiatant = ((SourceViewer)viewer).getQuickAssistAssistant();
assertTrue("String - " + str + " not found", offset > 0);
IQuickAssistAssistant assiatant = ((SourceViewer) viewer)
.getQuickAssistAssistant();
TextInvocationContext ctx = new TextInvocationContext(viewer, offset, length);
ICompletionProposal[] proposals = assiatant.getQuickAssistProcessor().computeQuickAssistProposals(ctx);

for(ICompletionProposal proposal : proposals){
for (ICompletionProposal proposal : proposals) {
if (proposal.getClass().getName().equals(proposalClassName)) {
return;
}
}

fail("Quick fix: "+proposalClassName+" not found");
}finally{
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editor, false);
fail("Quick fix: " + proposalClassName + " not found");
} finally {
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().closeEditor(editor, false);
}
}

private ISourceViewer getViewer(IEditorPart editor){
if(editor instanceof JSPMultiPageEditor){
IEditorPart ed = ((JSPMultiPageEditor)editor).getSourceEditor();

if(ed instanceof JSPTextEditor){
return ((JSPTextEditor)ed).getTextViewer();
}else {
fail("Editor must be JSPTextEditor, but was "+ed.getClass());
private ISourceViewer getViewer(IEditorPart editor) {
if (editor instanceof JSPMultiPageEditor) {
IEditorPart ed = ((JSPMultiPageEditor) editor).getSourceEditor();
if (ed instanceof JSPTextEditor) {
return ((JSPTextEditor) ed).getTextViewer();
} else {
fail("Editor must be JSPTextEditor, but was " + ed.getClass());
}
}else{
fail("editor must be instanceof EditorPartWrapper, but was "+editor.getClass());
} else {
fail("editor must be instanceof EditorPartWrapper, but was "
+ editor.getClass());
}
return null;
}
}
}