List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getJavaProject
IJavaProject getJavaProject();
null
if this element is not contained in any Java project (for instance, the IJavaModel
is not contained in any Java project). From source file:org.jetbrains.kotlin.wizards.FileCreationOp.java
License:Apache License
public static IFile makeFile(IPackageFragment packageFragment, IPackageFragmentRoot sourceDir, String unitName) {//from w w w. j a va 2s .c om IPath path = packageFragment.getPath().append(getCompilationUnitName(unitName)); IProject project = sourceDir.getJavaProject().getProject(); return project.getFile(path.makeRelativeTo(project.getFullPath())); }
From source file:org.jetbrains.kotlin.wizards.NewUnitWizard.java
License:Apache License
@Nullable public static IFile createKotlinSourceFile(@NotNull IPackageFragmentRoot root, @NotNull IPackageFragment packageFragment, @NotNull String fileName, @NotNull String contents, @NotNull Shell shell, @NotNull IRunnableContext runnableContext) throws InvocationTargetException, InterruptedException { FileCreationOp operation = new FileCreationOp(root, packageFragment, fileName, contents, shell); runnableContext.run(true, true, operation); IProject project = root.getJavaProject().getProject(); addKotlinModelSpecificConfiguration(project); KotlinRuntimeConfigurationSuggestor.suggestForProject(project); return operation.getResult(); }
From source file:org.jnario.spec.ui.wizards.NewSpecWizardPageOne.java
License:Open Source License
private IType chooseClassToTestType() { IPackageFragmentRoot root = getPackageFragmentRoot(); if (root == null) return null; IJavaElement[] elements = new IJavaElement[] { root.getJavaProject() }; IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements); try {/*from w w w. ja v a 2 s . c o m*/ SelectionDialog dialog = JavaUI.createTypeDialog(getShell(), getWizard().getContainer(), scope, IJavaElementSearchConstants.CONSIDER_CLASSES_AND_ENUMS, false, getClassUnderTestText()); dialog.setTitle(WizardMessages.NewTestCaseWizardPageOne_class_to_test_dialog_title); dialog.setMessage(WizardMessages.NewTestCaseWizardPageOne_class_to_test_dialog_message); if (dialog.open() == Window.OK) { Object[] resultArray = dialog.getResult(); if (resultArray != null && resultArray.length > 0) return (IType) resultArray[0]; } } catch (JavaModelException e) { JUnitPlugin.log(e); } return null; }
From source file:org.jnario.spec.ui.wizards.NewSpecWizardPageOne.java
License:Open Source License
protected IStatus classUnderTestChanged() { JUnitStatus status = new JUnitStatus(); fClassUnderTest = null;/*from www .ja v a2s. c o m*/ IPackageFragmentRoot root = getPackageFragmentRoot(); if (root == null) { return status; } String classToTestName = getClassUnderTestText(); if (classToTestName.length() == 0) { return status; } IStatus val = JavaConventionsUtil.validateJavaTypeName(classToTestName, root); if (val.getSeverity() == IStatus.ERROR) { status.setError(WizardMessages.NewTestCaseWizardPageOne_error_class_to_test_not_valid); return status; } IPackageFragment pack = getPackageFragment(); // can be null try { IType type = resolveClassNameToType(root.getJavaProject(), pack, classToTestName); if (type == null) { status.setError(WizardMessages.NewTestCaseWizardPageOne_error_class_to_test_not_exist); return status; } if (type.isInterface()) { status.setWarning( Messages.format(WizardMessages.NewTestCaseWizardPageOne_warning_class_to_test_is_interface, BasicElementLabels.getJavaElementName(classToTestName))); } if (pack != null && !JUnitStubUtility.isVisible(type, pack)) { status.setWarning( Messages.format(WizardMessages.NewTestCaseWizardPageOne_warning_class_to_test_not_visible, BasicElementLabels.getJavaElementName(classToTestName))); } fClassUnderTest = type; fPage2.setClassUnderTest(fClassUnderTest); } catch (JavaModelException e) { status.setError(WizardMessages.NewTestCaseWizardPageOne_error_class_to_test_not_valid); } return status; }
From source file:org.jnario.spec.ui.wizards.NewSpecWizardPageOne.java
License:Open Source License
/** * The method is called when the container has changed to validate if the project * is suited for the JUnit test class. Clients can override to modify or remove that validation. * * @return the status of the validation// www.jav a2 s. c o m */ protected IStatus validateIfJUnitProject() { JUnitStatus status = new JUnitStatus(); IPackageFragmentRoot root = getPackageFragmentRoot(); if (root != null) { try { IJavaProject project = root.getJavaProject(); if (project.exists()) { if (!JUnitStubUtility.is50OrHigher(project)) { status.setError(WizardMessages.NewTestCaseWizardPageOne_error_java5required); return status; } if (project.findType(JUnitCorePlugin.JUNIT4_ANNOTATION_NAME) == null) { status.setWarning(WizardMessages.NewTestCaseWizardPageOne__error_junit4NotOnbuildpath); return status; } } } catch (JavaModelException e) { } } return status; }
From source file:org.limy.eclipse.qalab.ant.UmlgraphCreator.java
License:Open Source License
/** * @param targetEl// ww w .j a v a2 s. c o m * @param env * @param targetProject * @return Element???? true * @throws CoreException */ private boolean createJavadocElement(XmlElement targetEl, LimyQalabEnvironment env, IProject targetProject) throws CoreException { XmlElement javadocEl = createElement(targetEl, "javadoc"); IJavaProject javaProject = JavaCore.create(targetProject); IPreferenceStore store = env.getStore(); IPackageFragmentRoot[] roots = javaProject.getAllPackageFragmentRoots(); // v?WFNg\?[XfBNg boolean isEmpty = true; for (IPackageFragmentRoot root : roots) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE && root.getJavaProject().equals(javaProject)) { IResource rootDir = root.getResource(); if (((IContainer) rootDir).members().length > 0) { isEmpty = false; } XmlElement fileEl = createElement(javadocEl, "fileset", "dir", rootDir.getLocation().toString()); fileEl.setAttribute("includes", "**/*.java"); fileEl.setAttribute("excludes", "**/*Test.java"); } } // \?[Xt@C??javadocvf? if (isEmpty) { targetEl.removeChild(javadocEl); return false; } javadocEl.setAttribute("destDir", "${dest.dir}/javadoc/" + targetProject.getName()); javadocEl.setAttribute("Encoding", "${src.encoding}"); javadocEl.setAttribute("classpathref", "all.classpath"); javadocEl.setAttribute("private", "false"); javadocEl.setAttribute("packagenames", "*"); javadocEl.setAttribute("useexternalfile", "yes"); XmlElement docletEl = createElement(javadocEl, "doclet"); docletEl.setAttribute("name", "gr.spinellis.umlgraph.doclet.UmlGraph"); docletEl.setAttribute("path", LimyQalabPluginUtils.getResourcePath("lib/UmlGraph.jar")); addParam(docletEl, "-collpackages", "java.util.*"); if (store.getBoolean(LimyQalabConstants.UMLGRAPH_INFERREL)) { addParam(docletEl, "-inferrel", null); } if (store.getBoolean(LimyQalabConstants.UMLGRAPH_HORIZONTAL)) { addParam(docletEl, "-horizontal", null); } String resources = env.getStore().getString(LimyQalabConstants.EXCLUDE_JDEPENDS); String[] excludes = resources.split("\n"); for (String exclude : excludes) { // ?K\\L java.* => ^java\..* // org.apache.* => ^org\.apache\..* if (exclude.length() > 0) { addParam(docletEl, "-hide", "^" + exclude.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*")); } } return true; }
From source file:org.limy.eclipse.qalab.common.LimyQalabEnvironment.java
License:Open Source License
/** * Javav?WFNg?o?fBNg?B//from ww w . ja v a2s.c o m * @param env * @param enableRef Q?v?WFNg? * @return Javav?WFNg\?[XfBNg * @throws JavaModelException JavafO */ private Collection<IPath> privateGetBinPaths(LimyQalabEnvironment env, boolean enableRef) throws JavaModelException { IJavaProject project = env.getJavaProject(); Set<IPath> results = new HashSet<IPath>(); if (enableRef && store.getBoolean(LimyQalabConstants.ENABLE_REFPROJECT)) { // Q?v?WFNgL?? IPackageFragmentRoot[] roots = project.getAllPackageFragmentRoots(); for (IPackageFragmentRoot refRoot : roots) { if (refRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { // Q?v?WFNg?[v IJavaProject refProject = refRoot.getJavaProject(); LimyQalabUtils.appendProjectBinPaths(refProject, results); } } } else { // ftHgv?WFNg?ofBNg LimyQalabUtils.appendProjectBinPaths(project, results); } return results; }
From source file:org.limy.eclipse.qalab.common.LimyQalabJavaUtils.java
License:Open Source License
/** * PackageFragmentRoot?pX?B// w w w.j a va 2 s . c o m * @param fragment PackageFragmentRoot * @return * @throws CoreException */ public static String getExternalLocation(IPackageFragmentRoot fragment) throws CoreException { String location = null; if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) { // v?WFNgQ?v?WFNg\?[XfBNg IPath outputLocation = fragment.getRawClasspathEntry().getOutputLocation(); if (outputLocation != null) { // \?[XpXL?o?w?? location = LimyQalabUtils.createFullPath(fragment.getJavaProject(), outputLocation); } else { // \?[XpXL?o?w???Av?WFNgftHg?o?gp location = LimyQalabUtils.createFullPath(fragment.getJavaProject(), fragment.getJavaProject().getOutputLocation()); } } else { // v?WFNgclasspathQ?v?WFNgExportCu IResource resource = fragment.getResource(); if (resource != null) { location = resource.getLocation().toString(); } else { // Variablewjart@Cresource = null IPath path = fragment.getRawClasspathEntry().getPath(); if (!path.toString().startsWith("org.eclipse.jdt.launching.JRE_CONTAINER")) { // JREOJARt@C?iVariablew?jNXpX location = fragment.getPath().toString(); } } } return location; }
From source file:org.melord.pde.explorer.handlers.OpenExplorerHandler.java
License:Apache License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); ISelection sel = window.getSelectionService().getSelection(); if (sel instanceof IStructuredSelection) { Object obj = ((IStructuredSelection) sel).getFirstElement(); IResource resource = null;/*from www . jav a 2s. com*/ String path = null; String file = null; // common resource file if (obj instanceof IFile) { resource = (IResource) obj; file = resource.getLocation().toOSString(); path = file.substring(0, file.lastIndexOf(File.separator)); } else if (obj instanceof IProject) { IProject prj = (IProject) obj; path = prj.getLocation().toOSString(); } // other resource such as folder,project else if (obj instanceof IResource) { resource = (IResource) obj; path = resource.getLocation().toOSString(); } // explorer java element, contain field,method,package else if (obj instanceof IJavaElement) { // java project. if (obj instanceof IJavaProject) { path = ((IJavaProject) obj).getProject().getLocation().toOSString(); } // jar resource is null else if (obj instanceof JarPackageFragmentRoot) { file = ((IPackageFragmentRoot) obj).getPath().toOSString(); // get folder path = file.substring(0, file.lastIndexOf(File.separator)); } else if (obj instanceof IPackageFragmentRoot) { // src folder IPackageFragmentRoot src = ((IPackageFragmentRoot) obj); IProject p = src.getJavaProject().getProject(); String prjPath = p.getLocation().toOSString(); path = new File(prjPath, src.getElementName()).getAbsolutePath(); // System.out.println(path); } else if (obj instanceof IPackageFragment) {// other : package resource = ((IPackageFragment) obj).getResource(); path = resource.getLocation().toOSString(); } else {// member:filed: resource = ((IJavaElement) obj).getResource(); file = resource.getLocation().toOSString(); // get folder path = file.substring(0, file.lastIndexOf(File.separator)); } } // explorer team ui resource else if (obj instanceof ISynchronizeModelElement) { resource = ((ISynchronizeModelElement) obj).getResource(); } // process if (path != null) { // System.out.println(path); String cmd = null; try { cmd = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.EXPLORER_CMD) .trim(); if (cmd.toLowerCase().startsWith("explorer")) { String winCmd = String.format("%s %s", cmd, path); if (file != null) { winCmd = String.format("%s /select,%s", cmd, file); } Runtime.getRuntime().exec(winCmd); return null; } Runtime.getRuntime().exec(cmd.trim() + " " + path); //$NON-NLS-1$ } catch (IOException e) { // e.printStackTrace(); } } } return null; }
From source file:org.neuro4j.studio.core.diagram.wizards.customblock.CustomBlockParametersWizardPage.java
License:Apache License
protected IStatus superClassChanged(DialogField field) { StatusInfo status = new StatusInfo(); IPackageFragmentRoot root = getPackageFragmentRoot(); ((StringButtonDialogField) field).enableButton(true); // this.fSuperClassStubTypeContext = null; String sclassName = getSuperClass(field); if (sclassName.length() == 0) { return status; }/*ww w.j a v a 2 s.c o m*/ if (root != null) { Type type = TypeContextChecker.parseSuperClass(sclassName); if (type == null) { status.setError(NewWizardMessages.NewTypeWizardPage_error_InvalidSuperClassName); return status; } if (((type instanceof ParameterizedType)) && (!JavaModelUtil.is50OrHigher(root.getJavaProject()))) { status.setError(NewWizardMessages.NewTypeWizardPage_error_SuperClassNotParameterized); return status; } } else { status.setError(""); } return status; }