Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright Technophobia Ltd 2012
*
* This file is part of Substeps.
*
* Substeps is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Substeps is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Substeps. If not, see .
*/
package com.technophobia.substeps.runner.syntax;
import java.io.File;
import java.util.Collections;
import java.util.List;
import com.technophobia.substeps.model.SubSteps;
import com.technophobia.substeps.model.Syntax;
import com.technophobia.substeps.scanner.ClasspathScanner;
/**
*
* @author imoore
*
*/
public final class SyntaxBuilder {
private SyntaxBuilder() {
}
public static List> getStepImplementationClasses(final ClassLoader classLoader, final String[] classpath) {
final ClasspathScanner cpScanner = new ClasspathScanner();
final List> implClassList = cpScanner.getClassesWithAnnotation(SubSteps.StepImplementations.class,
classLoader, classpath);
return implClassList;
}
public static Syntax buildSyntax(final List> stepImplementationClasses, final File subStepsFile) {
return buildSyntax(stepImplementationClasses, subStepsFile, true, null);
}
public static Syntax buildSyntax(final List> stepImplementationClasses, final File subStepsFile,
final boolean strict, final String[] nonStrictKeywordPrecedence) {
return buildSyntax(stepImplementationClasses, subStepsFile, strict, nonStrictKeywordPrecedence,
new ClassAnalyser());
}
public static Syntax buildSyntax(final List> stepImplementationClasses, final File subStepsFile,
final boolean strict, final String[] nonStrictKeywordPrecedence, final ClassAnalyser classAnalyser) {
return buildSyntax(stepImplementationClasses, subStepsFile, strict, nonStrictKeywordPrecedence, classAnalyser,
true);
}
public static Syntax buildSyntax(final List> stepImplementationClasses, final File subStepsFile,
final boolean strict, final String[] nonStrictKeywordPrecedence, final ClassAnalyser classAnalyser,
final boolean failOnDuplicateEntries) {
return buildSyntax(stepImplementationClasses, subStepsFile, strict, nonStrictKeywordPrecedence, classAnalyser,
failOnDuplicateEntries, new DefaultSyntaxErrorReporter());
}
public static Syntax buildSyntax(final List> stepImplementationClasses, final File subStepsFile,
final boolean strict, final String[] nonStrictKeywordPrecedence, final ClassAnalyser classAnalyser,
final boolean failOnDuplicateEntries, final SyntaxErrorReporter syntaxErrorReporter) {
final Syntax syntax = buildBaseSyntax(stepImplementationClasses, classAnalyser, failOnDuplicateEntries,
syntaxErrorReporter);
syntax.setStrict(strict, nonStrictKeywordPrecedence);
if (subStepsFile != null) {
final SubStepDefinitionParser subStepParser = new SubStepDefinitionParser(failOnDuplicateEntries,
syntaxErrorReporter);
syntax.setSubStepsMap(subStepParser.loadSubSteps(subStepsFile));
}
return syntax;
}
private static Syntax buildBaseSyntax(final List> stepImplementationClasses,
final ClassAnalyser classAnalyser, final boolean failOnDuplicateEntries,
final SyntaxErrorReporter syntaxErrorReporter) {
// step implementations (arranged by StepDefinition, ie the annotation)
// +
// sub step definitions
final Syntax syntax = new Syntax(syntaxErrorReporter);
syntax.setFailOnDuplicateStepImplementations(failOnDuplicateEntries);
final List> implClassList;
if (stepImplementationClasses != null) {
implClassList = stepImplementationClasses;
} else {
implClassList = Collections.emptyList();
}
for (final Class> implClass : implClassList) {
classAnalyser.analyseClass(implClass, syntax);
}
return syntax;
}
}