Java Code Examples for org.apache.commons.lang.StringUtils#trimImports()

The following examples show how to use org.apache.commons.lang.StringUtils#trimImports() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Test
public void issue105() throws Exception {
	//@formatter:off
	String expected =
			"import importorder.example.root.BFoo;\n" +
			"import importorder.example.root.CFoo;\n" +
			"import importorder.example.root.A.AFoo;\n";

	String imports =
			"import importorder.example.root.BFoo;\n" +
			"import importorder.example.root.CFoo;\n" +
			"import importorder.example.root.A.AFoo;\n";

	//@formatter:on

	List<String> importsOrder = Arrays.asList();

	List<String> importsList = StringUtils.trimImports(imports);
	Collections.shuffle(importsList);
	List<String> strings = sort(importsList, importsOrder);
	printAndAssert(expected, strings);
}
 
Example 2
@Test
public void test3a() throws Exception {
	//@formatter:off
	String expected = "import static aaa.XAAA.aaa;\n"
			+ "import static com.google.common.collect.Multimaps.forMap;\n" + "import static foo.bar.XFOO.foo;\n"
			+ "import static org.easymock.EasyMock.createControl;\n" + "\n" + "import java.util.ArrayList;\n"
			+ "import java.util.HashMap;\n" + "import java.util.List;\n" + "\n"
			+ "import org.easymock.IMocksControl;\n" + "\n" + "import com.google.common.collect.SetMultimap;\n"
			+ "\n" + "import aaa.XAAA;\n" + "import foo.bar.XFOO;\n";

	String imports = "import static org.easymock.EasyMock.createControl;\n" + "\n" + "import java.util.ArrayList;\n"
			+ "import java.util.HashMap;\n" + "import java.util.List;\n" + "\n"
			+ "import org.easymock.IMocksControl;\n" + "\n" + "import com.google.common.collect.SetMultimap;\n"
			+ "\n" + "import aaa.XAAA;\n" + "import foo.bar.XFOO;\n" + "\n" + "import static aaa.XAAA.aaa;\n"
			+ "import static com.google.common.collect.Multimaps.forMap;\n" + "import static foo.bar.XFOO.foo;\n";
	//@formatter:on
	List<String> importsOrder = Arrays.asList("java", "javax", "org", "com");

	List<String> importsList = StringUtils.trimImports(imports);
	Collections.shuffle(importsList);
	List<String> strings = sort(importsList, importsOrder);
	printAndAssert(expected, strings);
}
 
Example 3
@Test
public void test3b() throws Exception {
	//@formatter:off
		String expected = "import static aaa.XAAA.aaa;\n"
			+ "import static com.google.common.collect.Multimaps.forMap;\n" + "import static foo.bar.XFOO.foo;\n"
			+ "import static org.easymock.EasyMock.createControl;\n" + "\n" + "import aaa.XAAA;\n"
			+ "import com.google.common.collect.SetMultimap;\n" + "import foo.bar.XFOO;\n"
			+ "import java.util.ArrayList;\n" + "import java.util.HashMap;\n" + "import java.util.List;\n"
			+ "import org.easymock.IMocksControl;\n";

	String imports = "import static org.easymock.EasyMock.createControl;\n" + "\n" + "import java.util.ArrayList;\n"
			+ "import java.util.HashMap;\n" + "import java.util.List;\n" + "\n"
			+ "import org.easymock.IMocksControl;\n" + "\n" + "import com.google.common.collect.SetMultimap;\n"
			+ "\n" + "import aaa.XAAA;\n" + "import foo.bar.XFOO;\n" + "\n" + "import static aaa.XAAA.aaa;\n"
			+ "import static com.google.common.collect.Multimaps.forMap;\n" + "import static foo.bar.XFOO.foo;\n";
	//@formatter:on
	List<String> importsOrder = Arrays.asList();

	List<String> importsList = StringUtils.trimImports(imports);
	Collections.shuffle(importsList);
	List<String> strings = sort(importsList, importsOrder);
	printAndAssert(expected, strings);
}
 
Example 4
@Test
public void test3() throws Exception {
	//@formatter:off	
	String expected = "import static com.MyUtil.kuk;\n" + "import static org.junit.Assert.assertNotNull;\n"
			+ "import static tmutil.StringUtil.replaceText;\n\n" + "import java.util.ArrayList;\n" + "\n"
			+ "import org.w3c.dom.DOMConfiguration;\n" + "import org.w3c.dom.DOMException;\n"
			+ "import org.w3c.dom.Document;\n" + "import org.w3c.dom.Node;\n"
			+ "import org.w3c.dom.ls.LSException;\n" + "import org.w3c.dom.ls.LSInput;\n"
			+ "import org.w3c.dom.ls.LSParser;\n" + "import org.w3c.dom.ls.LSParserFilter;\n"
			+ "import org.xml.sax.InputSource;\n";

	String imports = "import org.w3c.dom.DOMConfiguration;\n" + "import org.w3c.dom.DOMException;\n"
			+ "import org.w3c.dom.Document;\n" + "import org.w3c.dom.Node;\n"
			+ "import org.w3c.dom.ls.LSException;\n" + "import org.w3c.dom.ls.LSInput;\n"
			+ "import static com.MyUtil.kuk;\n" + "import static org.junit.Assert.assertNotNull;\n"
			+ "import static tmutil.StringUtil.replaceText;\n" + "import org.w3c.dom.ls.LSParser;\n"
			+ "import org.w3c.dom.ls.LSParserFilter;\n" + "import org.xml.sax.InputSource;\n" + N
			+ "import java.util.ArrayList;";

	List<String> imports1 = StringUtils.trimImports(imports);
	System.err.println(Arrays.toString(imports1.toArray()));
	List<String> strings = sort(imports1, DEFAULT_ORDER);
	printAndAssert(expected, strings);
}
 
Example 5
@Test
public void test4() throws Exception {
	//@formatter:off
	String expected = "import java.util.Arrays;\n" +
               "\n" +
               "import comtrollers.deadbolt.Restrict;\n" +
               "import models.Deployment;\n" +
               "import play.jobs.Job;\n" +
               "import play.mvc.Before;\n";

	String imports = "import comtrollers.deadbolt.Restrict;\n" + "import java.util.Arrays;\n"
			+ "import play.mvc.Before;\n" + "import models.Deployment;\n" + "import play.jobs.Job;\n";

	List<String> imports1 = StringUtils.trimImports(imports);
	System.err.println(Arrays.toString(imports1.toArray()));
	List<String> strings = sort(imports1, DEFAULT_ORDER);
	printAndAssert(expected, strings);
}
 
Example 6
@Test
public void test4b() throws Exception {
	String expected = 
			"import java.util.Arrays;\n" +
			"\n" +
			"import comtrollers.deadbolt.Restrict;\n" +
			"import controllers.deadbolt.Restricts;\n" +
			"import models.Deployment;\n" +
			"import play.jobs.Job;\n" +
			"import play.mvc.Before;\n";
	
	String imports = 
			"import java.util.Arrays;\n" +
			"import comtrollers.deadbolt.Restrict;\n" +
			"import controllers.deadbolt.Restricts;\n" +
			"import models.Deployment;\n" +
			"import play.jobs.Job;\n" +
			"import play.mvc.Before;\n";
	
	List<String> imports1 = StringUtils.trimImports(imports);
	System.err.println(Arrays.toString(imports1.toArray()));
	List<String> strings = sort(imports1, DEFAULT_ORDER);
	printAndAssert(expected, strings);
}
 
Example 7
@Test
public void test5()		
		 throws Exception {
	//@formatter:off
	String expected = "import static java.lang.Integer.numberOfLeadingZeros;\n"
			+ "import static java.lang.Integer.valueOf;\n" + "\n" + "import java.sql.Date;\n"
			+ "import java.util.List;\n" + "import java.util.Map;\n"
			+ "import javax.xml.crypto.dsig.spec.HMACParameterSpec;\n" + "import org.w3c.dom.Text;\n"
			+ "import org.w3c.dom.stylesheets.StyleSheetList;\n";

	String imports = "import javax.xml.crypto.dsig.spec.HMACParameterSpec;\n" + "import org.w3c.dom.Text;\n"
			+ "import java.util.List;\n" + "import static java.lang.Integer.numberOfLeadingZeros;\n"
			+ "import java.sql.Date;\n" + "\n" + "import static java.lang.Integer.valueOf;\n"
			+ "import java.util.Map;\n" + "import org.w3c.dom.stylesheets.StyleSheetList;\n";
	//@formatter:on

	List<String> importsOrder = Collections.emptyList();

	List<String> imports1 = StringUtils.trimImports(imports);
	System.err.println(Arrays.toString(imports1.toArray()));
	List<String> strings = sort(imports1, importsOrder);
	printAndAssert(expected, strings);
}
 
Example 8
@Test
public void test12() throws Exception {
	//@formatter:off
	String imports = "import static foo.JettyStart.startJetty;\n" + "import org.apache.commons.lang3.ArrayUtils;\n"
			+ "import static foo.Tomcat7Start.startTomcat;\n";

	String expected = "import static foo.JettyStart.startJetty;\n" + "\n"
			+ "import org.apache.commons.lang3.ArrayUtils;\n" + "\n"
			+ "import static foo.Tomcat7Start.startTomcat;\n";
	//@formatter:on

	List<String> importsOrder = Arrays.asList("\\#", "", "\\#foo.Tomcat7Start");

	List<String> imports1 = StringUtils.trimImports(imports);
	System.err.println(Arrays.toString(imports1.toArray()));
	List<String> strings = sort(imports1, importsOrder);
	printAndAssert(expected, strings);
}
 
Example 9
@Test
public void test12() throws Exception {
	String imports = "import static foo.JettyStart.startJetty;\n" + "import org.apache.commons.lang3.ArrayUtils;\n"
			+ "import static foo.Tomcat7Start.startTomcat;\n";

	String expected = "import static foo.JettyStart.startJetty;\n" + "\n"
			+ "import org.apache.commons.lang3.ArrayUtils;\n" + "\n"
			+ "import static foo.Tomcat7Start.startTomcat;\n";

	List<String> importsOrder = Arrays.asList("\\#", "", "\\#foo.Tomcat7Start");

	List<String> imports1 = StringUtils.trimImports(imports);
	System.err.println(Arrays.toString(imports1.toArray()));
	List<String> strings = ImportsSorter450.sort(imports1, importsOrder);
	printAndAssert(expected, strings);
}
 
Example 10
@Test
public void issue105() throws Exception {
	//@formatter:off
	String expected =
			"import importorder.example.root.BFoo;\n" +
			"import importorder.example.root.CFoo;\n" +
			"import importorder.example.root.A.AFoo;\n";

	String imports =
			"import importorder.example.root.BFoo;\n" +
			"import importorder.example.root.CFoo;\n" +
			"import importorder.example.root.A.AFoo;\n";

	//@formatter:on

	List<String> importsOrder = Arrays.asList("java", "javax", "org", "com");

	List<String> importsList = StringUtils.trimImports(imports);
	Collections.shuffle(importsList);
	List<String> strings = ImportsSorter450.sort(importsList, importsOrder);
	printAndAssert(expected, strings);
}
 
Example 11
@Test
public void test9() throws Exception {
	String expected = "import android.content.Context;\n" + "import android.view.LayoutInflater;\n"
			+ "import android.view.View;\n" + "import android.widget.TextView;\n";

	String imports = "\n" + "import android.widget.TextView;\n" + "import android.view.LayoutInflater;\n"
			+ "import android.view.View;\n" + "import android.content.Context;";

	List<String> imports1 = StringUtils.trimImports(imports);
	System.err.println(Arrays.toString(imports1.toArray()));
	List<String> strings = ImportsSorter450.sort(imports1, DEFAULT_ORDER);
	printAndAssert(expected, strings);
}
 
Example 12
@Test
public void test8() throws Exception {
	String imports = "";

	String expected = "";

	List<String> imports1 = StringUtils.trimImports(imports);
	System.err.println(Arrays.toString(imports1.toArray()));
	List<String> strings = ImportsSorter450.sort(imports1, DEFAULT_ORDER);
	printAndAssert(expected, strings);
}
 
Example 13
@Test
public void test11() throws Exception {
	String imports = "import static org.junit.Assert.assertSame;\n" + "import org.junit.Test;";

	String expected = "import static org.junit.Assert.assertSame;\n" + "\n" + "import org.junit.Test;\n";

	List<String> importsOrder = Arrays.asList("\\#", "");

	List<String> imports1 = StringUtils.trimImports(imports);
	System.err.println(Arrays.toString(imports1.toArray()));
	List<String> strings = ImportsSorter450.sort(imports1, importsOrder);
	printAndAssert(expected, strings);
}
 
Example 14
@Test
public void issue104a() throws Exception {
	//@formatter:off
	String expected =
			"import com.mycorp.Foo;\n" +
					"\n" +
					"import static com.mycorp.Foo.foo;\n" +
					"\n" +
					"import com.google.bar;\n" +
					"\n" +
					"import static com.google.bar.bar;\n";

	String imports =
			"import static com.google.bar.bar;\n" +
			"import com.google.bar;\n" +
			"import static com.mycorp.Foo.foo;\n" +
			"import com.mycorp.Foo;\n" +
					"";

	//@formatter:on


	List<String> importsList = StringUtils.trimImports(imports);
	Collections.shuffle(importsList);

	Settings settings = new Settings();
	File file = FileUtils.getFile("resources/issue104.importorder");
	setPath(settings, file);
	ImportOrderProvider importOrderProvider = new ImportOrderProvider(settings);

	List<String> strings = sort(importsList, importOrderProvider.get());
	printAndAssert(expected, strings);
}
 
Example 15
@Test
public void test4() throws Exception {
	String expected = "import java.util.Arrays;\n" + "\n" + "import models.Deployment;\n"
			+ "import play.jobs.Job;\n" + "import play.mvc.Before;\n" + "import controllers.deadbolt.Restrict;\n";

	String imports = "import controllers.deadbolt.Restrict;\n" + "import java.util.Arrays;\n"
			+ "import play.mvc.Before;\n" + "import models.Deployment;\n" + "import play.jobs.Job;\n";

	List<String> imports1 = StringUtils.trimImports(imports);
	System.err.println(Arrays.toString(imports1.toArray()));
	List<String> strings = ImportsSorter450.sort(imports1, DEFAULT_ORDER);
	printAndAssert(expected, strings);
}
 
Example 16
@Test
public void test10() throws Exception {
	String imports = "\n" + "import static org.junit.Assert.assertSame;\n" + "import org.junit.Test;";

	String expected = "import org.junit.Test;\n" + "\n" + "import static org.junit.Assert.assertSame;\n";

	List<String> importsOrder = Arrays.asList("", "\\#");

	List<String> imports1 = StringUtils.trimImports(imports);
	System.err.println(Arrays.toString(imports1.toArray()));
	List<String> strings = ImportsSorter450.sort(imports1, importsOrder);
	printAndAssert(expected, strings);
}
 
Example 17
@Test
public void test4b() throws Exception {
	String expected = "import java.util.Arrays;\n" + "\n" + "import javax.Javax;\n" + "\n"
			+ "import models.Deployment;\n" + "import play.jobs.Job;\n" + "import play.mvc.Before;\n" + "\n"
			+ "import comtrollers.deadbolt.Restrict;\n" + "\n" + "import controllers.deadbolt.Restricts;\n";

	String imports = "\n" + "import java.util.Arrays;\n" + "import models.Deployment;\n" + "import play.jobs.Job;\n"
			+ "import play.mvc.Before;\n" + "import javax.Javax;\n" + "import comtrollers.deadbolt.Restrict;\n"
			+ "import controllers.deadbolt.Restricts;\n";

	List<String> imports1 = StringUtils.trimImports(imports);
	System.err.println(Arrays.toString(imports1.toArray()));
	List<String> strings = ImportsSorter450.sort(imports1, DEFAULT_ORDER);
	printAndAssert(expected, strings);
}
 
Example 18
@Test
public void test7() throws Exception {
	//@formatter:off
	String imports = "import java.util.Calendar;";

	String expected = "import java.util.Calendar;\n";
	//@formatter:on

	List<String> importsOrder = Arrays.asList("com", "java", "javax", "org");

	List<String> imports1 = StringUtils.trimImports(imports);
	System.err.println(Arrays.toString(imports1.toArray()));
	List<String> strings = sort(imports1, importsOrder);
	printAndAssert(expected, strings);
}
 
Example 19
@Test
public void test4a() throws Exception {
	String expected = "import java.util.Arrays;\n" + "\n" + "import models.Deployment;\n"
			+ "import play.jobs.Job;\n" + "import play.mvc.Before;\n" + "\n"
			+ "import comtrollers.deadbolt.Restrict;\n";

	String imports = "import comtrollers.deadbolt.Restrict;\n" + "import java.util.Arrays;\n"
			+ "import play.mvc.Before;\n" + "import models.Deployment;\n" + "import play.jobs.Job;\n";

	List<String> imports1 = StringUtils.trimImports(imports);
	System.err.println(Arrays.toString(imports1.toArray()));
	List<String> strings = ImportsSorter450.sort(imports1, DEFAULT_ORDER);
	printAndAssert(expected, strings);
}
 
Example 20
@Test
public void test11() throws Exception {
	//@formatter:off
	String imports = "import static org.junit.Assert.assertSame;\n" + "import org.junit.Test;";

	String expected = "import static org.junit.Assert.assertSame;\n" + "\n" + "import org.junit.Test;\n";
	//@formatter:on

	List<String> importsOrder = Arrays.asList("\\#", "");

	List<String> imports1 = StringUtils.trimImports(imports);
	System.err.println(Arrays.toString(imports1.toArray()));
	List<String> strings = sort(imports1, importsOrder);
	printAndAssert(expected, strings);
}