當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。