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


Java JavaCore.create方法代码示例

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


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

示例1: getPathWithinPackageFragment

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
/**
 * Return a path relative to its package fragment root
 * 
 * @param project
 * @param path
 * @return
 * @throws JavaModelException
 */
public static IPath getPathWithinPackageFragment(IResource ifile) throws JavaModelException {
	IProject project = ifile.getProject();
	IPath path = ifile.getFullPath();
	String[] segments = path.segments();
	IJavaProject jproject = JavaCore.create(project);
	IPackageFragment[] pkgs = jproject.getPackageFragments();
	IPath p = new Path("/");
	for (int i = 0; i < segments.length; i++) {
		for (int j = 0; j < pkgs.length; j++) {
			if (pkgs[j].getPath().equals(p)) {
				IPath ret = path.makeRelativeTo(pkgs[j].getPath());
				return ret;
			}
		}
		p = p.append(segments[i]);
	}
	return null;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:27,代码来源:ResourceManager.java

示例2: resolveClassFile

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
private static IClassFile resolveClassFile(String uriString) {
    if (uriString == null || uriString.isEmpty()) {
        return null;
    }
    try {
        URI uri = new URI(uriString);
        if (uri != null && JDT_SCHEME.equals(uri.getScheme()) && "contents".equals(uri.getAuthority())) {
            String handleId = uri.getQuery();
            IJavaElement element = JavaCore.create(handleId);
            IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
            return cf;
        }
    } catch (URISyntaxException e) {
        // ignore
    }
    return null;
}
 
开发者ID:Microsoft,项目名称:java-debug,代码行数:18,代码来源:JdtSourceLookUpProvider.java

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

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

示例5: createJavaProjectThroughActiveEditor

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
private IJavaProject createJavaProjectThroughActiveEditor() {
	
	IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	 	    if(page.getActiveEditor().getEditorInput() instanceof IFileEditorInput)
	 	    {	
	 		IFileEditorInput input = (IFileEditorInput) page.getActiveEditor().getEditorInput();
	 		IFile file = input.getFile();
	 		IProject activeProject = file.getProject();
	 		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(activeProject.getName());
	 		return JavaCore.create(project);
	 	    }
	 	    else if(page.getActiveEditor().getEditorInput() instanceof IClassFileEditorInput)
	 	    {
	  IClassFileEditorInput classFileEditorInput=(InternalClassFileEditorInput)page.getActiveEditor().getEditorInput() ;
	  IClassFile classFile=classFileEditorInput.getClassFile();
	  return classFile.getJavaProject();
	 	    }
	 	    return null;
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:20,代码来源:ValidatorUtility.java

示例6: setIJavaProject

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
private static void setIJavaProject() {
	IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	if ((page.getActiveEditor().getEditorInput().getClass()).isAssignableFrom(FileEditorInput.class)) {
		IFileEditorInput input = (IFileEditorInput) page.getActiveEditor().getEditorInput();
		IFile file = input.getFile();
		IProject activeProject = file.getProject();
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(activeProject.getName());
		iJavaProject = JavaCore.create(project);
	}
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:11,代码来源:FilterOperationClassUtility.java

示例7: getPackageFragmentRoot

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
/**
 * Return package fragment of the passed resource
 * 
 * @param project
 * @param path
 * @return
 * @throws JavaModelException
 */
public static IPackageFragmentRoot getPackageFragmentRoot(IProject project, IPackageFragment pkg)
		throws JavaModelException {
	IJavaProject jproject = JavaCore.create(project);
	IPackageFragmentRoot[] roots = jproject.getPackageFragmentRoots();
	for (int i = 0; i < roots.length; i++) {
		IPackageFragmentRoot root = roots[i];
		IPackageFragment pf = root.getPackageFragment(pkg.getElementName());
		if (pf.equals(pkg))
			return root;
	}
	return null;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:21,代码来源:ResourceManager.java

示例8: getPackageFragment

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
/**
 * Return package fragment of the passed resource
 * 
 * @param project
 * @param path
 * @return
 * @throws CoreException
 */
public static IPackageFragment getPackageFragment(IProject project, IPath path) throws CoreException {
	IFolder folder = ResourceManager.ensureFolder(project, path.toString(), new NullProgressMonitor());
	IJavaElement element = JavaCore.create(folder);
	if (element instanceof IPackageFragment) {
		return (IPackageFragment) element;
	}
	if (element instanceof IPackageFragmentRoot) {
		IPackageFragmentRoot root = (IPackageFragmentRoot) element;
		element = root.getPackageFragment("");
		return (IPackageFragment) element;
	}
	return null;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:22,代码来源:ResourceManager.java

示例9: getJavaProject

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
/**
 * If the project represents a java project, then convert it to a java project.
 * Otherwise, return null.
 */
public static IJavaProject getJavaProject(IProject project) {
    if (isJavaProject(project)) {
        return JavaCore.create(project);
    }
    return null;
}
 
开发者ID:Microsoft,项目名称:java-debug,代码行数:11,代码来源:JdtUtils.java

示例10: ensureFolderInClasspath

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
/**
 * Make sure the passed folder is in the classpath
 * 
 * @param project
 * @param folderPath
 * @param monitor
 * @return
 * @throws JavaModelException
 */
public static IClasspathEntry ensureFolderInClasspath(IProject project, String folderPath,
		IProgressMonitor monitor) throws JavaModelException {
	IJavaProject javaProject = JavaCore.create(project);

	if (folderPath.startsWith("src")) {
		handleFolderExclusion(project, folderPath);
	}

	IClasspathEntry[] entries = javaProject.getRawClasspath();

	boolean classpathentryFound = false;
	IPath folder = project.getFolder(folderPath).getFullPath();
	for (int i = 0; i < entries.length; i++) {

		if (entries[i].getPath().equals(folder)) {
			classpathentryFound = true;
			return entries[i];
		}
	}
	if (!classpathentryFound) {
		IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
		System.arraycopy(entries, 0, newEntries, 0, entries.length);
		IPath srcPath = javaProject.getPath().append(folderPath);
		IClasspathEntry srcEntry = JavaCore.newSourceEntry(srcPath, null);
		newEntries[entries.length] = JavaCore.newSourceEntry(srcEntry.getPath());
		javaProject.setRawClasspath(newEntries, monitor);
		return srcEntry;
	}
	return null;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:40,代码来源:ClasspathManager.java

示例11: handleFolderExclusion

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
/**
 * Manage source folders exclusion
 * 
 * @param project
 * @param folderPath
 * @throws JavaModelException
 */
private static void handleFolderExclusion(IProject project, String folderPath) throws JavaModelException {
	IJavaProject javaProject = JavaCore.create(project);
	IClasspathEntry[] entries = javaProject.getRawClasspath();
	IClasspathEntry rootSrcEntry = null;
	IPath srcPath = javaProject.getPath().append("src");
	for (int i = 0; i < entries.length; i++) {
		if ((entries[i].getPath().equals(srcPath))) {
			rootSrcEntry = entries[i];
			break;
		}
	}

	// 'src' folder by itslef is not in the build path ...
	if (rootSrcEntry == null)
		return;

	String relative = folderPath.substring("src/".length()).concat("/");

	StringTokenizer st = new StringTokenizer(relative, "/");
	StringBuffer sb = new StringBuffer();
	while (st.hasMoreTokens()) {
		String temp = st.nextToken();
		sb.append(temp).append("/");
		rootSrcEntry = ClasspathManager.ensureExcludedPath(project, rootSrcEntry, sb.toString());
	}

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

示例12: addProject

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
public IPath addProject(String projectName, String compliance) {
  checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$
  IProject project = createProject(projectName);
  int requiredComplianceFlag = 0;
  String compilerVersion = null;
  if ("1.5".equals(compliance)) {
    requiredComplianceFlag = AbstractCompilerTest.F_1_5;
    compilerVersion = CompilerOptions.VERSION_1_5;
  } else if ("1.6".equals(compliance)) {
    requiredComplianceFlag = AbstractCompilerTest.F_1_6;
    compilerVersion = CompilerOptions.VERSION_1_6;
  } else if ("1.7".equals(compliance)) {
    requiredComplianceFlag = AbstractCompilerTest.F_1_7;
    compilerVersion = CompilerOptions.VERSION_1_7;
  } else if (!"1.4".equals(compliance) && !"1.3".equals(compliance)) {
    throw new UnsupportedOperationException("Test framework doesn't support compliance level: " + compliance);
  }
  if (requiredComplianceFlag != 0) {
    if ((AbstractCompilerTest.getPossibleComplianceLevels() & requiredComplianceFlag) == 0)
      throw new RuntimeException("This test requires a " + compliance + " JRE");
    IJavaProject javaProject = JavaCore.create(project);
    Map options = new HashMap();
    options.put(CompilerOptions.OPTION_Compliance, compilerVersion);
    options.put(CompilerOptions.OPTION_Source, compilerVersion);
    options.put(CompilerOptions.OPTION_TargetPlatform, compilerVersion);
    javaProject.setOptions(options);
  }
  return project.getFullPath();
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:30,代码来源:TestingEnvironment.java

示例13: createProject

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
public static IJavaProject createProject(String name) throws CoreException {

		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
		IProject project = root.getProject(name);
		if (!project.exists()) {
			project.create(new NullProgressMonitor());
		} else {
			project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
		}

		if (!project.isOpen()) {
			project.open(new NullProgressMonitor());
		}

		IFolder binFolder = project.getFolder("bin");
		if (!binFolder.exists()) {
			createFolder(binFolder, false, true, new NullProgressMonitor());
		}
		IPath outputLocation = binFolder.getFullPath();

		addNatureToProject(project, JavaCore.NATURE_ID, new NullProgressMonitor());

		IJavaProject jproject = JavaCore.create(project);
		jproject.setOutputLocation(outputLocation, new NullProgressMonitor());

		IClasspathEntry[] entries = PreferenceConstants.getDefaultJRELibrary();

		jproject.setRawClasspath(entries, new NullProgressMonitor());

		return jproject;
	}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:32,代码来源:ProjectHelper.java

示例14: getPackageFragmentRoot

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
/**
 * Return a package fragment with the passed path
 * 
 * @param project
 * @param path
 * @return
 * @throws JavaModelException
 */
public static IPackageFragmentRoot getPackageFragmentRoot(IProject project, IPath path) throws JavaModelException {
	IJavaProject javaProject = JavaCore.create(project);
	IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
	for (int i = 0; i < roots.length; i++) {
		if (roots[i].getPath().equals(path))
			return roots[i];
	}
	return null;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:18,代码来源:JDTManager.java

示例15: fullBuild

import org.eclipse.jdt.core.JavaCore; //导入方法依赖的package包/类
protected void fullBuild(IProgressMonitor monitor) throws CoreException{
	Visuflow.getDefault().getLogger().info("Build Start");
	String targetFolder = "sootOutput";
	IJavaProject project = JavaCore.create(getProject());
	IResourceDelta delta = getDelta(project.getProject());
	if (delta == null || !delta.getAffectedChildren()[0].getProjectRelativePath().toString().equals(targetFolder)) {
		classpath = getSootCP(project);
		String location = GlobalSettings.get("Target_Path");
		IFolder folder = project.getProject().getFolder(targetFolder);

		// at this point, no resources have been created
		if (!folder.exists()) {
			// Changed to force because of bug id vis-119
			folder.create(IResource.FORCE, true, monitor);

		} else {
			for (IResource resource : folder.members()) {
				resource.delete(IResource.FORCE, monitor);
			}
		}
		classpath = location + classpath;
		String[] sootString = new String[] { "-cp", classpath, "-exclude", "javax", "-allow-phantom-refs", "-no-bodies-for-excluded", "-process-dir",
				location, "-src-prec", "only-class", "-w", "-output-format", "J", "-keep-line-number", "-output-dir",
				folder.getLocation().toOSString()/* , "tag.ln","on" */ };
		ICFGStructure icfg = new ICFGStructure();
		JimpleModelAnalysis analysis = new JimpleModelAnalysis();
		analysis.setSootString(sootString);
		List<VFClass> jimpleClasses = new ArrayList<>();
		try {
			analysis.createICFG(icfg, jimpleClasses);
			fillDataModel(icfg, jimpleClasses);
		} catch(Exception e) {
			logger.error("Couldn't execute analysis", e);
		}

		folder.refreshLocal(IResource.DEPTH_INFINITE, monitor);
	}
}
 
开发者ID:VisuFlow,项目名称:visuflow-plugin,代码行数:39,代码来源:JimpleBuilder.java


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