Permalink
Browse files

moved xml/service validation to proper validator

  • Loading branch information...
1 parent c208747 commit e404bb90df7f69a663984083f037c00dfbca67ba @pulse00 pulse00 committed Oct 12, 2012
@@ -16,7 +16,9 @@ Require-Bundle: org.eclipse.core.runtime,
com.dubture.symfony.index,
com.dubture.symfony.annotation,
com.dubture.doctrine.core,
- org.eclipse.wst.validation;bundle-version="1.2.303"
+ org.eclipse.wst.validation,
+ org.eclipse.wst.xml.core,
+ org.eclipse.wst.common.uriresolver
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: com.dubture.symfony.core,
@@ -144,6 +144,28 @@
name="resolutionText">
</attribute>
</extension>
-
+ <extension
+ id="com.dubture.symfony.validation.serviceValidator"
+ name="Symfony Service Validator"
+ point="org.eclipse.wst.validation.validatorV2">
+ <validator
+ build="true"
+ class="com.dubture.symfony.core.validation.ServiceDefinitionValidator"
+ markerId="com.dubture.symfony.core.serviceMarker"
+ sourceid="org.eclipse.wst.xml.ui.internal.validation.DelegatingSourceValidatorForXML"
+ version="1">
+ <include>
+ <rules>
+ <projectNature id="com.dubture.symfony.core.symfonyNature"/>
+ <contentType id="org.eclipse.core.runtime.xml"></contentType>
+ <contentType id="org.eclipse.wst.xml.core.xmlsource"></contentType>
+ <fileext
+ caseSensitive="false"
+ ext="xml">
+ </fileext>
+ </rules>
+ </include>
+ </validator>
+ </extension>
</plugin>
@@ -22,18 +22,11 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.dltk.core.DLTKCore;
import org.eclipse.dltk.core.IScriptProject;
-import org.eclipse.dltk.core.IType;
-import org.eclipse.dltk.core.index2.search.ISearchEngine.MatchRule;
-import org.eclipse.dltk.core.search.IDLTKSearchScope;
-import org.eclipse.dltk.core.search.SearchEngine;
-import org.eclipse.php.internal.core.model.PhpModelAccess;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.yaml.snakeyaml.scanner.ScannerException;
@@ -44,7 +37,6 @@
import com.dubture.symfony.core.parser.YamlRoutingParser;
import com.dubture.symfony.core.parser.YamlTranslationParser;
import com.dubture.symfony.core.preferences.ProjectOptions;
-import com.dubture.symfony.core.resources.SymfonyMarker;
import com.dubture.symfony.core.util.BuildPathUtils;
import com.dubture.symfony.core.util.TranslationUtils;
import com.dubture.symfony.index.SymfonyIndexer;
@@ -62,7 +54,6 @@
* @author Robert Gruendler <r.gruendler@gmail.com>
*
*/
-@SuppressWarnings("restriction")
public abstract class AbstractSymfonyVisitor {
protected IFile file;
@@ -243,7 +234,6 @@ protected void loadXML(IResource resource) {
if (parser.hasServices()) {
indexServices(parser.getServices());
- setMarkers(resource, parser.getServices());
}
if (parser.hasRoutes()) {
@@ -298,52 +288,4 @@ protected void indexServices(HashMap<String, Service> services) {
Logger.logException(e);
}
}
-
- public void setMarkers(IResource resource, HashMap<String,Service> hashMap) throws CoreException
- {
-
- Iterator<String> iterator = hashMap.keySet().iterator();
- IScriptProject scriptProject = DLTKCore.create(resource.getProject());
- IDLTKSearchScope scope = SearchEngine.createSearchScope(scriptProject);
-
- PhpModelAccess model = PhpModelAccess.getDefault();
-
- resource.deleteMarkers(SymfonyMarker.MISSING_SERVICE_CLASS, true, 1);
-
- while (iterator.hasNext()) {
-
- String next = iterator.next();
- Service service = hashMap.get(next);
-
- if (service == null) {
- Logger.log(Logger.INFO, "Error setting marker for service " + next);
- continue;
- }
- String phpClass = service.getPHPClass();
-
- if ("synthetic".equals(phpClass)) {
- Logger.log(Logger.INFO, "Error setting marker for synthetic service " + next);
- continue;
- }
-
- IType[] types = model.findTypes(phpClass, MatchRule.EXACT, 0, 0, scope, null);
-
- if (types.length == 0) {
- IMarker marker = resource.createMarker(SymfonyMarker.MISSING_SERVICE_CLASS);
- marker.setAttribute(SymfonyMarker.SERVICE_CLASS, phpClass);
- marker.setAttribute(SymfonyMarker.RESOLUTION_TEXT, "Create class " + phpClass);
- marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
- marker.setAttribute("problemType", SymfonyMarker.MISSING_SERVICE_CLASS);
- marker.setAttribute(IMarker.MESSAGE, "Class " + phpClass + " does not exist");
- marker.setAttribute(IMarker.LINE_NUMBER, service.getLine());
- //TODO: check for non-existing methods and create a marker
- } else if (types.length == 1) {
-
-
- // type is ambigous.
- } else {
-
- }
- }
- }
}
@@ -8,14 +8,13 @@
******************************************************************************/
package com.dubture.symfony.core.parser;
-import java.io.FileInputStream;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
-import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
@@ -27,7 +26,6 @@
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.xml.sax.SAXParseException;
import com.dubture.symfony.core.log.Logger;
import com.dubture.symfony.index.dao.Route;
@@ -51,25 +49,13 @@
private HashMap<String, Service> services;
private Stack<Route> routes = new Stack<Route>();
- public XMLConfigParser(FileInputStream file) throws Exception {
+ public XMLConfigParser(InputStream inputStream) throws Exception {
- try {
-// SAXParser sp = SAXParserFactory.newInstance().newSAXParser();
-
-// FileInputStream is = new FileInputStream(file);
- doc = PositionalXMLReader.readXML(file);
-// doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
-// sp.parse(file, new LocationRecordingHandler(doc));
-
- xPath = XPathFactory.newInstance().newXPath();
-
- } catch (SAXParseException e) {
- doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("<dummy></dummy>");
- Logger.log(Logger.WARNING, "Error parsing xml ");
- }
+ doc = PositionalXMLReader.readXML(inputStream);
+ xPath = XPathFactory.newInstance().newXPath();
parameters = new HashMap<String, String>();
services = new HashMap<String, Service>();
-
+
}
@@ -0,0 +1,98 @@
+package com.dubture.symfony.core.validation;
+
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.core.IType;
+import org.eclipse.dltk.core.index2.search.ISearchEngine.MatchRule;
+import org.eclipse.dltk.core.search.IDLTKSearchScope;
+import org.eclipse.dltk.core.search.SearchEngine;
+import org.eclipse.php.internal.core.model.PhpModelAccess;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+
+import com.dubture.symfony.core.log.Logger;
+import com.dubture.symfony.core.parser.XMLConfigParser;
+import com.dubture.symfony.core.resources.SymfonyMarker;
+import com.dubture.symfony.index.dao.Service;
+
+@SuppressWarnings("restriction")
+public class ServiceDefinitionValidator extends AbstractValidator {
+
+
+ @Override
+ public ValidationResult validate(IResource resource, int kind,
+ ValidationState state, IProgressMonitor monitor) {
+
+ if (resource.getType() != IResource.FILE) {
+ return null;
+ }
+
+ ValidationResult result = new ValidationResult();
+// IReporter reporter = result.getReporter(monitor);
+ IFile file = (IFile) resource;
+
+ //TODO: check why the include nodes don't work in plugin.xml and we get
+ // everything passed in here...
+ if (!"xml".equals(file.getFileExtension())) {
+ return null;
+ }
+
+ IScriptProject scriptProject = DLTKCore.create(resource.getProject());
+ XMLConfigParser parser;
+ try {
+ parser = new XMLConfigParser(file.getContents());
+ parser.parse();
+ HashMap<String,Service> services = parser.getServices();
+
+ Iterator<String> it = services.keySet().iterator();
+ PhpModelAccess model = PhpModelAccess.getDefault();
+ IDLTKSearchScope scope = SearchEngine.createSearchScope(scriptProject);
+
+ while(it.hasNext()) {
+ String key = it.next();
+ Service service = services.get(key);
+
+ if (service == null) {
+ Logger.log(Logger.INFO, "Error setting marker for service " + key);
+ continue;
+ }
+ String phpClass = service.getPHPClass();
+
+ if ("synthetic".equals(phpClass)) {
+ Logger.log(Logger.INFO, "Error setting marker for synthetic service " + key);
+ continue;
+ }
+
+ IType[] types = model.findTypes(phpClass, MatchRule.EXACT, 0, 0, scope, null);
+
+ if (types.length == 0) {
+
+ IMarker marker = resource.createMarker(SymfonyMarker.MISSING_SERVICE_CLASS);
+ marker.setAttribute(SymfonyMarker.SERVICE_CLASS, phpClass);
+ marker.setAttribute(SymfonyMarker.RESOLUTION_TEXT, "Create class " + phpClass);
+ marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
+ marker.setAttribute("problemType", SymfonyMarker.MISSING_SERVICE_CLASS);
+ marker.setAttribute(IMarker.MESSAGE, "Class " + phpClass + " does not exist");
+ marker.setAttribute(IMarker.LINE_NUMBER, service.getLine());
+ }
+ }
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return result;
+ }
+}
Oops, something went wrong.

0 comments on commit e404bb9

Please sign in to comment.