/** * Creates a new instance of {@link PunctDescription} for the given language. * * @param resourceDir path to the folder with the language resources * @param lang the language * @param macrosMap a map of macro names to regular expression strings * @throws IOException if there is an error when reading the configuration */ public PunctDescription(String resourceDir, String lang, Map<String, String> macrosMap) throws IOException { super.setDefinitionsMap(new HashMap<String, RegExp>()); super.setRulesMap(new HashMap<String, RegExp>()); super.setRegExpMap(new HashMap<RegExp, String>()); Path punctDescrPath = Paths.get(resourceDir).resolve(lang + PUNCT_DESCR); BufferedReader in = new BufferedReader( new InputStreamReader(FileTools.openResourceFileAsStream(punctDescrPath), "utf-8")); // read config file to definitions start readToDefinitions(in); // read definitions Map<String, String> defsMap = new HashMap<>(); super.loadDefinitions(in, macrosMap, defsMap); // when loadDefinitions returns the reader has reached the rules section; // read rules super.loadRules(in, defsMap, macrosMap); getRulesMap().put(ALL_RULE, createAllRule(defsMap)); in.close(); }
private void createStory(Description description) { if (description.getAnnotation(Story.class) != null) createStoryFromAnnotation(description.getAnnotation(Story.class)); else { createStoryFromDescription(description.getDisplayName()); } }
private boolean isItSingleScenario(Description description) { try { return description.getMethodName() != null; } catch (NoSuchMethodError e) { // junit 4.5 return description.getDisplayName() != null; } }
/** * Returns the description of this document. * * @return the description ({@code null} means no description was set, whereas the empty-string * means the description is empty) */ public String getDescription() { Description description = getExtension(Description.class); if (description == null) { return null; } return description.getValue() == null ? "" : description.getValue(); }
public static <T> void assertMismatchDescription( String expected, Matcher<? super T> matcher, T arg) { assertFalse("Precondtion: Matcher should not match item.", matcher.matches(arg)); Description description = new StringDescription(); matcher.describeMismatch(arg, description); assertEquals("Expected mismatch description", expected, description.toString().trim()); }
private String createScenarioNameFromTestMethodName( Description description, Parameters parametersAnnotation) { try { return decamelise(description.getMethodName()); } catch (NoSuchMethodError e) { // junit 4.5 return decamelise(description.getDisplayName()); } }
@Override public void describeTo(Description description) { description.appendText("a Complex number having "); reMatcher.describeTo(description); description.appendText(" as real part and "); imMatcher.describeTo(description); description.appendText(" as imaginary part"); }
/** @return the full description string for the specified map */ public String getFullDescription(String map) { Description desc = getDescriptionItem(map); if (desc != null) { return desc.getDescription(); } else { return null; } }
private Description findChildForParams(Statement methodInvoker, Description methodDescription) { for (Description child : methodDescription.getChildren()) { InvokeParameterisedMethod parameterisedInvoker = findParameterisedMethodInvokerInChain(methodInvoker); /* if (child.getMethodName().startsWith(parameterisedInvoker.getParamsAsString())) return child; */ int paramsSetInx = parameterisedInvoker.getParamsSetIdx() - 1; if (child.getMethodName().endsWith("[" + paramsSetInx + "]")) return child; } return null; }
/** * @return the item tag for the specified map if the description was specified as "<item tag> main * description". Otherwise null is returned. */ public String getItemTag(String map) { Description desc = getDescriptionItem(map); if (desc != null) { String dstr = desc.getDescription(); if (dstr.startsWith("<") && (dstr.indexOf('>') > -1)) { return dstr.substring(1, dstr.indexOf('>')); } } return null; }
private static LinkedHashMap<String, Prop> createProps() { Field[] fs = Configuration.class.getDeclaredFields(); LinkedHashMap<String, Prop> res = new LinkedHashMap<String, Prop>(); for (Field f : fs) if (!Modifier.isStatic(f.getModifiers())) { Description annotation = f.getAnnotation(Description.class); if (annotation != null) { String name = f.getName().replace('_', '.'); res.put(name, new Prop(name, annotation.value(), f)); } } return res; }
/** @return the description instance for the specified map */ private Description getDescriptionItem(String map) { Iterator desciter = desclist.iterator(); Description desc; while (desciter.hasNext()) { desc = (Description) desciter.next(); if (desc.getMap().equals(map)) { return desc; } } return null; }
/** * @return the description string for the specified map. If the description string was specified * as "<item tag> main description" then only the main description is returned. */ public String getDescription(String map) { Description desc = getDescriptionItem(map); if (desc != null) { String dstr = desc.getDescription(); if (dstr.startsWith("<") && (dstr.indexOf('>') > -1)) { return dstr.substring(dstr.indexOf('>') + 1).trim(); } else { return desc.getDescription().trim(); } } else { return null; } }
ParameterExtractor(TypeCaster caster, Class<?> type, Parameter param, Description description) { this.caster = caster; this.type = type; this.name = param.name(); this.optional = param.optional(); this.description = description == null ? "" : description.value(); }
public static void parse() { Class classt = ITCAST.class; /** 类上的注解 */ if (classt.isAnnotationPresent(Name.class)) { Name name = (Name) classt.getAnnotation(Name.class); System.out.println(name.value()); } Method[] methods = classt.getMethods(); for (Method method : methods) { if (method.isAnnotationPresent(Description.class)) { Description description = (Description) method.getAnnotation(Description.class); System.out.println(description.value()); } } }
/** * Validate a set of properties for a description, and return a report. * * @param props the input properties * @param desc the configuration description * @return the validation report */ public static Report validate(final Properties props, final Description desc) { final Report report = new Report(); final List<Property> properties = desc.getProperties(); if (null != properties) { for (final Property property : properties) { final String key = property.getName(); final String value = props.getProperty(key); if (null == value || "".equals(value)) { if (property.isRequired()) { report.errors.put(key, "required"); continue; } } else { // try to validate final Property.Validator validator = property.getValidator(); if (null != validator) { try { if (!validator.isValid(value)) { report.errors.put(key, "Invalid value"); } } catch (ValidationException e) { report.errors.put(key, "Invalid value: " + e.getMessage()); } } } } } return report; }
/** Returns a recursively created XML representation of this <code>Meta</code>. */ public String toString() { StringBuilder buffer = new StringBuilder(); buffer.append("<" + xmltag + ">" + newline); if (null != corpus_id) { buffer.append("\t\t\t" + corpus_id.toString()); } if (null != history) { buffer.append("\t\t\t" + history.toString()); } if (null != format) { buffer.append("\t\t\t" + format.toString()); } if (null != name) { buffer.append("\t\t\t" + name.toString()); } if (null != author) { buffer.append("\t\t\t" + author.toString()); } if (null != date) { buffer.append("\t\t\t" + date.toString()); } if (null != description) { buffer.append("\t\t\t" + description.toString()); } buffer.append("\t\t</" + xmltag + ">" + newline); return buffer.toString(); }
public void register(Description<?> description) { Preconditions.checkNotNull(description); BuildRuleType type = description.getBuildRuleType(); types.put(type.getName(), type); factories.put(type, new DescribedRuleFactory<>(description)); descriptions.put(type, description); }
Description describeMethod() { Object[] params = paramsFromAnnotation(); Description parametrised = Description.createSuiteDescription(method.name()); for (int i = 0; i < params.length; i++) { /* Object paramSet = params[i]; parametrised.addChild(Description.createTestDescription(method.frameworkMethod.getMethod().getDeclaringClass(), Utils.stringify(paramSet, i) + " (" + method.name() + ")", method.frameworkMethod.getAnnotations())); */ parametrised.addChild( Description.createTestDescription( method.frameworkMethod.getMethod().getDeclaringClass(), method.name() + " [" + i + "]", method.frameworkMethod.getAnnotations())); } return parametrised; }
private Description getStepDescription(String step) { for (Description description : currentScenario.getChildren()) { if (!finishedDescriptions.contains(description) && match(step, description)) { return description; } } throw new RuntimeException("Could not find description for: " + step); }
/** * Converts a set of input configuration keys using the description's configuration to property * mapping, or the same input if the description has no mapping */ public static Map<String, String> mapProperties( final Map<String, String> input, final Description desc) { final Map<String, String> mapping = desc.getPropertiesMapping(); if (null == mapping) { return input; } return performMapping(input, mapping, false); }
private int getOptionLength() { Iterator iter = desclist.iterator(); int maxlength = 0; int length; Description desc; while (iter.hasNext()) { desc = (Description) iter.next(); length = 5 + desc.getMap().length() + 2; if (getItemTag(desc.getMap()) != null) { length += 3 + getItemTag(desc.getMap()).length(); } maxlength = Math.max(maxlength, length); } return Math.min(maxlength, MAX_LENGTH); }
private ScenarioModel namedScenario(Description description) { Scenario scenarioAnnotation = description.getAnnotation(Scenario.class); Parameters parametersAnnotation = description.getAnnotation(Parameters.class); String name = null; if (scenarioHasDefinedName(scenarioAnnotation)) name = scenarioAnnotation.value(); else name = createScenarioNameFromTestMethodName(description, parametersAnnotation); if (parametersAnnotation != null && !scenarioAnnotation.pending()) name = name.substring(name.indexOf('(') + 1, name.indexOf(')')) + " (" + description .getMethodName() .substring(0, description.getMethodName().indexOf('(') - 1) + ")"; return ScenarioManager.currentScenario().withName(name).withDescription(description); }
@Override public <T> BuildRule transform( TargetGraph targetGraph, BuildRuleResolver ruleResolver, TargetNode<T> targetNode) throws NoSuchBuildTargetException { BuildRuleFactoryParams ruleFactoryParams = targetNode.getRuleFactoryParams(); Description<T> description = targetNode.getDescription(); T arg = targetNode.getConstructorArg(); // The params used for the Buildable only contain the declared parameters. However, the deps of // the rule include not only those, but also any that were picked up through the deps declared // via a SourcePath. BuildRuleParams params = new BuildRuleParams( targetNode.getBuildTarget(), Suppliers.ofInstance(ruleResolver.requireAllRules(targetNode.getDeclaredDeps())), Suppliers.ofInstance(ruleResolver.requireAllRules(targetNode.getExtraDeps())), ruleFactoryParams.getProjectFilesystem(), targetNode.getCellNames()); return description.createBuildRule(targetGraph, params, ruleResolver, arg); }
/** * Reverses a set of properties mapped using the description's configuration to property mapping, * or the same input if the description has no mapping */ public static Map<String, String> demapProperties( final Map<String, String> input, final Description desc) { final Map<String, String> mapping = desc.getPropertiesMapping(); if (null == mapping) { return input; } final Map<String, String> rev = new HashMap<String, String>(); for (final Map.Entry<String, String> entry : mapping.entrySet()) { rev.put(entry.getValue(), entry.getKey()); } return performMapping(input, rev, true); }
private void fillCat2Funs(final Map<String, FunctionInfo> funs) { for (Entry<String, FunctionInfo> e : funs.entrySet()) { Class<?> funClass = e.getValue().getFunction().getClass(); assert (funClass.getConstructors().length == 1); Constructor<?> cons = funClass.getConstructors()[0]; String name = e.getKey(); String constructorDescription = null; Description consAnno = cons.getAnnotation(Description.class); if (consAnno != null) { constructorDescription = consAnno.description(); } HashMap<Category, ArrayList<SignatureInfo>> cat2sig = new HashMap<>(); int methodCount = e.getValue().signatures.length; for (int i = 0; i < methodCount; i++) { createSigInfo(e, consAnno, cat2sig, i); } for (Category cat : cat2sig.keySet()) { SortedMap<String, AnnotationInfo> m = cat2funs.get(cat); if (m == null) { m = new TreeMap<>(); cat2funs.put(cat, m); } AnnotationInfo aninfo = new AnnotationInfo(); aninfo.name = name; aninfo.constructorDescription = constructorDescription; aninfo.signatureInfos = cat2sig.get(cat).toArray(new SignatureInfo[] {}); m.put(aninfo.name, aninfo); cat2funs.put(cat, m); } } }
/** * @param system * @args args from main() */ private Result runMain(JUnitSystem system, String... args) { system.out().println("JUnit version " + Version.id()); List<Class<?>> classes = new ArrayList<Class<?>>(); List<Failure> missingClasses = new ArrayList<Failure>(); for (String each : args) try { classes.add(Class.forName(each)); } catch (ClassNotFoundException e) { system.out().println("Could not find class: " + each); Description description = Description.createSuiteDescription(each); Failure failure = new Failure(description, e); missingClasses.add(failure); } RunListener listener = new TextListener(system); addListener(listener); Result result = run(classes.toArray(new Class[0])); for (Failure each : missingClasses) result.getFailures().add(each); return result; }
/** * Abstract Agent class * * <p>Agent implementations should inherit from this class. It provides convenient methods for * managing the agent name and description. */ public abstract class AbstractAgent implements Agent { protected Description description = Description.getUninitializedDescription(this.getClass()); @Override public String getName() { return description.getName(); } @Override public void setName(String name) { description.setName(name); } @Override public Description getDescription() { return new Description(description); } @Override public void setDescription(Description description) { this.description = new Description(description); } }
public Description getSellerProtocol() { Description pd = new Description(); // 0 TryNode tn = new TryNode(); pd.getNode().add(tn); tn.setNextIndex(4); tn.setInnerIndex(1); tn.getCatchIndex().add(3); // 1 ReceiveMessage recvOrder = new ReceiveMessage(); recvOrder.setNextIndex(2); MessageType mt1 = new MessageType(); mt1.setValue(ORDER_MESSAGE_TYPE); recvOrder.getMessageType().add(mt1); pd.getNode().add(recvOrder); // 2 SendMessage sendConformation = new SendMessage(); MessageType mt2 = new MessageType(); mt2.setValue(CONFIRMATION_MESSAGE_TYPE); sendConformation.getMessageType().add(mt2); pd.getNode().add(sendConformation); // 3 ReceiveMessage recvCancel = new ReceiveMessage(); MessageType mt3 = new MessageType(); mt3.setValue(CANCEL_MESSAGE_TYPE); recvCancel.getMessageType().add(mt3); pd.getNode().add(recvCancel); // 4 ReceiveMessage recvFinish = new ReceiveMessage(); MessageType mt4 = new MessageType(); mt4.setValue(FINISH_MESSAGE_TYPE); recvFinish.getMessageType().add(mt4); pd.getNode().add(recvFinish); return (pd); }
private void createSigInfo( Entry<String, FunctionInfo> e, Description consAnno, HashMap<Category, ArrayList<SignatureInfo>> cat2sig, int i) { SignatureInfo si = new SignatureInfo(); si.signature = e.getValue().signatures[i]; Method m = si.signature.evaluateMethod; Description des = m.getAnnotation(Description.class); if ((des == null) || (des.params() == null)) { si.params = consAnno.params(); } else { si.description = des.description(); si.params = des.params(); } if (e.getValue().needsEvaluatorArgument()) { // the first parameter is the InternalGreqlEvaluator assert si.params[0].equals("internal"); si.params = Arrays.copyOfRange(si.params, 1, si.params.length); } if ((des != null) && (des.categories() != null)) { for (Category cat : des.categories()) { if (!cat2sig.containsKey(cat)) { cat2sig.put(cat, new ArrayList<SignatureInfo>()); } cat2sig.get(cat).add(si); } } else { for (Category cat : consAnno.categories()) { if (!cat2sig.containsKey(cat)) { cat2sig.put(cat, new ArrayList<SignatureInfo>()); } cat2sig.get(cat).add(si); } } }