@Test public void testMultipleLines() throws ScriptException { DefaultNameStrategy nameStrategy = new DefaultNameStrategy(); assertThat(nameStrategy.getFullName("" + "\n" + "package com.example;\n" + "public class Alpha {\n" + "}")) .isEqualTo("com.example.Alpha"); assertThat(nameStrategy.getFullName("" + "\n" + "package \n" + " com.example ;\n" + "\n" + "public\n" + "\tclass\n" + "\n" + "Alpha\n" + "{\n" + "}")) .isEqualTo("com.example.Alpha"); }
@Override public String getFullName(String script) throws ScriptException { String fullPackage = null; Matcher packageMatcher = PACKAGE_PATTERN.matcher(script); if (packageMatcher.find()) { fullPackage = packageMatcher.group(1); } Matcher nameMatcher = NAME_PATTERN.matcher(script); if (nameMatcher.find()) { String name = nameMatcher.group(1); if (fullPackage == null) { return name; } else { return fullPackage + "." + name; } } throw new ScriptException("Could not determine fully qualified class name"); }
DefaultNameStrategy implements NameStrategy { @Override public String getFullName(String script) throws ScriptException { String fullPackage = null; Matcher packageMatcher = PACKAGE_PATTERN.matcher(script); if (packageMatcher.find()) { fullPackage = packageMatcher.group(1); } Matcher nameMatcher = NAME_PATTERN.matcher(script); if (nameMatcher.find()) { String name = nameMatcher.group(1); if (fullPackage == null) { return name; } else { return fullPackage + "." + name; } } throw new ScriptException("Could not determine fully qualified class name"); } }
DefaultNameStrategy implements NameStrategy { @Override public String getFullName(String script) throws ScriptException { String fullPackage = null; Matcher packageMatcher = PACKAGE_PATTERN.matcher(script); if (packageMatcher.find()) { fullPackage = packageMatcher.group(1); } Matcher nameMatcher = NAME_PATTERN.matcher(script); if (nameMatcher.find()) { String name = nameMatcher.group(1); if (fullPackage == null) { return name; } else { return fullPackage + "." + name; } } throw new ScriptException("Could not determine fully qualified class name"); }  }
DefaultNameStrategy implements NameStrategy { @Override public String getFullName(String script) throws ScriptException { String fullPackage = null; Matcher packageMatcher = PACKAGE_PATTERN.matcher(script); if (packageMatcher.find()) { fullPackage = packageMatcher.group(1); } Matcher nameMatcher = NAME_PATTERN.matcher(script); if (nameMatcher.find()) { String name = nameMatcher.group(1); if (fullPackage == null) { return name; } else { return fullPackage + "." + name; } } throw new ScriptException("Could not determine fully qualified class name"); }  @Override String getFullName(String script); }
DefaultNameStrategy implements NameStrategy { @Override public String getFullName(String script) throws ScriptException { String fullPackage = null; Matcher packageMatcher = PACKAGE_PATTERN.matcher(script); if (packageMatcher.find()) { fullPackage = packageMatcher.group(1); } Matcher nameMatcher = NAME_PATTERN.matcher(script); if (nameMatcher.find()) { String name = nameMatcher.group(1); if (fullPackage == null) { return name; } else { return fullPackage + "." + name; } } throw new ScriptException("Could not determine fully qualified class name"); }  @Override String getFullName(String script);  }