Search in sources :

Example 21 with IMessage

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");
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) Iterator(java.util.Iterator) JSPDirectiveValidator(org.eclipse.jst.jsp.core.internal.validation.JSPDirectiveValidator)

Example 22 with IMessage

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);
                }
            }
        }
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) IncrementalReporter(org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) AnnotationInfo(org.eclipse.wst.sse.ui.internal.reconcile.validator.AnnotationInfo)

Example 23 with IMessage

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);
    }
}
Also used : IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage)

Example 24 with IMessage

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);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 25 with IMessage

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();
}
Also used : Entity(org.eclipse.jpt.jpa.core.context.Entity) RelationshipMapping(org.eclipse.jpt.jpa.core.context.RelationshipMapping) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy)

Aggregations

IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)25 CoreException (org.eclipse.core.runtime.CoreException)7 List (java.util.List)6 Iterator (java.util.Iterator)5 IPath (org.eclipse.core.runtime.IPath)5 Path (org.eclipse.core.runtime.Path)5 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)4 ArrayList (java.util.ArrayList)3 IFile (org.eclipse.core.resources.IFile)3 BadLocationException (org.eclipse.jface.text.BadLocationException)3 Position (org.eclipse.jface.text.Position)3 JSPDirectiveValidator (org.eclipse.jst.jsp.core.internal.validation.JSPDirectiveValidator)3 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)3 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)3 AnnotationInfo (org.eclipse.wst.sse.ui.internal.reconcile.validator.AnnotationInfo)3 IncrementalReporter (org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter)3 IReporter (org.eclipse.wst.validation.internal.provisional.core.IReporter)3 IOException (java.io.IOException)2 IMarker (org.eclipse.core.resources.IMarker)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2