diff options
author | Florian Groeger <groeger@itestra.de> | 2013-12-19 10:31:55 +0100 |
---|---|---|
committer | Stefan Laner <laner@itestra.de> | 2014-03-05 15:29:00 +0100 |
commit | 43967c317751a2acf809357d7dbf8ccb9e7120a2 (patch) | |
tree | 031c4bc136971aeb809cbaca96bbf385e364ab39 | |
parent | 1f195652b8bc7171fecb642154c18ec540c2d29f (diff) | |
download | genivi-common-api-runtime-43967c317751a2acf809357d7dbf8ccb9e7120a2.tar.gz |
Deleted the old validator, added a validator with general restrictions
Change-Id: I095196950cbabeb226b76d6368462cc1e50ebadb
14 files changed, 420 insertions, 816 deletions
diff --git a/org.genivi.commonapi.core.validator.feature/.settings/org.eclipse.core.resources.prefs b/org.genivi.commonapi.core.validator.feature/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 99f26c0..0000000 --- a/org.genivi.commonapi.core.validator.feature/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding/<project>=UTF-8 diff --git a/org.genivi.commonapi.core.validator.feature/.settings/org.eclipse.core.runtime.prefs b/org.genivi.commonapi.core.validator.feature/.settings/org.eclipse.core.runtime.prefs deleted file mode 100644 index 5a0ad22..0000000 --- a/org.genivi.commonapi.core.validator.feature/.settings/org.eclipse.core.runtime.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -line.separator=\n diff --git a/org.genivi.commonapi.core.validator.feature/build.properties b/org.genivi.commonapi.core.validator.feature/build.properties index 2cbd854..a4bee29 100644 --- a/org.genivi.commonapi.core.validator.feature/build.properties +++ b/org.genivi.commonapi.core.validator.feature/build.properties @@ -1,3 +1,3 @@ bin.includes = feature.xml,\ feature.properties,\ - license.html + license.html
\ No newline at end of file diff --git a/org.genivi.commonapi.core.validator/.classpath b/org.genivi.commonapi.core.validator/.classpath index ad32c83..098194c 100644 --- a/org.genivi.commonapi.core.validator/.classpath +++ b/org.genivi.commonapi.core.validator/.classpath @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> <classpathentry kind="output" path="bin"/> diff --git a/org.genivi.commonapi.core.validator/.settings/org.eclipse.core.resources.prefs b/org.genivi.commonapi.core.validator/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 99f26c0..0000000 --- a/org.genivi.commonapi.core.validator/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding/<project>=UTF-8 diff --git a/org.genivi.commonapi.core.validator/.settings/org.eclipse.core.runtime.prefs b/org.genivi.commonapi.core.validator/.settings/org.eclipse.core.runtime.prefs deleted file mode 100644 index 5a0ad22..0000000 --- a/org.genivi.commonapi.core.validator/.settings/org.eclipse.core.runtime.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -line.separator=\n diff --git a/org.genivi.commonapi.core.validator/.settings/org.eclipse.jdt.core.prefs b/org.genivi.commonapi.core.validator/.settings/org.eclipse.jdt.core.prefs index 8000cd6..f42de36 100644 --- a/org.genivi.commonapi.core.validator/.settings/org.eclipse.jdt.core.prefs +++ b/org.genivi.commonapi.core.validator/.settings/org.eclipse.jdt.core.prefs @@ -1,11 +1,7 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/org.genivi.commonapi.core.validator/META-INF/MANIFEST.MF b/org.genivi.commonapi.core.validator/META-INF/MANIFEST.MF index 45680ec..0e55bb6 100644 --- a/org.genivi.commonapi.core.validator/META-INF/MANIFEST.MF +++ b/org.genivi.commonapi.core.validator/META-INF/MANIFEST.MF @@ -1,10 +1,10 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: GENIVI Common API validator +Bundle-Name: General Bundle-Vendor: BMW AG Bundle-SymbolicName: org.genivi.commonapi.core.validator;singleton:=true Bundle-Version: 2.1.5.qualifier -Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Require-Bundle: org.eclipse.ui, org.eclipse.core.expressions;bundle-version="3.4.400", org.eclipse.core.resources, @@ -15,10 +15,9 @@ Require-Bundle: org.eclipse.ui, org.eclipse.xtext.ui.ecore;bundle-version="2.4.0", com.google.inject;bundle-version="3.0.0", org.genivi.commonapi.core;bundle-version="2.1.4", - org.genivi.commonapi.core.ui;bundle-version="2.1.4" + org.genivi.commonapi.core.ui;bundle-version="2.1.4", + org.franca.core.dsl;bundle-version="0.8.9", + org.eclipse.xtext;bundle-version="2.4.3" Import-Package: org.eclipse.core.resources, - org.franca.core.dsl.validation, - org.franca.core.franca, - org.franca.core.franca.impl, - org.franca.core.utils + org.eclipse.core.runtime;version="3.4.0" Export-Package: org.genivi.commonapi.core.validator diff --git a/org.genivi.commonapi.core.validator/plugin.xml b/org.genivi.commonapi.core.validator/plugin.xml index 09cd4af..c135580 100644 --- a/org.genivi.commonapi.core.validator/plugin.xml +++ b/org.genivi.commonapi.core.validator/plugin.xml @@ -4,8 +4,8 @@ <extension point="org.franca.core.dsl.francaValidator"> <validator - class="org.genivi.commonapi.core.validator.ResourceValidator" + class="org.genivi.commonapi.core.validator.ValidatorCore" mode="FAST"> </validator> </extension> -</plugin> +</plugin>
\ No newline at end of file diff --git a/org.genivi.commonapi.core.validator/src/org/genivi/commonapi/core/validator/AllInfoMapsBuilder.java b/org.genivi.commonapi.core.validator/src/org/genivi/commonapi/core/validator/AllInfoMapsBuilder.java deleted file mode 100644 index 86bca18..0000000 --- a/org.genivi.commonapi.core.validator/src/org/genivi/commonapi/core/validator/AllInfoMapsBuilder.java +++ /dev/null @@ -1,169 +0,0 @@ -/* Copyright (C) 2013 BMW Group - * Author: Manfred Bathelt (manfred.bathelt@bmw.de) - * Author: Juergen Gehring (juergen.gehring@bmw.de) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package org.genivi.commonapi.core.validator; - -import org.franca.core.franca.impl.FModelImpl; -import java.io.File; -import java.io.IOException; -import java.util.*; -import java.util.Map.Entry; - -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; -import org.franca.core.franca.FInterface; -import org.franca.core.franca.FTypeCollection; - -public class AllInfoMapsBuilder { - - private String path = ""; - public Map<String, Triple<String, ArrayList<String>, ArrayList<String>>> allInfo = new HashMap<String, Triple<String, ArrayList<String>, ArrayList<String>>>(); - private Triple<String, ArrayList<String>, ArrayList<String>> infoTriple; - private ResourceSet resourceSet = null; - public Map<String, HashMap<String, HashSet<String>>> fastAllInfo = new HashMap<String, HashMap<String, HashSet<String>>>(); - - public boolean buildAllInfos(String path) { - if (this.path.equals(path)) { - return false; - } - resourceSet = new ResourceSetImpl(); - this.path = path; - allInfo.clear(); - buildAllInfo(path); - fastAllInfo.clear(); - buildFastAllInfo(); - return true; - - } - - private void buildFastAllInfo() { - - for (Entry<String, Triple<String, ArrayList<String>, ArrayList<String>>> entry : allInfo - .entrySet()) { - addNames(entry, entry.getValue().interfaceList); - addNames(entry, entry.getValue().typeCollectionList); - } - } - - private void addNames( - Entry<String, Triple<String, ArrayList<String>, ArrayList<String>>> entry, - ArrayList<String> arrayList) { - for (String name : arrayList) { - HashMap<String, HashSet<String>> hilfMap = new HashMap<String, HashSet<String>>(); - HashSet<String> hilfSet = new HashSet<String>(); - if (fastAllInfo.containsKey(name)) { - hilfMap = fastAllInfo.get(name); - if (hilfMap.containsKey(entry.getValue().packageName)) { - hilfSet = hilfMap.get(entry.getValue().packageName); - hilfSet.add(entry.getKey()); - hilfMap.put(entry.getValue().packageName, hilfSet); - fastAllInfo.put(name, hilfMap); - } - } - hilfSet.add(entry.getKey()); - hilfMap.put(entry.getValue().packageName, hilfSet); - fastAllInfo.put(name, hilfMap); - } - } - - public void updateAllInfo(EObject model, String absolutPath) { - ArrayList<String> typeCollectionList = new ArrayList<String>(); - ArrayList<String> interfaceList = new ArrayList<String>(); - if (model != null) { - for (EObject e : model.eContents()) { - if (e instanceof FTypeCollection && !(e instanceof FInterface)) { - typeCollectionList.add(((FTypeCollection) e).getName()); - } - if (e instanceof FInterface) { - interfaceList.add(((FInterface) e).getName()); - } - } - infoTriple = new Triple<String, ArrayList<String>, ArrayList<String>>( - ((FModelImpl) model).getName(), typeCollectionList, - interfaceList); - allInfo.put(absolutPath, infoTriple); - } - fastAllInfo.clear(); - buildFastAllInfo(); - } - - private void buildAllInfo(String path) { - - File folder = new File(path); - for (File file : folder.listFiles()) { - if (file.isDirectory()) { - if (!(file.getName().equals("bin") || file.equals(".settings"))) - buildAllInfo(path + "/" + file.getName()); - } - if (file.isFile()) { - if (file.getName().endsWith(".fidl")) { - String cwd = "file:/" + path; - EObject model = buildResource(file.getName(), cwd); - ArrayList<String> typeCollectionList = new ArrayList<String>(); - ArrayList<String> interfaceList = new ArrayList<String>(); - if (model != null) { - for (EObject e : model.eContents()) { - if (e instanceof FTypeCollection - && !(e instanceof FInterface)) { - typeCollectionList.add(((FTypeCollection) e) - .getName()); - } - if (e instanceof FInterface) { - interfaceList.add(((FInterface) e).getName()); - } - } - infoTriple = new Triple<String, ArrayList<String>, ArrayList<String>>( - ((FModelImpl) model).getName(), - typeCollectionList, interfaceList); - allInfo.put(file.getAbsolutePath().replace("\\", "/"), - infoTriple); - } - } - } - } - } - - private EObject buildResource(String filename, String cwd) { - - URI fileURI = normalizeURI(URI.createURI(filename)); - URI cwdURI = normalizeURI(URI.createURI(cwd)); - Resource resource = null; - - if (cwd != null && cwd.length() > 0) { - resourceSet - .getURIConverter() - .getURIMap() - .put(fileURI, - URI.createURI((cwdURI.toString() + "/" + fileURI - .toString()).replaceAll("/+", "/"))); - } - - try { - - resource = resourceSet.getResource(fileURI, true); - resource.load(Collections.EMPTY_MAP); - } catch (IOException e) { - return null; - } - try { - return resource.getContents().get(0); - } catch (Exception e) { - return null; - } - } - - private static URI normalizeURI(URI path) { - if (path.isFile()) { - return URI.createURI(path.toString().replaceAll("\\\\", "/")); - } - return path; - } - -} diff --git a/org.genivi.commonapi.core.validator/src/org/genivi/commonapi/core/validator/ResourceValidator.java b/org.genivi.commonapi.core.validator/src/org/genivi/commonapi/core/validator/ResourceValidator.java deleted file mode 100644 index 0f08eb2..0000000 --- a/org.genivi.commonapi.core.validator/src/org/genivi/commonapi/core/validator/ResourceValidator.java +++ /dev/null @@ -1,598 +0,0 @@ -/* Copyright (C) 2013 BMW Group - * Author: Manfred Bathelt (manfred.bathelt@bmw.de) - * Author: Juergen Gehring (juergen.gehring@bmw.de) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - - - -package org.genivi.commonapi.core.validator; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.genivi.commonapi.core.generator.FTypeCycleDetector; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; - -import org.eclipse.xtext.validation.ValidationMessageAcceptor; -import org.franca.core.dsl.validation.IFrancaExternalValidator; -import org.franca.core.franca.FArgument; - -import org.franca.core.franca.FAttribute; -import org.franca.core.franca.FBroadcast; -import org.franca.core.franca.FEnumerationType; -import org.franca.core.franca.FEnumerator; -import org.franca.core.franca.FField; -import org.franca.core.franca.FInterface; -import org.franca.core.franca.FMapType; -import org.franca.core.franca.FMethod; -import org.franca.core.franca.FModel; -import org.franca.core.franca.FStructType; -import org.franca.core.franca.FType; -import org.franca.core.franca.FTypeCollection; -import org.franca.core.franca.FTypeRef; -import org.franca.core.franca.FTypeDef; -import org.franca.core.franca.FrancaPackage; -import org.franca.core.franca.Import; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; - -import com.google.inject.Guice; - -public class ResourceValidator implements IFrancaExternalValidator { - - private FTypeCycleDetector cycleDetector; - private ResourceSet resourceSet; - private HashMap<String, HashSet<String>> importList = new HashMap<String, HashSet<String>>(); - private Boolean hasChanged = false; - private AllInfoMapsBuilder aimBuilder = new AllInfoMapsBuilder(); - private Map<String, HashMap<String, HashSet<String>>> fastAllInfo = new HashMap<String, HashMap<String, HashSet<String>>>(); - private CppKeywords cppKeyWords = new CppKeywords(); - - @Override - public void validateModel(FModel model, - ValidationMessageAcceptor messageAcceptor) { - cycleDetector = Guice.createInjector().getInstance( - FTypeCycleDetector.class); - resourceSet = new ResourceSetImpl(); - Resource res = model.eResource(); - URI uri = res.getURI(); - int segCount = uri.segmentCount() -2; - String projectName = uri.segment(1); - final Path platformPath = new Path(res.getURI().toPlatformString(true)); - final IFile file = ResourcesPlugin.getWorkspace().getRoot() - .getFile(platformPath); - IPath filePath = file.getLocation(); - String cwd = filePath.removeLastSegments(segCount).toString(); - - if (aimBuilder.buildAllInfos(cwd)) { - fastAllInfo = aimBuilder.fastAllInfo; - } else { - if (!uri.segment(2).toString().equals("bin")) - aimBuilder.updateAllInfo((EObject) model, filePath.toString()); - fastAllInfo = aimBuilder.fastAllInfo; - } - - validateImport(model, messageAcceptor, file, filePath, cwd); - List<String> interfaceTypecollectionNames = new ArrayList<String>(); - for (FTypeCollection fTypeCollection : model.getTypeCollections()) { - interfaceTypecollectionNames.add(fTypeCollection.getName()); - validateImportedTypeCollections(model, messageAcceptor, file, cwd, - fTypeCollection); - } - HashMap<FInterface,EList<FInterface>> managedInterfaces = new HashMap<FInterface,EList<FInterface>>(); - for (FInterface fInterface : model.getInterfaces()) { - interfaceTypecollectionNames.add(fInterface.getName()); - managedInterfaces.put(fInterface, fInterface.getManagedInterfaces()); - validateImportedTypeCollections(model, messageAcceptor, file, cwd, - fInterface); - } - - for (FTypeCollection fTypeCollection : model.getTypeCollections()) { - validateTypeCollectionName(model, messageAcceptor, filePath, - interfaceTypecollectionNames, fTypeCollection); - validateTypeCollectionElements(messageAcceptor, fTypeCollection); - } - - for (FInterface fInterface : model.getInterfaces()) { - validateManagedInterfaces(messageAcceptor, fInterface); - validateTypeCollectionName(model, messageAcceptor, filePath, interfaceTypecollectionNames, fInterface); - validateFInterfaceElements(messageAcceptor, fInterface); - - } - - interfaceTypecollectionNames.clear(); - importList.clear(); - } - private void validateFInterfaceElements( - ValidationMessageAcceptor messageAcceptor, FInterface fInterface) { - if (fInterface.getVersion() == null) - acceptError( - "Missing version! Add: version(major int minor int)", - fInterface, FrancaPackage.Literals.FINTERFACE__BASE, - -1, messageAcceptor); - - for (FAttribute att : fInterface.getAttributes()) { - validateName(att.getName(), messageAcceptor, att); - } - for (FBroadcast fBroadcast : fInterface.getBroadcasts()) { - validateName(fBroadcast.getName(), messageAcceptor, fBroadcast); - for (FArgument out : fBroadcast.getOutArgs()) { - validateName(out.getName(), messageAcceptor, out); - } - } - for (FMethod fMethod : fInterface.getMethods()) { - validateName(fMethod.getName(), messageAcceptor, fMethod); - for (FArgument out : fMethod.getOutArgs()) { - validateMethodArgument(messageAcceptor, fMethod, out); - } - for (FArgument in : fMethod.getInArgs()) { - validateMethodArgument(messageAcceptor, fMethod, in); - } - } - } - - private void validateTypeCollectionElements( - ValidationMessageAcceptor messageAcceptor, - FTypeCollection fTypeCollection) { - for (FType fType : fTypeCollection.getTypes()) { - validateName(fType.getName(), messageAcceptor, fType); - if (fType instanceof FStructType) { - for (FField fField : ((FStructType) fType).getElements()) { - validateName(fField.getName(), messageAcceptor, fField); - } - } - - if (fType instanceof FMapType) - validateMapKey((FMapType) fType, messageAcceptor); - - if (fType instanceof FEnumerationType) { - for (FEnumerator fEnumerator : ((FEnumerationType) fType) - .getEnumerators()) { - validateName(fEnumerator.getName(), messageAcceptor, - fEnumerator); - if (fEnumerator.getValue() != null) { - String enumeratorValue = fEnumerator.getValue() - .toLowerCase(); - validateEnumerationValue(enumeratorValue, - messageAcceptor, fEnumerator); - } - } - } - } - } - - private void validateImport(FModel model, - ValidationMessageAcceptor messageAcceptor, final IFile file, - IPath filePath, String cwd) { - HashSet<String> importedFiles = new HashSet<String>(); - ArrayList<String> importUriAndNamesspace = new ArrayList<String>(); - for (Import fImport : model.getImports()) { - - if (importUriAndNamesspace.contains(fImport.getImportURI() + "," - + fImport.getImportedNamespace())) - acceptWarning("Multiple times imported!", - fImport, FrancaPackage.Literals.IMPORT__IMPORT_URI, -1, - messageAcceptor); - if (fImport.getImportURI().equals(file.getName())) { - acceptError("Class may not import itself!", - fImport, FrancaPackage.Literals.IMPORT__IMPORT_URI, -1, - messageAcceptor); - } else { - Path absoluteImportPath = new Path(fImport.getImportURI()); - if (!absoluteImportPath.isAbsolute()) { - absoluteImportPath = new Path(cwd + "/" - + fImport.getImportURI()); - importedFiles.add(absoluteImportPath.toString()); - } else { - importedFiles.add(absoluteImportPath.toString() - .replaceFirst(absoluteImportPath.getDevice() + "/", - "")); - } - - } - importUriAndNamesspace.add(fImport.getImportURI() + "," - + fImport.getImportedNamespace()); - } - importUriAndNamesspace.clear(); - importList.put(filePath.toString(), importedFiles); - - ArrayList<String> start = new ArrayList<String>(); - try { - importList = buildImportList(importList); - } catch (NullPointerException e) { - } - start.add(filePath.toString()); - for (Import fImport : model.getImports()) { - Path importPath = new Path(fImport.getImportURI()); - if (importPath.isAbsolute()) { - findCyclicImports( - importPath.toString().replaceFirst( - importPath.getDevice() + "/", ""), - filePath.toString(), start, fImport, messageAcceptor); - } else { - importPath = new Path(cwd + "/" + fImport.getImportURI()); - findCyclicImports(importPath.toString(), filePath.toString(), - start, fImport, messageAcceptor); - } - } - start.clear(); - } - - private void validateMethodArgument(ValidationMessageAcceptor messageAcceptor, - FMethod fMethod, FArgument arg) { - if (arg.getName().equals(fMethod.getName())) { - acceptError("Parameters cannot share name with method", arg, - FrancaPackage.Literals.FMODEL_ELEMENT__NAME, - -1, messageAcceptor); - } - validateName(arg.getName(), messageAcceptor, arg); - } - - private void validateTypeCollectionName(FModel model, - ValidationMessageAcceptor messageAcceptor, IPath filePath, - List<String> interfaceTypecollectionNames, - FTypeCollection fTypeCollection) { - validateName(fTypeCollection.getName(), messageAcceptor, - fTypeCollection); - if (interfaceTypecollectionNames.indexOf(fTypeCollection.getName()) != interfaceTypecollectionNames - .lastIndexOf(fTypeCollection.getName())) { - acceptError("Name " + fTypeCollection.getName() - + " isn't unique in this file!", fTypeCollection, FrancaPackage.Literals.FMODEL_ELEMENT__NAME, - -1, messageAcceptor); - } - if (fastAllInfo.get(fTypeCollection.getName()).get(model.getName()) - .size() > 1) { - for (String s : fastAllInfo.get(fTypeCollection.getName()).get( - model.getName())) { - if (!s.equals(filePath.toString())) { - if (importList.containsKey(s)) { - acceptError( - "Imported file " - + s - + " has interface or typeCollection with the same name and same package!", - fTypeCollection, FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, messageAcceptor); - } else { - acceptWarning( - "Interface or typeCollection in file " - + s - + " has the same name and same package!", - fTypeCollection, FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, messageAcceptor); - } - } - } - } - } - - private void validateImportedTypeCollections(FModel model, - ValidationMessageAcceptor messageAcceptor, final IFile file, - String cwd, FTypeCollection fTypeCollection) { - String type="typeCollection name"; - if(fTypeCollection instanceof FInterface) - type = "interface name"; - for(Entry<String, Triple<String, ArrayList<String>, ArrayList<String>>> entry :aimBuilder.allInfo.entrySet()){ - if(!entry.getKey().equals(cwd+"/"+file.getName())){ - if(entry.getValue().packageName.startsWith(model.getName()+"."+fTypeCollection.getName())){ - if(importList.get(cwd+"/"+file.getName()).contains(entry.getKey())){ - acceptError( - "Imported file's package " - + entry.getValue().packageName - + " may not start with package " - + model.getName() + " + "+type - + fTypeCollection.getName(), fTypeCollection, - FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, messageAcceptor); - }else{ - acceptWarning( - entry.getKey()+". File's package " - + entry.getValue().packageName - + " starts with package " - + model.getName() + " + "+type - + fTypeCollection.getName(), fTypeCollection, - null, -1, messageAcceptor); - } - } - } - } - } - private void validateManagedInterfaces( - ValidationMessageAcceptor messageAcceptor, FInterface fInterface) { - ArrayList<FInterface> startI = new ArrayList<FInterface>(); - int index = 0 ; - startI.add(fInterface); - ArrayList<FInterface> managedList = new ArrayList<FInterface>(); - for(FInterface managedInterface : fInterface.getManagedInterfaces()){ - findCyclicManagedInterfaces(managedInterface, startI , fInterface, messageAcceptor, index, false); - if(managedList.contains(managedInterface)) - acceptError("Interface "+ managedInterface.getName() +" is already managed! Delete this equivalent!", fInterface, FrancaPackage.Literals.FINTERFACE__MANAGED_INTERFACES, index, messageAcceptor); - managedList.add(managedInterface); - index++; - } - } - - private void findCyclicManagedInterfaces(FInterface rekInterface, - ArrayList<FInterface> interfaceList, FInterface fInterface, - ValidationMessageAcceptor messageAcceptor, int index, boolean managed){ - if(interfaceList.contains(rekInterface)){ - String errorString=""; - for(FInterface a : interfaceList ){ - errorString=errorString + a.getName()+" -> "; - } - errorString = errorString + rekInterface.getName(); - if(rekInterface.equals(fInterface)){ - acceptError("Interface "+fInterface.getName()+" manages itself: " +errorString, fInterface, FrancaPackage.Literals.FINTERFACE__MANAGED_INTERFACES, index, messageAcceptor); - }else{ - if(!managed){ - acceptError("Cycle detected: " +errorString, fInterface, FrancaPackage.Literals.FINTERFACE__MANAGED_INTERFACES, index, messageAcceptor); - } - } - acceptError("Cycle detected: " +errorString, fInterface, FrancaPackage.Literals.FINTERFACE__MANAGED_INTERFACES, index, messageAcceptor); - }else{ - interfaceList.add(rekInterface); - for(FInterface nextInterface :rekInterface.getManagedInterfaces()){ - findCyclicManagedInterfaces(nextInterface, interfaceList, fInterface, messageAcceptor, index, managed); - } - if(rekInterface.getBase()!=null) - findCyclicManagedInterfaces(rekInterface.getBase(), interfaceList, fInterface, messageAcceptor, index, true); - interfaceList.remove(rekInterface); - } - } - - private HashMap<String, HashSet<String>> buildImportList( - HashMap<String, HashSet<String>> rekImportList) { - HashMap<String, HashSet<String>> helpMap = new HashMap<String, HashSet<String>>(); - for (Entry<String, HashSet<String>> entry : rekImportList.entrySet()) { - for (String importedPath : entry.getValue()) { - if (!rekImportList.containsKey(importedPath)) { - hasChanged = true; - HashSet<String> importedFIDL = new HashSet<String>(); - EObject resource = null; - resource = buildResource( - importedPath.substring( - importedPath.lastIndexOf("/") + 1, - importedPath.length()), - "file:/" - + importedPath.substring(0, - importedPath.lastIndexOf("/") + 1)); - for (EObject imp : resource.eContents()) { - if (imp instanceof Import) { - Path importImportedPath = new Path( - ((Import) imp).getImportURI()); - if (importImportedPath.isAbsolute()) { - importedFIDL.add(importImportedPath.toString() - .replaceFirst( - importImportedPath.getDevice() - + "/", "")); - } else { - importImportedPath = new Path( - importedPath.substring(0, - importedPath.lastIndexOf("/")) - + "/" - + ((Import) imp).getImportURI()); - importedFIDL.add(importImportedPath.toString()); - } - } - } - helpMap.put(importedPath, importedFIDL); - } - } - } - if (hasChanged) { - hasChanged = false; - helpMap.putAll(rekImportList); - return buildImportList(helpMap); - } else { - return rekImportList; - } - } - private void findCyclicImports(String filePath, String prevFilePath, - ArrayList<String> cyclicList, Import imp, - ValidationMessageAcceptor messageAcceptor) { - if (cyclicList.contains(filePath)) { - String errorString = ""; - for (String impString : cyclicList) { - errorString = errorString + impString + "->"; - } - if (prevFilePath.equals(filePath)) { - if (cyclicList.size() > 1) - acceptError("Last file imports itself!: " - + errorString + filePath, imp, - FrancaPackage.Literals.IMPORT__IMPORT_URI, - -1, messageAcceptor); - return; - } else { - acceptError("Cyclic Imports: " + errorString - + filePath, imp, - FrancaPackage.Literals.IMPORT__IMPORT_URI, -1, messageAcceptor); - return; - } - } else { - cyclicList.add(filePath); - if (importList.containsKey(filePath)) { - for (String importPath : importList.get(filePath)) { - findCyclicImports(importPath, filePath, cyclicList, imp, - messageAcceptor); - } - } - cyclicList.remove(cyclicList.size() - 1); - } - } - - private EObject buildResource(String filename, String cwd) { - URI fileURI = normalizeURI(URI.createURI(filename)); - URI cwdURI = normalizeURI(URI.createURI(cwd)); - Resource resource = null; - - if (cwd != null && cwd.length() > 0) { - resourceSet - .getURIConverter() - .getURIMap() - .put(fileURI, - URI.createURI((cwdURI.toString() + "/" + fileURI - .toString()).replaceAll("/+", "/"))); - } - - try { - resource = resourceSet.getResource(fileURI, true); - resource.load(Collections.EMPTY_MAP); - } catch (RuntimeException e) { - return null; - } catch (IOException io) { - return null; - } - - return resource.getContents().get(0); - } - - private static URI normalizeURI(URI path) { - if (path.isFile()) { - return URI.createURI(path.toString().replaceAll("\\\\", "/")); - } - return path; - } - private void validateEnumerationValue(String enumeratorValue, - ValidationMessageAcceptor messageAcceptor, FEnumerator fEnumerator) { - String value = enumeratorValue; - if (value.length() == 0) { - acceptWarning("Missing value!", fEnumerator, - FrancaPackage.Literals.FENUMERATOR__VALUE, -1, messageAcceptor); - return; - } - - if (value.length() == 1) { - if (48 > (int) value.charAt(0) || (int) value.charAt(0) > 57) { - acceptWarning("Not a valid number!", - fEnumerator, FrancaPackage.Literals.FENUMERATOR__VALUE, - -1, messageAcceptor); - return; - } - } - - if (value.length() > 2) { - if (value.charAt(0) == '0') { - // binary - if (value.charAt(1) == 'b') { - for (int i = 2; i < value.length(); i++) { - if (value.charAt(i) != '0' && value.charAt(i) != '1') { - acceptWarning( - "Not a valid number! Should be binary", - fEnumerator, - FrancaPackage.Literals.FENUMERATOR__VALUE, - -1, messageAcceptor); - return; - } - } - return; - } - // hex - if (value.charAt(1) == 'x') { - for (int i = 2; i < value.length(); i++) { - if ((48 > (int) value.charAt(i) || (int) value - .charAt(i) > 57) - && (97 > (int) value.charAt(i) || (int) value - .charAt(i) > 102)) { - acceptWarning( - "Not a valid number! Should be hexadecimal", - fEnumerator, - FrancaPackage.Literals.FENUMERATOR__VALUE, - -1, messageAcceptor); - return; - } - } - return; - } - } - } - if (value.charAt(0) == '0') { - // oct - for (int i = 1; i < value.length(); i++) { - if (48 > (int) value.charAt(i) || (int) value.charAt(i) > 55) { - acceptWarning( - "Not a valid number! Should be octal", - fEnumerator, - FrancaPackage.Literals.FENUMERATOR__VALUE, - -1, messageAcceptor); - return; - } - } - return; - } - // dec - for (int i = 0; i < value.length(); i++) { - if (48 > (int) value.charAt(i) || (int) value.charAt(i) > 57) { - acceptWarning( - "Not a valid number! Should be decimal", fEnumerator, - FrancaPackage.Literals.FENUMERATOR__VALUE, -1, messageAcceptor); - return; - } - } - } - private void validateName(String name, - ValidationMessageAcceptor messageAcceptor, EObject eObject) { - if (cppKeyWords.keyWords.contains(name)) { - acceptError( - "Name " + name + " is a keyword in c++", eObject, FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, - messageAcceptor); - return; - } - if (eObject instanceof FTypeCollection) { - if (name.indexOf(".") != -1) { - acceptError("Name may not contain '.'", - eObject, FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, messageAcceptor); - } - } - } - private void validateMapKey(FMapType m, ValidationMessageAcceptor messageAcceptor) { - if (cycleDetector.hasCycle(m)) { - return; - } - - FTypeRef key = m.getKeyType(); - if (isTypeAcceptableAsMapKey(key)) { - return; - } - - while (key.getDerived() instanceof FTypeDef) { - key = ((FTypeDef) key.getDerived()).getActualType(); - - if (isTypeAcceptableAsMapKey(key)) { - return; - } - } - - acceptError("Key type has to be an primitive type!", m, FrancaPackage.Literals.FMAP_TYPE__KEY_TYPE, -1, messageAcceptor); - } - private boolean isTypeAcceptableAsMapKey(FTypeRef typeRef) { - boolean accepted = false; - - if (!typeRef.getPredefined().toString().equals("undefined")) { - accepted = true; // basic types are ok - } else if (typeRef.getDerived() instanceof FEnumerationType) { - accepted = true; // enums are also ok - } - - return accepted; - } - - private void acceptError(String message, EObject object, EStructuralFeature feature, int index, ValidationMessageAcceptor messageAcceptor){ - messageAcceptor.acceptError("CommonAPI validation: "+message, object, feature, index, null); - } - private void acceptWarning(String message, EObject object, EStructuralFeature feature, int index, ValidationMessageAcceptor messageAcceptor){ - messageAcceptor.acceptWarning("CommonAPI validation: "+message, object, feature, index, null); - } -} diff --git a/org.genivi.commonapi.core.validator/src/org/genivi/commonapi/core/validator/Triple.java b/org.genivi.commonapi.core.validator/src/org/genivi/commonapi/core/validator/Triple.java deleted file mode 100644 index cbe02f1..0000000 --- a/org.genivi.commonapi.core.validator/src/org/genivi/commonapi/core/validator/Triple.java +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (C) 2013 BMW Group - * Author: Manfred Bathelt (manfred.bathelt@bmw.de) - * Author: Juergen Gehring (juergen.gehring@bmw.de) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package org.genivi.commonapi.core.validator; - -public class Triple<Package, TypeCollectionList, InterfaceList> { - - public final Package packageName; - public final TypeCollectionList typeCollectionList; - public final InterfaceList interfaceList; - - public Triple(Package packageName, TypeCollectionList typeCollectionList, - InterfaceList interfaceList) { - this.packageName = packageName; - this.interfaceList = interfaceList; - this.typeCollectionList = typeCollectionList; - } - -}
\ No newline at end of file diff --git a/org.genivi.commonapi.core.validator/src/org/genivi/commonapi/core/validator/ValidatorCore.java b/org.genivi.commonapi.core.validator/src/org/genivi/commonapi/core/validator/ValidatorCore.java new file mode 100644 index 0000000..9487df2 --- /dev/null +++ b/org.genivi.commonapi.core.validator/src/org/genivi/commonapi/core/validator/ValidatorCore.java @@ -0,0 +1,407 @@ +/* Copyright (C) 2013 BMW Group + * Author: Manfred Bathelt (manfred.bathelt@bmw.de) + * Author: Juergen Gehring (juergen.gehring@bmw.de) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.genivi.commonapi.core.validator; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map.Entry; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.xtext.validation.ValidationMessageAcceptor; +import org.franca.core.dsl.validation.IFrancaExternalValidator; +import org.franca.core.franca.FArgument; +import org.franca.core.franca.FAttribute; +import org.franca.core.franca.FBroadcast; +import org.franca.core.franca.FEnumerationType; +import org.franca.core.franca.FEnumerator; +import org.franca.core.franca.FField; +import org.franca.core.franca.FInterface; +import org.franca.core.franca.FMethod; +import org.franca.core.franca.FModel; +import org.franca.core.franca.FStructType; +import org.franca.core.franca.FType; +import org.franca.core.franca.FTypeCollection; +import org.franca.core.franca.FrancaPackage; +import org.franca.core.franca.Import; + +public class ValidatorCore implements IFrancaExternalValidator { + + private CppKeywords cppKeywords = new CppKeywords(); + private HashMap<String, HashSet<String>> importList = new HashMap<String, HashSet<String>>(); + private Boolean hasChanged = false; + private ResourceSet resourceSet; + + @Override + public void validateModel(FModel model, + ValidationMessageAcceptor messageAcceptor) { + resourceSet = new ResourceSetImpl(); + Resource res = model.eResource(); + final Path platformPath = new Path(res.getURI().toPlatformString(true)); + final IFile file = ResourcesPlugin.getWorkspace().getRoot() + .getFile(platformPath); + IPath filePath = file.getLocation(); + String cwd = filePath.removeLastSegments(1).toString(); + validateImport(model, messageAcceptor, file, filePath, cwd); + List<String> interfaceTypecollectionNames = new ArrayList<String>(); + for (FTypeCollection fTypeCollection : model.getTypeCollections()) { + interfaceTypecollectionNames.add(fTypeCollection.getName()); + } + HashMap<FInterface, EList<FInterface>> managedInterfaces = new HashMap<FInterface, EList<FInterface>>(); + for (FInterface fInterface : model.getInterfaces()) { + interfaceTypecollectionNames.add(fInterface.getName()); + managedInterfaces + .put(fInterface, fInterface.getManagedInterfaces()); + } + + for (FTypeCollection fTypeCollection : model.getTypeCollections()) { + validateTypeCollectionName(messageAcceptor, + interfaceTypecollectionNames, fTypeCollection); + validateTypeCollectionElements(messageAcceptor, fTypeCollection); + } + + for (FInterface fInterface : model.getInterfaces()) { + validateTypeCollectionName(messageAcceptor, + interfaceTypecollectionNames, fInterface); + validateManagedInterfaces(messageAcceptor, fInterface); + validateFInterfaceElements(messageAcceptor, fInterface); + } + + interfaceTypecollectionNames.clear(); + importList.clear(); + } + + private void validateManagedInterfaces( + ValidationMessageAcceptor messageAcceptor, FInterface fInterface) { + ArrayList<FInterface> startI = new ArrayList<FInterface>(); + int index = 0; + startI.add(fInterface); + ArrayList<FInterface> managedList = new ArrayList<FInterface>(); + for (FInterface managedInterface : fInterface.getManagedInterfaces()) { + findCyclicManagedInterfaces(managedInterface, startI, fInterface, + messageAcceptor, index, false); + if (managedList.contains(managedInterface)) + acceptError("Interface " + managedInterface.getName() + + " is already managed! Delete this equivalent!", + fInterface, + FrancaPackage.Literals.FINTERFACE__MANAGED_INTERFACES, + index, messageAcceptor); + managedList.add(managedInterface); + index++; + } + } + + private void findCyclicManagedInterfaces(FInterface rekInterface, + ArrayList<FInterface> interfaceList, FInterface fInterface, + ValidationMessageAcceptor messageAcceptor, int index, + boolean managed) { + if (interfaceList.contains(rekInterface)) { + String errorString = ""; + for (FInterface a : interfaceList) { + errorString = errorString + a.getName() + " -> "; + } + errorString = errorString + rekInterface.getName(); + if (rekInterface.equals(fInterface)) { + acceptError("Interface " + fInterface.getName() + + " manages itself: " + errorString, fInterface, + FrancaPackage.Literals.FINTERFACE__MANAGED_INTERFACES, + index, messageAcceptor); + } else { + // if(!managed){ + acceptError("Cycle detected: " + errorString, fInterface, + FrancaPackage.Literals.FINTERFACE__MANAGED_INTERFACES, + index, messageAcceptor); + // } + } + // acceptError("Cycle detected: " +errorString, fInterface, + // FrancaPackage.Literals.FINTERFACE__MANAGED_INTERFACES, index, + // messageAcceptor); + } else { + interfaceList.add(rekInterface); + for (FInterface nextInterface : rekInterface.getManagedInterfaces()) { + findCyclicManagedInterfaces(nextInterface, interfaceList, + fInterface, messageAcceptor, index, managed); + } + if (rekInterface.getBase() != null) + findCyclicManagedInterfaces(rekInterface.getBase(), + interfaceList, fInterface, messageAcceptor, index, true); + interfaceList.remove(rekInterface); + } + } + + private void validateImport(FModel model, + ValidationMessageAcceptor messageAcceptor, final IFile file, + IPath filePath, String cwd) { + HashSet<String> importedFiles = new HashSet<String>(); + ArrayList<String> importUriAndNamesspace = new ArrayList<String>(); + for (Import fImport : model.getImports()) { + + if (importUriAndNamesspace.contains(fImport.getImportURI() + "," + + fImport.getImportedNamespace())) + acceptWarning("Multiple times imported!", fImport, + FrancaPackage.Literals.IMPORT__IMPORT_URI, -1, + messageAcceptor); + if (fImport.getImportURI().equals(file.getName())) { + acceptError("Class may not import itself!", fImport, + FrancaPackage.Literals.IMPORT__IMPORT_URI, -1, + messageAcceptor); + } else { + Path absoluteImportPath = new Path(fImport.getImportURI()); + if (!absoluteImportPath.isAbsolute()) { + absoluteImportPath = new Path(cwd + "/" + + fImport.getImportURI()); + importedFiles.add(absoluteImportPath.toString()); + } else { + importedFiles.add(absoluteImportPath.toString() + .replaceFirst(absoluteImportPath.getDevice() + "/", + "")); + } + + } + importUriAndNamesspace.add(fImport.getImportURI() + "," + + fImport.getImportedNamespace()); + } + importUriAndNamesspace.clear(); + importList.put(filePath.toString(), importedFiles); + + ArrayList<String> start = new ArrayList<String>(); + try { + importList = buildImportList(importList); + } catch (NullPointerException e) { + } + start.add(filePath.toString()); + for (Import fImport : model.getImports()) { + Path importPath = new Path(fImport.getImportURI()); + if (importPath.isAbsolute()) { + findCyclicImports( + importPath.toString().replaceFirst( + importPath.getDevice() + "/", ""), + filePath.toString(), start, fImport, messageAcceptor); + } else { + importPath = new Path(cwd + "/" + fImport.getImportURI()); + findCyclicImports(importPath.toString(), filePath.toString(), + start, fImport, messageAcceptor); + } + } + start.clear(); + } + + private HashMap<String, HashSet<String>> buildImportList( + HashMap<String, HashSet<String>> rekImportList) { + HashMap<String, HashSet<String>> helpMap = new HashMap<String, HashSet<String>>(); + for (Entry<String, HashSet<String>> entry : rekImportList.entrySet()) { + for (String importedPath : entry.getValue()) { + if (!rekImportList.containsKey(importedPath)) { + hasChanged = true; + HashSet<String> importedFIDL = new HashSet<String>(); + EObject resource = null; + resource = buildResource( + importedPath.substring( + importedPath.lastIndexOf("/") + 1, + importedPath.length()), + "file:/" + + importedPath.substring(0, + importedPath.lastIndexOf("/") + 1)); + for (EObject imp : resource.eContents()) { + if (imp instanceof Import) { + Path importImportedPath = new Path( + ((Import) imp).getImportURI()); + if (importImportedPath.isAbsolute()) { + importedFIDL.add(importImportedPath.toString() + .replaceFirst( + importImportedPath.getDevice() + + "/", "")); + } else { + importImportedPath = new Path( + importedPath.substring(0, + importedPath.lastIndexOf("/")) + + "/" + + ((Import) imp).getImportURI()); + importedFIDL.add(importImportedPath.toString()); + } + } + } + helpMap.put(importedPath, importedFIDL); + } + } + } + if (hasChanged) { + hasChanged = false; + helpMap.putAll(rekImportList); + return buildImportList(helpMap); + } else { + return rekImportList; + } + } + + private EObject buildResource(String filename, String cwd) { + URI fileURI = normalizeURI(URI.createURI(filename)); + URI cwdURI = normalizeURI(URI.createURI(cwd)); + Resource resource = null; + + if (cwd != null && cwd.length() > 0) { + resourceSet + .getURIConverter() + .getURIMap() + .put(fileURI, + URI.createURI((cwdURI.toString() + "/" + fileURI + .toString()).replaceAll("/+", "/"))); + } + + try { + resource = resourceSet.getResource(fileURI, true); + resource.load(Collections.EMPTY_MAP); + } catch (RuntimeException e) { + return null; + } catch (IOException io) { + return null; + } + + return resource.getContents().get(0); + } + + private static URI normalizeURI(URI path) { + if (path.isFile()) { + return URI.createURI(path.toString().replaceAll("\\\\", "/")); + } + return path; + } + + private void validateTypeCollectionName( + ValidationMessageAcceptor messageAcceptor, + List<String> interfaceTypecollectionNames, + FTypeCollection fTypeCollection) { + validateName(fTypeCollection.getName(), messageAcceptor, + fTypeCollection); + if (interfaceTypecollectionNames.indexOf(fTypeCollection.getName()) != interfaceTypecollectionNames + .lastIndexOf(fTypeCollection.getName())) { + acceptError("Name " + fTypeCollection.getName() + + " isn't unique in this file!", fTypeCollection, + FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, + messageAcceptor); + } + } + + private void findCyclicImports(String filePath, String prevFilePath, + ArrayList<String> cyclicList, Import imp, + ValidationMessageAcceptor messageAcceptor) { + if (cyclicList.contains(filePath)) { + String errorString = ""; + for (String impString : cyclicList) { + errorString = errorString + impString + "->"; + } + if (prevFilePath.equals(filePath)) { + if (cyclicList.size() > 1) + acceptError("Last file imports itself!: " + errorString + + filePath, imp, + FrancaPackage.Literals.IMPORT__IMPORT_URI, -1, + messageAcceptor); + return; + } else { + acceptError("Cyclic Imports: " + errorString + filePath, imp, + FrancaPackage.Literals.IMPORT__IMPORT_URI, -1, + messageAcceptor); + return; + } + } else { + cyclicList.add(filePath); + if (importList.containsKey(filePath)) { + for (String importPath : importList.get(filePath)) { + findCyclicImports(importPath, filePath, cyclicList, imp, + messageAcceptor); + } + } + cyclicList.remove(cyclicList.size() - 1); + } + } + + private void validateTypeCollectionElements( + ValidationMessageAcceptor messageAcceptor, + FTypeCollection fTypeCollection) { + for (FType fType : fTypeCollection.getTypes()) { + validateName(fType.getName(), messageAcceptor, fType); + if (fType instanceof FStructType) { + for (FField fField : ((FStructType) fType).getElements()) { + validateName(fField.getName(), messageAcceptor, fField); + } + } + + if (fType instanceof FEnumerationType) { + for (FEnumerator fEnumerator : ((FEnumerationType) fType) + .getEnumerators()) { + validateName(fEnumerator.getName(), messageAcceptor, + fEnumerator); + } + } + } + } + + private void validateFInterfaceElements( + ValidationMessageAcceptor messageAcceptor, FInterface fInterface) { + if (fInterface.getVersion() == null) + acceptError("Missing version! Add: version(major int minor int)", + fInterface, FrancaPackage.Literals.FMODEL_ELEMENT__NAME, + -1, messageAcceptor); + + for (FAttribute att : fInterface.getAttributes()) { + validateName(att.getName(), messageAcceptor, att); + } + for (FBroadcast fBroadcast : fInterface.getBroadcasts()) { + validateName(fBroadcast.getName(), messageAcceptor, fBroadcast); + for (FArgument out : fBroadcast.getOutArgs()) { + validateName(out.getName(), messageAcceptor, out); + } + } + for (FMethod fMethod : fInterface.getMethods()) { + validateName(fMethod.getName(), messageAcceptor, fMethod); + for (FArgument out : fMethod.getOutArgs()) { + validateName(out.getName(), messageAcceptor, out); + } + for (FArgument in : fMethod.getInArgs()) { + validateName(in.getName(), messageAcceptor, in); + } + } + } + + private void validateName(String name, + ValidationMessageAcceptor messageAcceptor, EObject eObject) { + if (cppKeywords.keyWords.contains(name)) { + acceptError("Name " + name + " is a keyword in c++", eObject, + FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, + messageAcceptor); + return; + } + } + + private void acceptError(String message, EObject object, + EStructuralFeature feature, int index, + ValidationMessageAcceptor messageAcceptor) { + messageAcceptor.acceptError("Core validation: " + message, object, + feature, index, null); + } + + private void acceptWarning(String message, EObject object, + EStructuralFeature feature, int index, + ValidationMessageAcceptor messageAcceptor) { + messageAcceptor.acceptWarning("Core validation: " + message, object, + feature, index, null); + } +} |