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

org.modelcc.io.java.checker.OptionalChecker 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.Iterator;

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 optional values
 */
public class OptionalChecker extends JavaModelChecker
{	
	public OptionalChecker (JavaModelReader reader)
	{
		super(reader);
	}
	
	@Override
	public void check(JavaLanguageMetadata metadata) 
	{
    	for (JavaLanguageClass pe: metadata.getJavaElements()) {
    		for (int i = 0;i < pe.getMembers().size();i++) {
    			LanguageMember em = (LanguageMember) pe.getMember(i);
    			if (em.isOptional()) {
    				if (!MemberCollection.class.isAssignableFrom(em.getClass())) {
    					JavaLanguageClass pe2 = metadata.getClassElement(em.getElementClass());
    					boolean allopt = true;
    					if (pe2.getMembers().isEmpty())
    						allopt = false;
    					for (Iterator itec2 = pe2.getMembers().iterator();itec2.hasNext() && allopt;) {
    						LanguageMember em2 = itec2.next();
    						if (!em2.isOptional())
    							allopt = false;
    					}
    				}
    			}
    		}
    	}		
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy