use of org.eclipse.wst.validation.internal.provisional.core.IMessage in project webtools.sourceediting by eclipse.
the class JSPDirectiveValidatorTest method testBug265710El.
public void testBug265710El() throws Exception {
JSPDirectiveValidator validator = new JSPDirectiveValidator();
IReporter reporter = new ReporterForTest();
ValidationContextForTest helper = new ValidationContextForTest();
String filePath = "/" + PROJECT_NAME + "/WebContent/bug265710el.jsp";
assertTrue("unable to find file: " + filePath, ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath)).exists());
helper.setURI(filePath);
validator.validate(helper, reporter);
if (reporter.getMessages().size() > 0) {
Iterator it = reporter.getMessages().iterator();
while (it.hasNext()) {
IMessage message = (IMessage) it.next();
if (message.getLineNumber() == 11 && message.getSeverity() == IMessage.HIGH_SEVERITY) {
fail("JSP Directive Validator flagged JSP EL in the import directive");
}
}
}
}
use of org.eclipse.wst.validation.internal.provisional.core.IMessage in project webtools.sourceediting by eclipse.
the class MarkupValidator method checkStartEndTagPairs.
private void checkStartEndTagPairs(IStructuredDocumentRegion sdRegion, IReporter reporter) {
if (sdRegion.isDeleted()) {
return;
}
// check start/end tag pairs
IDOMNode xmlNode = getXMLNode(sdRegion);
if (xmlNode == null) {
return;
}
boolean selfClosed = false;
String tagName = null;
/**
* For tags that aren't meant to be EMPTY, make sure it's empty or has an end tag
*/
if (xmlNode.isContainer()) {
IStructuredDocumentRegion endRegion = xmlNode.getEndStructuredDocumentRegion();
if (endRegion == null) {
IStructuredDocumentRegion startRegion = xmlNode.getStartStructuredDocumentRegion();
if (startRegion != null && !startRegion.isDeleted() && DOMRegionContext.XML_TAG_OPEN.equals(startRegion.getFirstRegion().getType())) {
// analyze the tag (check self closing)
ITextRegionList regions = startRegion.getRegions();
ITextRegion r = null;
int start = sdRegion.getStart();
int length = sdRegion.getTextLength();
for (int i = 0; i < regions.size(); i++) {
r = regions.get(i);
if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
tagName = sdRegion.getText(r);
start = sdRegion.getStartOffset(r);
length = r.getTextLength();
} else if (r.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
selfClosed = true;
}
}
if (!selfClosed && (tagName != null)) {
Object[] args = { tagName };
String messageText = NLS.bind(XMLUIMessages.Missing_end_tag_, args);
int lineNumber = getLineNumber(start);
IMessage message = new LocalizedMessage(SEVERITY_MISSING_END_TAG, messageText);
message.setOffset(start);
message.setLength(length);
message.setLineNo(lineNumber);
if (reporter instanceof IncrementalReporter) {
Object[] additionalFixInfo = getStartEndFixInfo(xmlNode, tagName, r);
MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
processor.setProblemId(ProblemIDsXML.MissingEndTag);
processor.setAdditionalFixInfo(additionalFixInfo);
message.setAttribute(QUICKASSISTPROCESSOR, processor);
AnnotationInfo info = new AnnotationInfo(message);
((IncrementalReporter) reporter).addAnnotationInfo(this, info);
} else {
reporter.addMessage(this, message);
}
}
}
} else {
IStructuredDocumentRegion startRegion = xmlNode.getStartStructuredDocumentRegion();
if (startRegion == null || startRegion.isDeleted()) {
// analyze the tag (check self closing)
ITextRegionList regions = endRegion.getRegions();
ITextRegion r = null;
int start = sdRegion.getStart();
int length = sdRegion.getTextLength();
for (int i = 0; i < regions.size(); i++) {
r = regions.get(i);
if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
tagName = sdRegion.getText(r);
start = sdRegion.getStartOffset(r);
length = r.getTextLength();
}
}
if (tagName != null) {
Object[] args = { tagName };
String messageText = NLS.bind(XMLUIMessages.Missing_start_tag_, args);
int lineNumber = getLineNumber(start);
IMessage message = new LocalizedMessage(SEVERITY_MISSING_START_TAG, messageText);
message.setOffset(start);
message.setLength(length);
message.setLineNo(lineNumber);
if (reporter instanceof IncrementalReporter) {
Object[] additionalFixInfo = getStartEndFixInfo(xmlNode, tagName, r);
MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
processor.setProblemId(ProblemIDsXML.MissingStartTag);
processor.setAdditionalFixInfo(additionalFixInfo);
message.setAttribute(QUICKASSISTPROCESSOR, processor);
AnnotationInfo info = new AnnotationInfo(message);
((IncrementalReporter) reporter).addAnnotationInfo(this, info);
} else {
reporter.addMessage(this, message);
}
}
}
}
} else /*
* Check for an end tag that has no start tag
*/
{
IStructuredDocumentRegion startRegion = xmlNode.getStartStructuredDocumentRegion();
if (startRegion == null) {
IStructuredDocumentRegion endRegion = xmlNode.getEndStructuredDocumentRegion();
if (!endRegion.isDeleted()) {
// get name
ITextRegionList regions = endRegion.getRegions();
ITextRegion r = null;
for (int i = 0; i < regions.size(); i++) {
r = regions.get(i);
if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
tagName = sdRegion.getText(r);
}
}
if (!selfClosed && (tagName != null)) {
String messageText = XMLUIMessages.Indicate_no_grammar_specified_severities_error;
int start = sdRegion.getStart();
int lineNumber = getLineNumber(start);
// SEVERITY_STRUCTURE == IMessage.HIGH_SEVERITY
IMessage message = new LocalizedMessage(IMessage.HIGH_SEVERITY, messageText);
message.setOffset(start);
message.setLength(sdRegion.getTextLength());
message.setLineNo(lineNumber);
reporter.addMessage(this, message);
}
}
}
}
}
use of org.eclipse.wst.validation.internal.provisional.core.IMessage in project jbosstools-hibernate by jbosstools.
the class HibernateJpaProject method validateConsoleConfiguration.
/**
* @param messages
*/
protected void validateConsoleConfiguration(List<IMessage> messages) {
if (KnownConfigurations.getInstance().find(getDefaultConsoleConfigurationName()) == null) {
IMessage message = HibernateJpaValidationMessage.buildMessage(IMessage.NORMAL_SEVERITY, Messages.CC_NOT_EXISTS, new String[] { getDefaultConsoleConfigurationName() }, getResource());
messages.add(message);
}
}
use of org.eclipse.wst.validation.internal.provisional.core.IMessage in project jbosstools-hibernate by jbosstools.
the class HibernatePersistenceUnit method validateProperties.
// ********** Validation ***********************************************
@Override
protected void validateProperties(List<IMessage> messages, IReporter reporter) {
String configFile = this.hibernateProperties.getConfigurationFile();
if (configFile != null && configFile.length() > 0) {
IPath path = new Path(configFile);
try {
IJavaProject jp = getJpaProject().getJavaProject();
IPackageFragmentRoot[] pfrs = jp.getPackageFragmentRoots();
for (int i = 0; i < pfrs.length; i++) {
if (pfrs[i].isArchive())
continue;
if (((IContainer) pfrs[i].getResource()).findMember(path) != null) {
return;
}
}
} catch (JavaModelException e) {
HibernateJptPlugin.logException(e);
}
IJavaProject jProject = getJpaProject().getJavaProject();
IResource res = null;
if (jProject != null) {
try {
IPackageFragmentRoot[] allPackageFragmentRoots = jProject.getAllPackageFragmentRoots();
for (IPackageFragmentRoot iPackageFragmentRoot : allPackageFragmentRoots) {
if (!iPackageFragmentRoot.isArchive()) {
IResource sourceFolder = iPackageFragmentRoot.getResource();
if (sourceFolder instanceof IContainer) {
IContainer folder = (IContainer) sourceFolder;
if ((res = folder.findMember(path)) != null) {
break;
}
}
}
}
} catch (JavaModelException e) {
// ignore
}
}
if (res != null) {
int resType = res.getType();
if (resType != IResource.FILE) {
Property prop = getProperty(BasicHibernateProperties.HIBERNATE_CONFIG_FILE);
IMessage message = HibernateJpaValidationMessage.buildMessage(IMessage.HIGH_SEVERITY, NOT_A_FILE, new String[] { configFile }, getResource());
message.setLineNo(prop.getValidationTextRange().getLineNumber());
messages.add(message);
}
} else {
Property prop = getProperty(BasicHibernateProperties.HIBERNATE_CONFIG_FILE);
IMessage message = HibernateJpaValidationMessage.buildMessage(IMessage.HIGH_SEVERITY, CONFIG_FILE_NOT_FOUND, new String[] { configFile }, getResource());
message.setLineNo(prop.getValidationTextRange().getLineNumber());
messages.add(message);
}
}
}
use of org.eclipse.wst.validation.internal.provisional.core.IMessage in project jbosstools-hibernate by jbosstools.
the class NamingStrategyMappingTools method buildJoinTableDefaultName.
public static String buildJoinTableDefaultName(Relationship relationshipReference) {
if (relationshipReference.getJpaProject().getDataSource().connectionProfileIsActive()) {
return buildDbJoinTableDefaultName(relationshipReference);
}
RelationshipMapping relationshipMapping = relationshipReference.getMapping();
if (relationshipMapping == null) {
return null;
}
if (!(relationshipReference.getTypeMapping() instanceof Entity))
// could be JavaNullTypeMapping
return null;
Entity ownerEntity = (Entity) relationshipReference.getTypeMapping();
org.eclipse.jpt.jpa.core.context.Table ownerTable = ownerEntity.getTable();
if (ownerTable == null) {
return null;
}
Entity targetEntity = relationshipMapping.getResolvedTargetEntity();
if (targetEntity == null) {
return null;
}
org.eclipse.jpt.jpa.core.context.Table targetTable = targetEntity.getTable();
if (targetTable == null) {
return null;
}
INamingStrategy ns = getJpaProject(relationshipReference).getNamingStrategy();
if (getJpaProject(relationshipReference).isNamingStrategyEnabled() && ns != null) {
/*
* By testing generated DDL I have found for JPA console configuration:
* 1) first parameter of the method is always fully qualified owner entity class name
* 2) second and forth parameters of the method are always fully qualified target entity class name
* 3) third parameter of the method is name attribute of @Table annotation,
* if it is not specified, then it is *unqualified* name attribute of @Entity annotation
* if @Entity annotation not specified it is *unqualified* name of the target entity class.
* 4) fifth parameter is owner entity field name (even if @Column annotation set different name)
*
*/
try {
String targetEntityName = targetEntity.getPersistentType().getName();
String ownerEntityName = ownerEntity.getPersistentType().getName();
String propName = relationshipMapping.getPersistentAttribute().getName();
return ns.collectionTableName(ownerEntityName, targetTable.getName(), targetEntityName, targetTable.getName(), propName);
} catch (Exception e) {
IMessage m = HibernateJpaValidationMessage.buildMessage(IMessage.HIGH_SEVERITY, Messages.NAMING_STRATEGY_EXCEPTION, relationshipReference);
HibernateJptPlugin.logException(m.getText(), e);
}
}
return ownerTable.getName() + '_' + targetTable.getName();
}
Aggregations