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


Java JavaCore类代码示例

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


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

示例1: testEnrichClass

import org.eclipse.jdt.core.JavaCore; //导入依赖的package包/类
@Test
public void testEnrichClass() throws Exception {
	IJavaProject pj = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME,true,false);
	
	IFile impl = ProjectHelper.createDummyClass (pj);
	ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(impl);
	IMethod m = compilationUnit.getTypes() [0].getMethod("runFunctionalTest",new String[0]);
	assertFalse (m.exists());

	IFile file = (IFile) ResourceManager.getResource(pj.getProject().getFullPath().append("src/test/resources/Simple.json").toString());
	ResourceContext context =  GenerationFactory.getResourceContext(file);
	ClassExtension ce = context.getClassExtension();
	ce.setGenerateRunFunctionalTest(true);
	ce.setStartElementForJunitTest("start_app");	
	TestResourceGeneration trg = new TestResourceGeneration(context);	 
	JDTManager.enrichClass(impl, trg, new NullProgressMonitor());
	
	m = compilationUnit.getTypes() [0].getMethod("runFunctionalTest",new String[0]);
	assertTrue (m.exists());
	
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:22,代码来源:JDTManagerTest.java

示例2: 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

示例3: addJunit4Libraries

import org.eclipse.jdt.core.JavaCore; //导入依赖的package包/类
/**
 * Add JUnit libraries to the passed project
 * 
 * @param project
 * @throws JavaModelException
 */
private static void addJunit4Libraries(IProject project) throws JavaModelException {
	IClasspathEntry entry = JavaCore.newContainerEntry(JUnitCore.JUNIT4_CONTAINER_PATH);
	IJavaProject javaProject = JavaCore.create(project);
	IClasspathEntry[] entries = javaProject.getRawClasspath();
	boolean junitFound = false;
	String s = entry.getPath().toString();
	for (int i = 0; i < entries.length; i++) {
		if (entries[i].getPath().toString().indexOf(s) != -1) {
			junitFound = true;
			break;
		}
	}
	if (!junitFound) {
		IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
		System.arraycopy(entries, 0, newEntries, 0, entries.length);
		newEntries[entries.length] = entry;
		javaProject.setRawClasspath(newEntries, null);
	}
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:26,代码来源:ClasspathManager.java

示例4: collectAllCompilationUnits

import org.eclipse.jdt.core.JavaCore; //导入依赖的package包/类
/**
 * Collects all compilation units within the project.
 * @return the collection of the compilation units
 */
public static List<ICompilationUnit> collectAllCompilationUnits() {
    List<ICompilationUnit> units = new ArrayList<ICompilationUnit>();
    
    try {
        IProject[] projects =  getWorkspace().getRoot().getProjects();
        for (int i = 0; i < projects.length; i++) {
            IJavaProject project = (IJavaProject)JavaCore.create((IProject)projects[i]);
            
            IPackageFragment[] packages = project.getPackageFragments();
            for (int j = 0; j < packages.length; j++) {
                
                ICompilationUnit[] cus = packages[j].getCompilationUnits();
                for (int k = 0; k < cus.length; k++) {
                    IResource res = cus[k].getResource();
                    if (res.getType() == IResource.FILE) {
                        String name = cus[k].getPath().toString();
                        if (name.endsWith(".java")) { 
                            units.add(cus[k]);
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
    
    return units;
}
 
开发者ID:liaoziyang,项目名称:ContentAssist,代码行数:34,代码来源:WorkspaceUtilities.java

示例5: getProjectMap

import org.eclipse.jdt.core.JavaCore; //导入依赖的package包/类
/**
 * Obtient la map Project vers Projet Java du workspace courant.
 * 
 * @return Map des projets.
 */
public static JavaProjectMap getProjectMap() {
	JavaProjectMap projects = new JavaProjectMap();

	/* Racine du workspace courant. */
	IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();

	/* Parcourt les projets de la racine. */
	for (IProject project : wsRoot.getProjects()) {

		/* Vérication que le projet est un projet Java accessible. */
		if (!project.isAccessible() || !JdtUtils.isJavaProject(project)) {
			continue;
		}

		/* Obtient l'AST du projet. */
		IJavaProject javaProject = JavaCore.create(project);
		projects.put(project, javaProject);
	}
	return projects;
}
 
开发者ID:sebez,项目名称:vertigo-chroma-kspplugin,代码行数:26,代码来源:ResourceUtils.java

示例6: createClasspathEntries

import org.eclipse.jdt.core.JavaCore; //导入依赖的package包/类
@Override
public List<IClasspathEntry> createClasspathEntries()
{
	IPath srcJar = null;
	if( underlyingResource.getFileExtension().equals("jar") )
	{
		String name = underlyingResource.getName();
		IFile srcJarFile = underlyingResource.getProject().getFile(
			"lib-src/" + name.substring(0, name.length() - 4) + "-sources.jar");
		if( srcJarFile.exists() )
		{
			srcJar = srcJarFile.getFullPath();
		}
	}
	return Arrays.asList(JavaCore.newLibraryEntry(underlyingResource.getFullPath(), srcJar, null));
}
 
开发者ID:equella,项目名称:Equella,代码行数:17,代码来源:JarPluginModelImpl.java

示例7: addGW4EClassPathContainer

import org.eclipse.jdt.core.JavaCore; //导入依赖的package包/类
/**
 * Add GraphWalker libraries to the passed project
 * 
 * @param project
 * @throws JavaModelException
 */
public static void addGW4EClassPathContainer(IProject project) throws JavaModelException {
	if (hasGW4EClassPathContainer(project)) {
		return;
	}
	IJavaProject javaProject = JavaCore.create(project); 
	IClasspathEntry[] entries = javaProject.getRawClasspath();
	IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
	System.arraycopy(entries, 0, newEntries, 0, entries.length);
	Path lcp = new Path(GW4ELibrariesContainer.ID);
	IClasspathEntry libEntry = JavaCore.newContainerEntry(lcp, true);
	newEntries[entries.length] = JavaCore.newContainerEntry(libEntry.getPath(), true);
	javaProject.setRawClasspath(newEntries, null);
	 
  	addJunit4Libraries(project);
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:22,代码来源:ClasspathManager.java

示例8: removeFolderFromClasspath

import org.eclipse.jdt.core.JavaCore; //导入依赖的package包/类
/**
 * Remove the passed folder from ClassPath
 * 
 * @param project
 * @param folderPath
 * @param monitor
 * @throws JavaModelException
 */
public static void removeFolderFromClasspath(IProject project, String folderPath, IProgressMonitor monitor)
		throws JavaModelException {
	IJavaProject javaProject = JavaCore.create(project);
	IClasspathEntry[] entries = javaProject.getRawClasspath();
	List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
	IPath folder = project.getFolder(folderPath).getFullPath();
	for (int i = 0; i < entries.length; i++) {
		if (!entries[i].getPath().equals(folder)) {
			newEntries.add(entries[i]);
		}
	}
	entries = new IClasspathEntry[newEntries.size()];
	newEntries.toArray(entries);
	javaProject.setRawClasspath(entries, monitor);

}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:25,代码来源:ClasspathManager.java

示例9: findClassesWithAnnotation

import org.eclipse.jdt.core.JavaCore; //导入依赖的package包/类
/**
 * @param projectName
 * @return
 * @throws JavaModelException
 */
private static List<IType> findClassesWithAnnotation(String projectName, Class annotationClass, String attributName,
		boolean valued) throws JavaModelException {
	List<IType> classList = new ArrayList<IType>();
	IProject project = ResourceManager.getProject(projectName);
	IJavaProject javaProject = JavaCore.create(project);
	IPackageFragment[] packages = javaProject.getPackageFragments();
	for (IPackageFragment packageFragment : packages) {
		for (final ICompilationUnit compilationUnit : packageFragment.getCompilationUnits()) {
			if (compilationUnit.exists()) {
				IType type = getClassesWithAnnotation(compilationUnit, annotationClass, attributName, valued);
				if (type != null)
					classList.add(type);
			}
		}
	}
	return classList;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:23,代码来源:JDTManager.java

示例10: getGW4EProjects

import org.eclipse.jdt.core.JavaCore; //导入依赖的package包/类
public static IJavaProject[] getGW4EProjects() {
	IJavaProject[] projects;
	try {
		projects = JavaCore.create(ResourceManager.getWorkspaceRoot()).getJavaProjects();
	} catch (JavaModelException e) {
		ResourceManager.logException(e);
		projects = new IJavaProject[0];
	}
	List<IJavaProject> gwps = new ArrayList<IJavaProject>();
	for (int i = 0; i < projects.length; i++) {
		if (GW4ENature.hasGW4ENature(projects[i].getProject())) {
			gwps.add(projects[i]);
		}
	}

	IJavaProject[] gwprojects = new IJavaProject[gwps.size()];
	gwps.toArray(gwprojects);
	return gwprojects;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:20,代码来源:GraphWalkerContextManager.java

示例11: getIFileFromQualifiedName

import org.eclipse.jdt.core.JavaCore; //导入依赖的package包/类
/**
 * @param project
 * @param qualifiedName
 * @return
 * @throws CoreException
 */
public static IFile getIFileFromQualifiedName(String projectname, String qualifiedName) throws CoreException {
	IProject project = getProject(projectname);
	IJavaProject jproject = JavaCore.create(project);
	IPackageFragment[] pkgs = jproject.getPackageFragments();
	String spath = qualifiedName.replace(".", "/");
	for (int i = 0; i < pkgs.length; i++) {
		if (pkgs[i].getKind() != IPackageFragmentRoot.K_SOURCE)
			continue;
		IPath path = pkgs[i].getPath().append(spath);
		IFile iFile = (IFile) ResourceManager.getResource(path.toString() + ".java");
		if (iFile != null && iFile.exists())
			return iFile;
	}
	return null;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:22,代码来源:ResourceManager.java

示例12: isFileInFolders

import org.eclipse.jdt.core.JavaCore; //导入依赖的package包/类
/**
 * Return whether the resource is in of the passed folders
 * 
 * @param resource
 * @param folders
 * @return
 */
public static boolean isFileInFolders(IFile resource, String[] folders) {
	if (resource == null)
		return false;
	IProject p = resource.getProject();
	IJavaProject javaProject = JavaCore.create(p);
	for (int i = 0; i < folders.length; i++) {
		IPath folderPath = javaProject.getPath().append(folders[i]);
		String allowedPAth = folderPath.toString();
		String resourcePath = resource.getFullPath().toString();
		if (resourcePath.startsWith(allowedPAth)) {
			return true;
		}
	}
	return false;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:23,代码来源:ResourceManager.java

示例13: testUpdatePathGeneratorInSourceFile

import org.eclipse.jdt.core.JavaCore; //导入依赖的package包/类
@Test
public void testUpdatePathGeneratorInSourceFile () throws CoreException, FileNotFoundException {
	System.out.println("XXXXXXXXXXXXXXXXXXXX testUpdatePathGeneratorInSourceFile");
	String expectedNewGenerator = "random(vertex_coverage(50))";
	 
		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);
		
		String location = JDTManager.getGW4EGeneratedAnnotationValue(cu,"value");
		IPath path = new Path (gwproject).append(location);
		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(edge_coverage(100));I;random(vertex_coverage(50));I;");
	bot.waitUntil(condition);
	}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:25,代码来源:GW4EFixesTestCase.java

示例14: assertHasSourceFolders

import org.eclipse.jdt.core.JavaCore; //导入依赖的package包/类
public void assertHasSourceFolders(String[] folders) throws JavaModelException {
	IProject project = getRoot().getProject(this.projectName);
	IJavaProject jproject = JavaCore.create(project);
	IPackageFragmentRoot[] pkgs = jproject.getPackageFragmentRoots();

	for (int i = 0; i < folders.length; i++) {
		String folder = folders[i];
		boolean found = false;
		for (int j = 0; j < pkgs.length; j++) {
			IPackageFragmentRoot pkg = pkgs[j];
			IPath path = new Path("/").append(this.projectName).append(folder);
			if (pkg.getPath().toString().equalsIgnoreCase(path.toString())) {
				found = true;
			}
			;
		}
		assertTrue("Expected folder: " + folder, found);
	}
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:20,代码来源:GW4EProject.java

示例15: 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


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