• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DefaultJavaPrettyPrinter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中spoon.reflect.visitor.DefaultJavaPrettyPrinter的典型用法代码示例。如果您正苦于以下问题:Java DefaultJavaPrettyPrinter类的具体用法?Java DefaultJavaPrettyPrinter怎么用?Java DefaultJavaPrettyPrinter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DefaultJavaPrettyPrinter类属于spoon.reflect.visitor包,在下文中一共展示了DefaultJavaPrettyPrinter类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: SpoonedFile

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
public SpoonedFile(File[] sourceFiles, NopolContext nopolContext) {
    this.nopolContext = nopolContext;
    this.sourceFiles = sourceFiles;
    this.projectClasspath = nopolContext.getProjectClasspath();

    factory = SpoonModelLibrary.newFactory();
    factory.getEnvironment().setComplianceLevel(nopolContext.getComplianceLevel());
    factory.getEnvironment().setCommentEnabled(false);
    factory.getEnvironment().setLevel(Level.OFF.toString());

    factory = SpoonModelLibrary.modelFor(factory, sourceFiles, projectClasspath());

    compiler = new DynamicClassCompiler(compilationClasspath(), nopolContext.getComplianceLevel());
    manager = new RuntimeProcessingManager(factory);
    compiledClasses = MetaMap.newHashMap();
    prettyPrinter = new DefaultJavaPrettyPrinter(spoonEnvironment());
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:18,代码来源:SpoonedFile.java


示例2: printJavaFileWithComment

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
public static void printJavaFileWithComment(CtType<?> type, File directory) {
    Factory factory = type.getFactory();
    Environment env = factory.getEnvironment();
    env.setAutoImports(true);
    env.setCommentEnabled(true);
    JavaOutputProcessor processor = new JavaOutputProcessor(directory, new DefaultJavaPrettyPrinter(env));
    processor.setFactory(factory);
    processor.createJavaFile(type);
    env.setAutoImports(false);
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:11,代码来源:DSpotUtils.java


示例3: getRefactoredCode

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
String getRefactoredCode() {
	Environment env = cmdAnalyser.getEnvironment();
	env.useTabulations(true);
	env.setAutoImports(true);
	DefaultJavaPrettyPrinter printer = new DefaultJavaPrettyPrinter(env);
	printer.calculate(null, new ArrayList<>(cmdAnalyser.getModel().getAllTypes()));
	return printer.getResult().replace(" \n", "\n").replaceAll("(\n)+", "\n");
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:9,代码来源:TestBlobRefactoring.java


示例4: run

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
@Override
public void run(final IMarker marker) {
	final Entry<CtExecutable<?>, UIListener> entry = DetectBlobListenerAction.getBlobCommands(marker);
	final WidgetProcessor widgetProc = new WidgetProcessor(true);
	
	System.out.println("Refactoring blob listener: " + entry);
	
	Launcher launcher = new Launcher(Collections.singletonList(widgetProc), DetectBlobListenerAction.currentAnalyser.getCmdAnalyser().getModelBuilder());
	launcher.process();
	
	System.out.println("Widgets processor ended");
	
	final CommandWidgetFinder finder = new CommandWidgetFinder(entry.getValue().getCommands(), widgetProc.getWidgetUsages());
	finder.process();
	final Collection<CommandWidgetFinder.WidgetFinderEntry> allEntries = finder.getResults().values();
	
	System.out.println("Widgets finder ended");
	
	entry.getValue().getCommands().forEach(cmd -> {
		final ListenerCommandRefactor ref = new ListenerCommandRefactor(cmd, null, false, false, false, allEntries);
		ref.execute();
		
		Environment env = widgetProc.getEnvironment();
		env.useTabulations(true);
		env.setAutoImports(true);
		DefaultJavaPrettyPrinter printer = new DefaultJavaPrettyPrinter(env);
		printer.calculate(null, cmd.getAllLocalStatmtsOrdered().stream().
				map(s -> s.getElements(new BasicFilter<CtTypeReference<?>>(CtTypeReference.class))).
				flatMap(s -> s.stream()).map(tref -> tref.getDeclaration()).collect(Collectors.toList()));
		System.out.println(printer.getResult());
	});
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:33,代码来源:BlobMarkerResolution.java


示例5: printAllClasses

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
public static void printAllClasses(Factory factory, File out, File fileFrom) {
    Environment env = factory.getEnvironment();
    Processor processor = new JavaOutputProcessorWithFilter(out, new DefaultJavaPrettyPrinter(env), allClassesName(fileFrom));
    try {
        ProcessingManager pm = new QueueProcessingManager(factory);
        pm.addProcessor(processor);
        pm.process(factory.Package().getRootPackage());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:12,代码来源:PrintClassUtils.java


示例6: printJavaFile

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
public static void printJavaFile(File directory, CtType type) throws IOException {
    try {
        Factory factory = type.getFactory();
        Environment env = factory.getEnvironment();

        JavaOutputProcessor processor = new JavaOutputProcessor(directory, new DefaultJavaPrettyPrinter(env));
        processor.setFactory(factory);

        processor.createJavaFile(type);
        Log.trace("write type {} in directory {}", type.getQualifiedName(), directory);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:15,代码来源:PrintClassUtils.java


示例7: printJavaFile

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
@Override
public void printJavaFile(String directory) throws IOException {
    CtType<?> type = getPosition().getCompilationUnit().getMainType();
    Factory factory = type.getFactory();
    Environment env = factory.getEnvironment();

    JavaOutputProcessor processor = new JavaOutputProcessor(new File(directory), new DefaultJavaPrettyPrinter(env));
    processor.setFactory(factory);

    processor.createJavaFile(type);
    Log.debug("write type {} in directory {}", type.getQualifiedName(), directory);
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:13,代码来源:AddParameterCondition.java


示例8: printJavaFile

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
protected void printJavaFile(String directory, List<CtType> classes) throws IOException {
    Environment env = getFactory().getEnvironment();

    classes.stream()
            .forEach(cl -> {
                Log.debug("print java file: {}", directory + "/" + cl.getQualifiedName().replace(".", "/") + ".java");
                cl.getPosition().getCompilationUnit().getDeclaredTypes().stream()
                        .forEach(cc -> {
                            JavaOutputProcessor processor = new JavaOutputProcessor(new File(directory), new DefaultJavaPrettyPrinter(env));
                            processor.setFactory(getFactory());
                            processor.createJavaFile(cc);
                        });
            });
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:15,代码来源:InstanceTransformation.java


示例9: printJavaFile

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
@Override
public void printJavaFile(String srcDir) throws IOException {
    CtType<?> type = loop.getParent(CtType.class);
    Factory factory = type.getFactory();
    Environment env = factory.getEnvironment();

    JavaOutputProcessor processor = new JavaOutputProcessor(new File(srcDir), new DefaultJavaPrettyPrinter(env));
    processor.setFactory(factory);

    processor.createJavaFile(type);
    Log.debug("write type {} in directory {}", type.getQualifiedName(), srcDir);
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:13,代码来源:LoopPerforation.java


示例10: printJavaFile

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
@Override
public void printJavaFile(String directory) throws IOException {
    CtType<?> type = transformation.getOriginalClass(transformation.getTransplantationPoint());
    Factory factory = type.getFactory();
    Environment env = factory.getEnvironment();

    JavaOutputProcessor processor = new JavaOutputProcessor(new File(directory), new DefaultJavaPrettyPrinter(env));
    processor.setFactory(factory);

    processor.createJavaFile(type);
    Log.debug("write type {} in directory {}", type.getQualifiedName(), directory);
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:13,代码来源:SwitchTransformation.java


示例11: printJavaFile

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
/**
 * Prints the modified java file. When the transformation is done a new java file is created. This method performs a
 * pretty print of it
 *
 * @param directory Directory where the java file is going to be placed
 * @throws IOException
 */
public void printJavaFile(String directory) throws IOException {
    CtType<?> type = getOriginalClass(transplantationPoint);
    Factory factory = type.getFactory();
    Environment env = factory.getEnvironment();

    JavaOutputProcessor processor = new JavaOutputProcessor(new File(directory), new DefaultJavaPrettyPrinter(env));
    processor.setFactory(factory);

    processor.createJavaFile(type);
    Log.debug("write type {} in directory {}", type.getQualifiedName(), directory);
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:19,代码来源:SpoonTransformation.java


示例12: writeLocalVariable

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
public <T> DefaultJavaPrettyPrinter writeLocalVariable(
		CtLocalVariable<T> localVariable) {
	if (!context.noTypeDecl) {
		elementPrinterHelper.writeModifiers(localVariable);
		scan(localVariable.getType());
		printer.write(" ");
	}
	printer.write(localVariable.getType().toString());
	if (localVariable.getDefaultExpression() != null) {
		printer.write(" = ");
		scan(localVariable.getDefaultExpression());
	}
	return this;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:15,代码来源:CodeFragmentEqualPrinter.java


示例13: printJavaFile

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
public void printJavaFile(String directory) throws IOException {
    CtType<?> type = getPosition().getCompilationUnit().getMainType();
    Factory factory = type.getFactory();
    Environment env = factory.getEnvironment();

    JavaOutputProcessor processor = new JavaOutputProcessor(new File(directory), new DefaultJavaPrettyPrinter(env));
    processor.setFactory(factory);

    processor.createJavaFile(type);
    Log.debug("write type {} in directory {}", type.getQualifiedName(), directory);
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:12,代码来源:SingleTransformation.java


示例14: compile

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
@Override
public CompilationResult compile(Collection<? extends CtType> ctClassList, URL[] cp) {

	Map<String, String> toCompile = new HashMap<String, String>();
	prettyPrinter = new DefaultJavaPrettyPrinter(this.getFactory().getEnvironment());
	dcc = new JavaXToolsCompiler();
	
	for (CtType ctClass : ctClassList) {
		try {
			this.getProcessingManager().process(ctClass);
			toCompile.put(ctClass.getQualifiedName(), sourceForModelledClass(ctClass));
		} catch (Exception e) {
			logger.error("Error printing class "+ctClass.getQualifiedName(),e);
		}
	}

	List<String> cps = new ArrayList<>();
	cps.add("-cp");
	String path = "";
	for (URL url : cp) {
		path += ((url.getPath()) + File.pathSeparator);
	}
	cps.add(path);
	
	String compliance = ConfigurationProperties.getProperty("javacompliancelevel");
	cps.add("-source");
	cps.add("1."+ compliance);

	cps.add("-target");
	cps.add("1."+ compliance);
	
	CompilationResult rbc = dcc.javaBytecodeFor(toCompile, new HashMap<String, byte[]>(), cps);
	return rbc;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:35,代码来源:SpoonClassCompiler.java


示例15: partialElementPrint

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
private String partialElementPrint(CtElement element) {
	DefaultJavaPrettyPrinter print = new DefaultJavaPrettyPrinter(element.getFactory().getEnvironment()) {
		@Override
		public DefaultJavaPrettyPrinter scan(CtElement e) {
			if (e != null && e.getMetadata("isMoved") == null) {
				return super.scan(e);
			}
			return this;
		}
	};

	print.scan(element);
	return print.getResult();
}
 
开发者ID:SpoonLabs,项目名称:gumtree-spoon-ast-diff,代码行数:15,代码来源:Operation.java


示例16: generateOutputFile

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
public void generateOutputFile(File destinationFolder) {
    Processor<?> writer = new JavaOutputProcessor(destinationFolder, new DefaultJavaPrettyPrinter(new StandardEnvironment()));
    process(writer);
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:5,代码来源:SpoonedFile.java


示例17: prettyPrinter

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
protected DefaultJavaPrettyPrinter prettyPrinter() {
    return prettyPrinter;
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:4,代码来源:SpoonedFile.java


示例18: generateProcessedSourceFilesUsingCUs

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
protected void generateProcessedSourceFilesUsingCUs() {

		try {
			getFactory().getEnvironment().debugMessage(
					"Generating source using compilation units...");
			// Check output directory
			if (getSourceOutputDirectory() == null) {
				throw new RuntimeException(
						"You should set output directory before generating source files");
			}
			// Create spooned dir
			if (getSourceOutputDirectory().isFile()) {
				throw new RuntimeException("Output must be a directory");
			}
			if (!getSourceOutputDirectory().exists()) {
				if (!getSourceOutputDirectory().mkdirs()) {
					throw new RuntimeException("Error creating output directory");
				}
			}
			setSourceOutputDirectory(getSourceOutputDirectory().getCanonicalFile());
			getFactory().getEnvironment().debugMessage(
					"Generating source files to: " + getSourceOutputDirectory());

			List<File> printedFiles = new ArrayList<File>();
			printing:
			for (spoon.reflect.cu.CompilationUnit cu : getFactory().CompilationUnit()
					.getMap().values()) {

				getFactory().getEnvironment().debugMessage(
						"Generating source for compilation unit: " + cu.getFile());

				CtType<?> element = cu.getMainType();

				CtPackage pack = element.getPackage();

				// create package directory
				File packageDir;
				if (pack.getQualifiedName()
						.equals(CtPackage.TOP_LEVEL_PACKAGE_NAME)) {
					packageDir = new File(getSourceOutputDirectory().getAbsolutePath());
				} else {
					char dot = '.';
					// Create current package dir
					packageDir = new File(getSourceOutputDirectory().getAbsolutePath()
							+ File.separatorChar
							+ pack.getQualifiedName().replace(dot, File.separatorChar));
				}
				if (!packageDir.exists()) {
					if (!packageDir.mkdirs()) {
						throw new RuntimeException(
								"Error creating output directory");
					}
				}

				File file = new File(packageDir.getAbsolutePath()
						+ File.separatorChar + element.getSimpleName()
						+ DefaultJavaPrettyPrinter.JAVA_FILE_EXTENSION);
				file.createNewFile();

				// the path must be given relatively to to the working directory
				InputStream is = getCompilationUnitInputStream(cu.getFile()
						.getPath());

				IOUtils.copy(is, new FileOutputStream(file));

				if (!printedFiles.contains(file)) {
					printedFiles.add(file);
				}
			} // end for
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
 
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:74,代码来源:TestSpoonCompiler.java


示例19: updateOutput

import spoon.reflect.visitor.DefaultJavaPrettyPrinter; //导入依赖的package包/类
public void updateOutput(String output) {
	JavaOutputProcessor fileOutput = new JavaOutputProcessor(new File(output),
			new DefaultJavaPrettyPrinter(getEnvironment()));
	this.javaPrinter = fileOutput;
	fileOutput.setFactory(getFactory());
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:7,代码来源:OutputWritter.java



注:本文中的spoon.reflect.visitor.DefaultJavaPrettyPrinter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StringListImpl类代码示例发布时间:2022-05-23
下一篇:
Java CustomName类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap