All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.modelcc.io.java.checker.ReferenceChecker Maven / Gradle / Ivy

Go to download

ModelCC is a model-based parser generator (a.k.a. compiler compiler) that decouples language specification from language processing, avoiding some of the problems caused by grammar-driven parser generators. ModelCC receives a conceptual model as input, along with constraints that annotate it. It is then able to create a parser for the desired textual language and the generated parser fully automates the instantiation of the language conceptual model. ModelCC also includes a built-in reference resolution mechanism that results in abstract syntax graphs, rather than mere abstract syntax trees.

The newest version!
package org.modelcc.io.java.checker;


import java.util.logging.Level;

import org.modelcc.io.java.JavaModelReader;
import org.modelcc.io.java.JavaModelChecker;
import org.modelcc.io.java.JavaLanguageMetadata;
import org.modelcc.io.java.JavaLanguageClass;
import org.modelcc.language.metamodel.MemberCollection;
import org.modelcc.language.metamodel.LanguageMember;

/**
 * Checks references
 */
public class ReferenceChecker extends JavaModelChecker 
{	
	public ReferenceChecker (JavaModelReader reader)
	{
		super(reader);
	}
	
	@Override
	public void check(JavaLanguageMetadata metadata) 
	{
    	for (JavaLanguageClass e: metadata.getJavaElements()) {
    		JavaLanguageClass pe = (JavaLanguageClass) e;
    		for (int i = 0;i < pe.getMembers().size();i++) {
    			LanguageMember em = pe.getMember(i);
    			if (em.isReference()) {
    				JavaLanguageClass peref = (JavaLanguageClass) metadata.getClassElement(em.getElementClass());
    				if (peref.getKeyMembers().isEmpty()) {
    					if (!MemberCollection.class.isAssignableFrom(em.getClass())) {
    						pe.getMembers().set(i,new LanguageMember(em.getID(),em.getElementClass(),em.isOptional(),em.isKey(),false,em.getPrefix(),em.getSuffix(),em.getSeparator(),em.getEvaluator()));
    						log(Level.SEVERE, "In field \"{0}\" of class \"{1}\": This field is annotated with @Reference but its field class has no @ID members.", new Object[]{em.getID(), pe.getElementClass().getCanonicalName()});
    					} else {
    						MemberCollection mem = (MemberCollection)em;
    						pe.getMembers().set(i,new MemberCollection(em.getID(),em.getElementClass(),em.isOptional(),em.isKey(),false,em.getPrefix(),em.getSuffix(),em.getSeparator(),mem.getCollection(),mem.getMinimumMultiplicity(),mem.getMaximumMultiplicity(),em.getEvaluator()));
    						log(Level.SEVERE, "In field \"{0}\" of class \"{1}\": This field is annotated with @Reference but its field class has no @ID members.", new Object[]{em.getID(), pe.getElementClass().getCanonicalName()});
    					}
    				}
    			}
    		}
    	}
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy