88import com .intellij .psi .xml .XmlAttribute ;
99import com .intellij .psi .xml .XmlFile ;
1010import com .intellij .psi .xml .XmlTag ;
11+ import com .jetbrains .php .config .PhpLanguageLevel ;
1112import com .jetbrains .php .lang .documentation .phpdoc .parser .PhpDocElementTypes ;
1213import com .jetbrains .php .lang .documentation .phpdoc .psi .PhpDocComment ;
1314import com .jetbrains .php .lang .documentation .phpdoc .psi .tags .PhpDocTag ;
1415import com .jetbrains .php .lang .psi .PhpFile ;
1516import com .jetbrains .php .lang .psi .elements .PhpClass ;
1617import com .jetbrains .php .lang .psi .elements .PhpPsiElement ;
18+ import com .jetbrains .php .refactoring .PhpNameUtil ;
1719import de .espend .idea .php .annotation .util .AnnotationUtil ;
1820import fr .adrienbrault .idea .symfony2plugin .stubs .indexes .visitor .AnnotationElementWalkingVisitor ;
1921import fr .adrienbrault .idea .symfony2plugin .stubs .indexes .visitor .AttributeElementWalkingVisitor ;
@@ -192,7 +194,11 @@ private static Collection<Pair<String, String>> getClassRepositoryPair(@NotNull
192194 // we are indexing all yaml files for prefilter on path,
193195 // if false if check on parse
194196 String name = yamlFile .getName ().toLowerCase ();
195- boolean iAmMetadataFile = name .contains (".odm." ) || name .contains (".orm." ) || name .contains (".mongodb." ) || name .contains (".couchdb." );
197+ boolean iAmMetadataFile = name .contains (".odm." )
198+ || name .contains (".orm." )
199+ || name .contains (".dcm." )
200+ || name .contains (".mongodb." )
201+ || name .contains (".couchdb." );
196202
197203 YAMLDocument yamlDocument = PsiTreeUtil .getChildOfType (yamlFile , YAMLDocument .class );
198204 if (yamlDocument == null ) {
@@ -205,39 +211,64 @@ private static Collection<Pair<String, String>> getClassRepositoryPair(@NotNull
205211 }
206212
207213 Collection <Pair <String , String >> pairs = new ArrayList <>();
208-
209214 for (YAMLKeyValue yamlKey : ((YAMLMapping ) topLevelValue ).getKeyValues ()) {
210215 String keyText = yamlKey .getKeyText ();
211- if (StringUtils .isBlank (keyText )) {
216+ if (StringUtils .isBlank (keyText ) || ! PhpNameUtil . isValidNamespaceFullName ( keyText , true , PhpLanguageLevel . current ( yamlFile . getProject ()) )) {
212217 continue ;
213218 }
214219
215- String repositoryClassValue = YamlHelper .getYamlKeyValueAsString (yamlKey , "repositoryClass" );
220+ boolean isValidEntry = iAmMetadataFile ;
221+
222+ if (!isValidEntry ) {
223+ @ Nullable String type = YamlHelper .getYamlKeyValueAsString (yamlKey , "type" );
224+ if ("entity" .equalsIgnoreCase (type ) || "embeddable" .equalsIgnoreCase (type ) || "mappedSuperclass" .equalsIgnoreCase (type )) {
225+ isValidEntry = YamlHelper .getYamlKeyValue (yamlKey , "fields" ) != null
226+ || YamlHelper .getYamlKeyValue (yamlKey , "repositoryClass" ) != null
227+ || YamlHelper .getYamlKeyValue (yamlKey , "id" ) != null
228+ || YamlHelper .getYamlKeyValue (yamlKey , "embedded" ) != null
229+ || YamlHelper .getYamlKeyValue (yamlKey , "associationOverride" ) != null
230+ || YamlHelper .getYamlKeyValue (yamlKey , "manyToOne" ) != null
231+ || YamlHelper .getYamlKeyValue (yamlKey , "manyToMany" ) != null
232+ || YamlHelper .getYamlKeyValue (yamlKey , "oneToMany" ) != null
233+ || YamlHelper .getYamlKeyValue (yamlKey , "oneToOne" ) != null ;
234+ }
216235
217- // check blank condition
218- String repositoryClass = null ;
219- if (StringUtils .isNotBlank (repositoryClassValue )) {
220- repositoryClass = repositoryClassValue ;
221- }
236+ if (!isValidEntry ) {
237+ @ Nullable String db = YamlHelper .getYamlKeyValueAsString (yamlKey , "db" );
238+ @ Nullable String typeOdm = YamlHelper .getYamlKeyValueAsString (yamlKey , "type" );
239+ if ("documents" .equalsIgnoreCase (db ) || "embeddable" .equalsIgnoreCase (db ) || "mappedSuperclass" .equalsIgnoreCase (db ) || "document" .equalsIgnoreCase (typeOdm )|| "embeddedDocument" .equalsIgnoreCase (typeOdm )) {
240+ isValidEntry = YamlHelper .getYamlKeyValue (yamlKey , "fields" ) != null
241+ || YamlHelper .getYamlKeyValue (yamlKey , "embedOne" ) != null
242+ || YamlHelper .getYamlKeyValue (yamlKey , "embedMany" ) != null
243+ || YamlHelper .getYamlKeyValue (yamlKey , "referenceOne" ) != null
244+ || YamlHelper .getYamlKeyValue (yamlKey , "referenceMany" ) != null
245+ || YamlHelper .getYamlKeyValue (yamlKey , "collection" ) != null
246+ || YamlHelper .getYamlKeyValue (yamlKey , "db" ) != null ;
247+ }
248+ }
222249
223- // fine repositoryClass exists a valid metadata file
224- if (!iAmMetadataFile && repositoryClass != null ) {
225- iAmMetadataFile = true ;
250+ if (!isValidEntry ) {
251+ @ Nullable String db = YamlHelper .getYamlKeyValueAsString (yamlKey , "db" );
252+ if ("documents" .equalsIgnoreCase (db ) || "embeddable" .equalsIgnoreCase (db ) || "mappedSuperclass" .equalsIgnoreCase (db )) {
253+ isValidEntry = YamlHelper .getYamlKeyValue (yamlKey , "fields" ) != null
254+ || YamlHelper .getYamlKeyValue (yamlKey , "embedOne" ) != null
255+ || YamlHelper .getYamlKeyValue (yamlKey , "embedMany" ) != null
256+ || YamlHelper .getYamlKeyValue (yamlKey , "referenceOne" ) != null
257+ || YamlHelper .getYamlKeyValue (yamlKey , "referenceMany" ) != null ;
258+ }
259+ }
226260 }
227261
228- // currently not valid metadata file find valid keys
229- // else we are not allowed to store values
230- if (!iAmMetadataFile ) {
231- Set <String > keySet = YamlHelper .getKeySet (yamlKey );
232- if (keySet == null ) {
233- continue ;
234- }
262+ if (!isValidEntry ) {
263+ continue ;
264+ }
235265
236- if (!(keySet .contains ("fields" ) || keySet .contains ("id" ) || keySet .contains ("collection" ) || keySet .contains ("db" ) || keySet .contains ("indexes" ))) {
237- continue ;
238- }
266+ String repositoryClassValue = YamlHelper .getYamlKeyValueAsString (yamlKey , "repositoryClass" );
239267
240- iAmMetadataFile = true ;
268+ // check blank condition
269+ String repositoryClass = null ;
270+ if (StringUtils .isNotBlank (repositoryClassValue )) {
271+ repositoryClass = repositoryClassValue ;
241272 }
242273
243274 pairs .add (Pair .create (keyText , repositoryClass ));
0 commit comments