当前位置: 首页>>代码示例>>Java>>正文


Java JavaCore.createCompilationUnitFrom方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.JavaCore.createCompilationUnitFrom方法的典型用法代码示例。如果您正苦于以下问题:Java JavaCore.createCompilationUnitFrom方法的具体用法?Java JavaCore.createCompilationUnitFrom怎么用?Java JavaCore.createCompilationUnitFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.JavaCore的用法示例。


在下文中一共展示了JavaCore.createCompilationUnitFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fix

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
private void fix(IMarker marker, IProgressMonitor monitor) {
	MarkerResolutionGenerator.printAttributes (marker);
	try {
		String filepath  = (String) marker.getAttribute(BuildPolicyConfigurationException.JAVAFILENAME);
		int start = (int) marker.getAttribute(IMarker.CHAR_START);
		int end =  (int) marker.getAttribute(IMarker.CHAR_END);
		IFile ifile = (IFile) ResourceManager.toResource(new Path(filepath));
		ICompilationUnit cu = JavaCore.createCompilationUnitFrom(ifile);
		String source = cu.getBuffer().getContents();
		String part1 =  source.substring(0,start);
		String part2 =  source.substring(end);
		source = part1 + "value=\"" + resolutionMarkerDescription.getGenerator() + "\"" + part2;
		final Document document = new Document(source);
		cu.getBuffer().setContents(document.get());
	    cu.save(monitor, false);
	} catch (Exception e) {
		ResourceManager.logException(e);
	}
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:20,代码来源:InvalidAnnotationPathGeneratorMarkerResolution.java

示例2: updateBuildPolicyFileFor

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
/**
 * @param file
 */
public static void updateBuildPolicyFileFor(IFile file) {
	Job job = new WorkspaceJob("Updating Build Policies from " + file.getName()) {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(file);
			if (compilationUnit != null) {
				if (JDTManager.isGraphWalkerExecutionContextClass(compilationUnit)) {
					updateBuildPolicyFileForCompilatioUnit(compilationUnit);
				}
			}
			return Status.OK_STATUS;
		}
	};
	job.setUser(true);
	job.setRule(file.getProject());
	job.schedule();
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:21,代码来源:ResourceManager.java

示例3: containsMethod

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
public static boolean containsMethod (String path, String[] requiredMethods) throws JavaModelException {
	IResource resource = ResourceManager.getResource(path);
	IFile file = (IFile) resource;
	ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file);
	IType[] types = cu.getAllTypes();
	List<String> list = new ArrayList<String>();
	for (int i = 0; i < types.length; i++) {
		IMethod[] methods = types[i].getMethods();
		for (int j = 0; j < methods.length; j++) {
			list.add(methods[j].getElementName());
		}
	} 
	for (int i = 0; i < requiredMethods.length; i++) {
		String method = requiredMethods[i];
		if (!list.contains(method)) return false;
	}     
	return true;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:19,代码来源:JDTHelper.java

示例4: testFindAnnotationParsingInGeneratedAnnotation

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
@Test
public void testFindAnnotationParsingInGeneratedAnnotation() throws Exception {
	IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true,true);
	IFile impl = (IFile) ResourceManager
			.getResource(project.getProject().getFullPath().append("src/test/java/SimpleImpl.java").toString());
	ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(impl);
	 
	AnnotationParsing annoParsing = JDTManager.findAnnotationParsingInGeneratedAnnotation(compilationUnit, "value");
	Location location = annoParsing.getLocation();
	assertNotNull(location);
	 
	int line = IOHelper.findLocationLineInFile(impl, "@Generated");
	assertEquals(line,location.getLineNumber());
	
	Location loc = IOHelper.findLocationInFile(impl, line, "value = \"src/test/resources/Simple.json\"");
	assertEquals(location,loc);
	
	String value = annoParsing.getValue ( );
	assertEquals("src/test/resources/Simple.json", value);
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:21,代码来源:JDTManagerTest.java

示例5: testFindAnnotationParsingInGraphWalkerAnnotation

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
@Test
public void testFindAnnotationParsingInGraphWalkerAnnotation() throws Exception {
	IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true,true);
	IFile impl = (IFile) ResourceManager
			.getResource(project.getProject().getFullPath().append("src/test/java/SimpleImpl.java").toString());
	ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(impl);
	AnnotationParsing annoParsing = JDTManager.findAnnotationParsingInGraphWalkerAnnotation(compilationUnit, "value");
	Location location = annoParsing.getLocation();
	assertNotNull(location);
	int line = IOHelper.findLocationLineInFile(impl, "@GraphWalker");
	assertEquals(line,location.getLineNumber());
	Location loc = IOHelper.findLocationInFile(impl, line, "value = \"random(edge_coverage(100))\"");
	assertEquals(location,loc);
	
	String value = annoParsing.getValue ( );
	assertEquals("random(edge_coverage(100))", value);
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:18,代码来源:JDTManagerTest.java

示例6: testHasGraphWalkerAnnotation

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
@Test
public void testHasGraphWalkerAnnotation() throws Exception {
	IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true,true);
	IFile impl = (IFile) ResourceManager
			.getResource(project.getProject().getFullPath().append("src/test/java/SimpleImpl.java").toString());
	ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(impl);
	boolean b = JDTManager.hasGraphWalkerAnnotation(compilationUnit);
	assertEquals(true, b);
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:10,代码来源:JDTManagerTest.java

示例7: formatUnitSourceCode

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
/**
 * Format a Unit Source Code
 * 
 * @param testInterface
 * @param monitor
 * @throws CoreException 
 */
@SuppressWarnings("unchecked")
public static void formatUnitSourceCode(IFile file, IProgressMonitor monitor) throws CoreException {
	@SuppressWarnings("rawtypes")
	SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
	ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file);
	subMonitor.split(50);
	ICompilationUnit workingCopy = unit.getWorkingCopy(monitor);

	Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();

	options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
	options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
	options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);

	options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS,
			DefaultCodeFormatterConstants.createAlignmentValue(true,
					DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE,
					DefaultCodeFormatterConstants.INDENT_ON_COLUMN));

	final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
	ISourceRange range = unit.getSourceRange();
	TextEdit formatEdit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, unit.getSource(),
			range.getOffset(), range.getLength(), 0, null);
	subMonitor.split(30);
	if (formatEdit != null /* && formatEdit.hasChildren()*/) {
		workingCopy.applyTextEdit(formatEdit, monitor);
		workingCopy.reconcile(ICompilationUnit.NO_AST, false, null, null);
		workingCopy.commitWorkingCopy(true, null);
		workingCopy.discardWorkingCopy();
	}
	file.refreshLocal(IResource.DEPTH_INFINITE, subMonitor);
	subMonitor.split(20);
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:41,代码来源:JDTManager.java

示例8: appendParseGeneratorCall

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
public static void appendParseGeneratorCall(IFile file) throws CoreException, IOException {
	String method = "public void parseTest () {"
			+ "org.graphwalker.core.generator.PathGenerator generator = org.graphwalker.dsl.antlr.generator.GeneratorFactory.parse(\"random(edge_coverage(100))\");"
			+ "}";
	ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(file);
	compilationUnit.getTypes()[0].createMethod(method, null, false, new NullProgressMonitor());
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:8,代码来源:IOHelper.java

示例9: testRenameClass

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
@Test
public void testRenameClass() throws Exception {
	IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true,true);
	IFile impl = (IFile) ResourceManager
			.getResource(project.getProject().getFullPath().append("src/test/java/SimpleImpl.java").toString());
	
	// The rename method only renames the class name within the file. It does not rename the file and it is expected.
	// See the comment of the JDTManager.renameClass (...) api
	// And this is why we expect 1 pb "assertEquals(1, pbs.length);" below
	IFile f = JDTManager.renameClass(impl, "SimpleImpl", "SimpleImpl1", new NullProgressMonitor());
	
	Waiter.waitUntil(new ICondition () {
		@Override
		public boolean checkCondition() throws Exception {
			IFolder folder = (IFolder) ResourceManager.getResource(project.getProject().getFullPath().append("src/test/java").toString());
			IFile frenamed = folder.getFile("SimpleImpl1.java");
			return frenamed.getName().equals("SimpleImpl1.java");
		}

		@Override
		public String getFailureMessage() {
			return "file not renamed";
		}
		
	});
	
	ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(f);
	CompilationUnit cu = JDTManager.parse(compilationUnit);
	IProblem[] pbs = cu.getProblems();
	assertEquals(1, pbs.length);
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:32,代码来源:JDTManagerTest.java

示例10: testInvalidGeneratorInSourceFile

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
@Test
public void testInvalidGeneratorInSourceFile () throws CoreException, FileNotFoundException {
	System.out.println("XXXXXXXXXXXXXXXXXXXX testInvalidGeneratorInSourceFile");
	String expectedNewGenerator = "xxx";
	 
		PetClinicProject.create (bot,gwproject); // At this step the generator is "random(edge_coverage(100))"
		 
		IFile veterinarien = PetClinicProject.getVeterinariensSharedStateImplFile(gwproject);
	ICompilationUnit cu = JavaCore.createCompilationUnitFrom(veterinarien);
	String oldGenerator = JDTManager.findPathGeneratorInGraphWalkerAnnotation(cu);
		SourceHelper.updatePathGenerator(veterinarien, oldGenerator, expectedNewGenerator);
		cu = JavaCore.createCompilationUnitFrom(veterinarien);
		String newGenerator = JDTManager.findPathGeneratorInGraphWalkerAnnotation(cu);
		assertEquals(newGenerator,expectedNewGenerator);
		
		GW4EProject project = new GW4EProject(bot, gwproject);
		project.cleanBuild(); 
		
		String expectedErrorMessageInProblemView = "Invalid path generator : '"+ expectedNewGenerator + "'";
	ProblemView pv = ProblemView.open(bot);
	List<ResolutionMarkerDescription> markers = PathGeneratorDescription.getDescriptions();
	 
	pv.executeQuickFixForErrorMessage(
			expectedErrorMessageInProblemView,
			markers.get(0).toString(), 
			new ICondition [] {new NoErrorInProblemView(pv)}
	);
	pv.close();//Mandatory
		
		String graphmlSourcePath = JDTManager.getGW4EGeneratedAnnotationValue(cu,"value");
		IPath path = new Path (gwproject).append(graphmlSourcePath);
		IFile graphModel =  (IFile)ResourceManager.getResource(path.toString());
		IPath buildPolicyPath = ResourceManager.getBuildPoliciesPathForGraphModel(graphModel);
		IFile buildPolicyFile =  (IFile)ResourceManager.getResource(buildPolicyPath.toString());
		
	PropertyValueCondition condition = new PropertyValueCondition(buildPolicyFile,graphModel.getName(),"random(vertex_coverage(100));I;random(edge_coverage(100));I;");
	bot.waitUntil(condition);
	    
	}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:40,代码来源:GW4EFixesTestCase.java

示例11: updatePathGenerator1

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
public static void updatePathGenerator1 (IFile ifile, String oldPathGenerator,String newPathGenerator) throws JavaModelException {
	ICompilationUnit cu = JavaCore.createCompilationUnitFrom(ifile);
	String source = cu.getBuffer().getContents();
	source = source.replace(oldPathGenerator, newPathGenerator);
	final  Document document = new Document(source);
	cu.getBuffer().setContents(document.get());
    cu.save(new NullProgressMonitor(), true);
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:9,代码来源:SourceHelper.java

示例12: updatePathGenerator

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
public static void updatePathGenerator (IFile ifile, String oldPathGenerator,String newPathGenerator) throws CoreException {
	ICompilationUnit cu = JavaCore.createCompilationUnitFrom(ifile);
	 
	ICompilationUnit workingCopy = cu.getWorkingCopy(new NullProgressMonitor());
	
	IBuffer buffer = ((IOpenable)workingCopy).getBuffer();
	String source = buffer.getContents();
	int start = source.indexOf(oldPathGenerator);
	buffer.replace(start, oldPathGenerator.length(), newPathGenerator);
	workingCopy.reconcile(ICompilationUnit.NO_AST, false, workingCopy.getOwner(), new NullProgressMonitor());
    workingCopy.commitWorkingCopy(true, null);
    workingCopy.discardWorkingCopy();
    
    ifile.touch(new NullProgressMonitor ());
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:16,代码来源:SourceHelper.java

示例13: testFindPathGeneratorInGraphWalkerAnnotation

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
@Test
public void testFindPathGeneratorInGraphWalkerAnnotation() throws Exception {
	IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true,true);
	IFile impl = (IFile) ResourceManager
			.getResource(project.getProject().getFullPath().append("src/test/java/SimpleImpl.java").toString());
	ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(impl);
	String value = JDTManager.findPathGeneratorInGraphWalkerAnnotation(compilationUnit);
	assertEquals("random(edge_coverage(100))", value);
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:10,代码来源:JDTManagerTest.java

示例14: testFindSetPathGeneratorInvocation

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
@Test
public void testFindSetPathGeneratorInvocation() throws Exception {
	IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true,true);
	IFile impl = (IFile) ResourceManager
			.getResource(project.getProject().getFullPath().append("src/test/java/SimpleImpl.java").toString());
	ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(impl);
	IType type = compilationUnit.getAllTypes()[0];
	Map<String, List<String>> map = JDTManager.findSetPathGeneratorInvocation(project.getProject(), type);
	List<String> list = map.get("SimpleImpl");
	assertTrue (list.size()==1);
	String value = list.get(0);
	assertEquals("new RandomPath(new EdgeCoverage(100))", value);
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:14,代码来源:JDTManagerTest.java

示例15: testParse

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
@Test
public void testParse() throws Exception {
	IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true,true);
	IFile impl = (IFile) ResourceManager
			.getResource(project.getProject().getFullPath().append("src/test/java/SimpleImpl.java").toString());
	ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(impl);
	CompilationUnit cu = JDTManager.parse(compilationUnit);
	IProblem[] pbs = cu.getProblems();
	assertEquals(0, pbs.length);
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:11,代码来源:JDTManagerTest.java


注:本文中的org.eclipse.jdt.core.JavaCore.createCompilationUnitFrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。