List of usage examples for org.eclipse.jdt.core IJavaProject exists
boolean exists();
From source file:org.sculptor.dsl.ui.resource.MavenClasspathUriResolver.java
License:Apache License
/** * Before forwarding to/*from ww w. j av a 2 s . co m*/ * {@link JdtClasspathUriResolver#findResourceInWorkspace(IJavaProject, URI)} * this methods uses {@link #isMavenResourceDirectory(IPackageFragment)} to * check if the given classpath URI references a resource in an excluded * Maven resource directory. */ @Override protected URI findResourceInWorkspace(IJavaProject javaProject, URI classpathUri) throws CoreException { if (javaProject.exists()) { String packagePath = classpathUri.trimSegments(1).path(); String fileName = classpathUri.lastSegment(); IPath filePath = new Path(fileName); String packageName = isEmpty(packagePath) ? "" : packagePath.substring(1).replace('/', '.'); for (IPackageFragmentRoot packageFragmentRoot : javaProject.getAllPackageFragmentRoots()) { IPackageFragment packageFragment = packageFragmentRoot.getPackageFragment(packageName); if (isMavenResourceDirectory(packageFragment)) { IResource packageFragmentResource = packageFragment.getResource(); if (packageFragmentResource instanceof IContainer) { IFile file = ((IContainer) packageFragmentResource).getFile(filePath); if (file.exists()) { return createPlatformResourceURI(file); } } } } } return super.findResourceInWorkspace(javaProject, classpathUri); }
From source file:org.sculptor.dsl.ui.resource.MavenProjectResourceSetInitializer.java
License:Apache License
public void initialize(ResourceSet resourceSet, IProject project) { if (resourceSet instanceof XtextResourceSet) { XtextResourceSet xtextResourceSet = (XtextResourceSet) resourceSet; IJavaProject javaProject = JavaCore.create(project); if (javaProject != null && javaProject.exists()) { xtextResourceSet.setClasspathUriResolver(new MavenClasspathUriResolver()); }//from w w w. j a va 2 s .c o m } }
From source file:org.seasar.dbflute.emecha.eclipse.plugin.dfassist.action.AbstractOpenActionBase.java
License:Apache License
/** * {@inheritDoc}// w ww.j a va 2s .c o m * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ public void run(IAction action) { Object obj = this._selection.getFirstElement(); if (obj instanceof IFile) { IFile file = (IFile) obj; IProject project = file.getProject(); IJavaProject javap = JavaCore.create(project); if (javap.exists() && javap.isOpen()) { String packageName = getTargetPackageName(getBasePackageName(file, javap)); String typeQualifiedName = getTargetClassName(file); try { IType findType = javap.findType(packageName, typeQualifiedName, (IProgressMonitor) null); if (findType == null || !findType.exists()) return; if (findType.isBinary()) { IClassFile classFile = findType.getClassFile(); classFile.open((IProgressMonitor) null); } else { openFileInEditor(file, findType); } } catch (JavaModelException e) { DfAssistPlugin.log(e); } catch (PartInitException e) { DfAssistPlugin.log(e); } } } }
From source file:org.seasar.dbflute.emecha.eclipse.plugin.dfassist.wizard.NewConcreteClassWizard.java
License:Apache License
protected void init(IFile file) { IProject p = file.getProject();// w w w.jav a 2 s .c om IJavaProject javap = JavaCore.create(p); if (javap.exists() && javap.isOpen()) { this.resource = file; } }
From source file:org.seasar.diigu.eclipse.util.JavaProjectClassLoader.java
License:Apache License
protected void addClasspathEntries(IJavaProject project, Set already, boolean atFirst) { already.add(project);/* w ww . j a va 2 s . co m*/ try { IContainer workspaceroot = project.getProject().getParent(); IPath path = project.getOutputLocation(); addURL(toURL(workspaceroot.getFolder(path).getLocation())); IClasspathEntry[] entries = project.getResolvedClasspath(true); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: IPath dist = entry.getOutputLocation(); if (dist != null) { addURL(toURL(workspaceroot.getFolder(dist).getLocation())); } break; case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_VARIABLE: IPath p = entry.getPath(); if (p.toFile().exists()) { addURL(toURL(p)); } else { addURL(toURL(workspaceroot.getFile(p).getLocation())); } break; case IClasspathEntry.CPE_PROJECT: IJavaProject proj = ProjectUtils.getJavaProject(entry.getPath().segment(0)); if (proj != null && proj.exists() && already.contains(proj) == false && (atFirst || entry.isExported())) { addClasspathEntries(proj, already, false); } break; default: break; } } } catch (Exception e) { DiiguPlugin.log(e); } }
From source file:org.seasar.kijimuna.core.util.JavaProjectClassLoader.java
License:Apache License
protected void addClasspathEntries(IJavaProject project, Set already, boolean atFirst) { already.add(project);//from w w w .j a v a2 s. c o m try { IContainer workspaceroot = project.getProject().getParent(); IPath path = project.getOutputLocation(); addURL(toURL(workspaceroot.getFolder(path).getLocation())); IClasspathEntry[] entries = project.getResolvedClasspath(true); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: IPath dist = entry.getOutputLocation(); if (dist != null) { addURL(toURL(workspaceroot.getFolder(dist).getLocation())); } break; case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_VARIABLE: IPath p = entry.getPath(); if (p.toFile().exists()) { addURL(toURL(p)); } else { addURL(toURL(workspaceroot.getFile(p).getLocation())); } break; case IClasspathEntry.CPE_PROJECT: IJavaProject proj = JavaCore.create(ProjectUtils.getProject(entry.getPath().segment(0))); if (proj != null && proj.exists() && already.contains(proj) == false && (atFirst || entry.isExported())) { addClasspathEntries(proj, already, false); } break; default: break; } } } catch (Exception e) { KijimunaCore.reportException(e); } }
From source file:org.seasar.s2junit4plugin.wizard.NewS2JUnit4TestCaseWizardPageOne.java
License:Apache License
private void updateBuildPathMessage() { if (fLink == null || fLink.isDisposed()) { return;// w ww .j a v a2s . com } String message = null; IPackageFragmentRoot root = getPackageFragmentRoot(); if (root != null) { try { IJavaProject project = root.getJavaProject(); if (project.exists()) { if (isJUnit4()) { if (!S2JUnit4StubUtility.is50OrHigher(project)) { message = WizardMessages.NewTestCaseWizardPageOne_linkedtext_java5required; } else if (project.findType(JUnitPlugin.JUNIT4_ANNOTATION_NAME) == null) { message = Messages.format( WizardMessages.NewTestCaseWizardPageOne_linkedtext_junit4_notonbuildpath, project.getElementName()); } } else { if (project.findType(JUnitPlugin.TEST_SUPERCLASS_NAME) == null) { message = Messages.format( WizardMessages.NewTestCaseWizardPageOne_linkedtext_junit3_notonbuildpath, project.getElementName()); } } } } catch (JavaModelException e) { } } fLink.setVisible(message != null); fImage.setVisible(message != null); if (message != null) { fLink.setText(message); } }
From source file:org.seasar.s2junit4plugin.wizard.NewS2JUnit4TestCaseWizardPageOne.java
License:Apache 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. * /*from www . j av a 2 s. co m*/ * @return the status of the validation */ protected IStatus validateIfJUnitProject() { JUnitStatus status = new JUnitStatus(); IPackageFragmentRoot root = getPackageFragmentRoot(); if (root != null) { try { IJavaProject project = root.getJavaProject(); if (project.exists()) { if (isJUnit4()) { if (!S2JUnit4StubUtility.is50OrHigher(project)) { status.setError(WizardMessages.NewTestCaseWizardPageOne_error_java5required); return status; } if (project.findType(JUnitPlugin.JUNIT4_ANNOTATION_NAME) == null) { status.setWarning(WizardMessages.NewTestCaseWizardPageOne__error_junit4NotOnbuildpath); return status; } } else { if (project.findType(JUnitPlugin.TEST_SUPERCLASS_NAME) == null) { status.setWarning(WizardMessages.NewTestCaseWizardPageOne_error_junitNotOnbuildpath); return status; } } } } catch (JavaModelException e) { } } return status; }
From source file:org.seasar.s2junit4plugin.wizard.NewS2JUnit4TypeWizardPage.java
License:Apache License
private static IStatus validateJavaTypeName(String text, IJavaProject project) { if (project == null || !project.exists()) { return JavaConventions.validateJavaTypeName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3); }/*from w w w . ja v a 2 s . co m*/ String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); String compliance = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); return JavaConventions.validateJavaTypeName(text, sourceLevel, compliance); }
From source file:org.seasar.s2junit4plugin.wizard.NewS2JUnit4TypeWizardPage.java
License:Apache License
private static IStatus validatePackageName(String text, IJavaProject project) { if (project == null || !project.exists()) { return JavaConventions.validatePackageName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3); }/* w ww . j a v a 2s . c o m*/ String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); String compliance = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); return JavaConventions.validatePackageName(text, sourceLevel, compliance); }