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.eclipse.modisco.java.discoverer.internal.io.library.LibraryReader.java
License:Open Source License
public void readModel(final Object source, final Model resultModel1, final BindingManager globalBindings1, final IProgressMonitor monitor) { if (source == null) { return;/*w w w . jav a 2s .c o m*/ } this.resultModel = resultModel1; this.globalBindings = globalBindings1; ClassFileParserUtils.initializePrimitiveTypes(this.factory, resultModel1, this.globalBindings); try { if (source instanceof IPackageFragmentRoot) { IPackageFragmentRoot library = (IPackageFragmentRoot) source; if (resultModel1.getName() == null || resultModel1.getName().length() == 0) { resultModel1.setName(library.getElementName()); } this.typeFinder = new TypeFinder(library.getJavaProject()); IJavaElement[] children = library.getChildren(); for (IJavaElement element : children) { IPackageFragment packageFolder = (IPackageFragment) element; if (packageFolder.getClassFiles().length > 0) { // report some feedback monitor.subTask(Messages.LibraryReader_DiscoveringTask + packageFolder.getElementName()); // parse package parsePackage(library, resultModel1, packageFolder, monitor); if (monitor.isCanceled()) { return; } } } } else if (source instanceof IClassFile) { IClassFile cf = (IClassFile) source; this.typeFinder = new TypeFinder(cf.getJavaProject()); parseClassFile(cf); } else { throw new IllegalArgumentException( "Library reader can not handle source object : " + source.toString()); //$NON-NLS-1$ } } catch (Exception e) { MoDiscoLogger.logError(e, JavaActivator.getDefault()); } }
From source file:org.eclipse.objectteams.otdt.internal.ui.wizards.listeners.NewRoleWizardPageListener.java
License:Open Source License
protected IType chooseSuperType() { IPackageFragmentRoot root = getObservedPage().getPackageFragmentRoot(); if (root == null) { return null; }//from ww w. j ava 2 s. co m IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { root.getJavaProject() }); FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(getObservedPage().getShell(), false, getObservedPage().getWizard().getContainer(), scope, IJavaSearchConstants.CLASS); dialog.setTitle(OTNewWizardMessages.NewRoleWizardPage_SuperclassDialog_title); dialog.setMessage(OTNewWizardMessages.NewRoleWizardPage_SuperclassDialog_message); dialog.setInitialPattern(getObservedPage().getSuperTypeName()); if (dialog.open() == Window.OK) { return (IType) dialog.getFirstResult(); } return null; }
From source file:org.eclipse.objectteams.otdt.internal.ui.wizards.listeners.NewRoleWizardPageListener.java
License:Open Source License
private IType chooseBaseType() { IPackageFragmentRoot root = getObservedPage().getPackageFragmentRoot(); if (root == null) { return null; }//w w w .j a va 2 s.com IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { root.getJavaProject() }); FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(getObservedPage().getShell(), false, getObservedPage().getWizard().getContainer(), scope, IJavaSearchConstants.TYPE) { IStatus status; // duplicate private field @Override protected void updateStatus(IStatus status) { this.status = status; super.updateStatus(status); } @Override protected void okPressed() { // super version is too strict, replace warning with OK in order to pass if (status.getCode() == IStatus.WARNING) updateStatus(StatusInfo.OK_STATUS); super.okPressed(); } }; dialog.setTitle(OTNewWizardMessages.NewRoleWizardPage_BaseclassDialog_title); dialog.setMessage(OTNewWizardMessages.NewRoleWizardPage_BaseclassDialog_message); dialog.setInitialPattern(((NewRoleWizardPage) getObservedPage()).getBaseClassName()); dialog.setValidator(new ISelectionStatusValidator() { public IStatus validate(Object[] selection) { if (selection != null && selection.length > 0 && selection[0] instanceof IType) return validateBaseClassName(getObservedPage().getEnclosingType(), ((IType) selection[0]).getElementName()); return StatusInfo.OK_STATUS; }; }); if (dialog.open() == FilteredTypesSelectionDialog.OK) { return (IType) dialog.getFirstResult(); } return null; }
From source file:org.eclipse.objectteams.otdt.internal.ui.wizards.listeners.NewTeamWizardPageListener.java
License:Open Source License
protected IType chooseSuperType() { IPackageFragmentRoot root = getObservedPage().getPackageFragmentRoot(); if (root == null) { return null; }/*from w ww . j a v a 2 s.c o m*/ return chooseTeam(root.getJavaProject(), getObservedPage().getShell(), getObservedPage().getWizard().getContainer(), OTNewWizardMessages.NewTeamWizardPage_ChooseSuperTypeDialog_title, OTNewWizardMessages.NewTeamWizardPage_ChooseSuperTypeDialog_description, getObservedPage().getSuperTypeName()); }
From source file:org.eclipse.objectteams.otdt.internal.ui.wizards.listeners.NewTeamWizardPageListener.java
License:Open Source License
/** * Gets called when the package field has changed. The method * validates the package name and returns the status of the validation. * The validation also updates the package fragment model. * /*ww w. ja va2 s . c om*/ * @return the status of the validation */ protected IStatus validatePackage() { StatusInfo status = new StatusInfo(); updatePackageStatusLabel(); getObservedPage().getPackageDialogField().enableButton(getObservedPage().getPackageFragmentRoot() != null); String packName = getObservedPage().getPackageName(); if (packName.trim().length() > 0) { IStatus val = NewTypeWizardPage.validatePackageName(packName, getObservedPage().getJavaProject()); if (val.getSeverity() == IStatus.ERROR) { status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName, val.getMessage())); return status; } else if (val.getSeverity() == IStatus.WARNING) { status.setWarning(Messages.format( NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName, val.getMessage())); // continue } } IPackageFragmentRoot root = getObservedPage().getPackageFragmentRoot(); if (root != null) { if (root.getJavaProject().exists() && packName.trim().length() > 0) { try { IPath rootPath = root.getPath(); IPath outputPath = root.getJavaProject().getOutputLocation(); if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) { // if the bin folder is inside of our root, dont allow to name a package // like the bin folder IPath packagePath = rootPath.append(packName.replace('.', '/')); if (outputPath.isPrefixOf(packagePath)) { status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation); return status; } } } catch (JavaModelException ex) { OTDTUIPlugin.logException("", ex); //$NON-NLS-1$ // let pass } } getObservedPage().setPackageFragment(root.getPackageFragment(packName), true); } else { status.setError(""); //$NON-NLS-1$ } return status; }
From source file:org.eclipse.objectteams.otdt.internal.ui.wizards.listeners.NewTypeWizardPageListener.java
License:Open Source License
private void chooseSuperInterfaces(ListDialogField field) { IPackageFragmentRoot root = getObservedPage().getPackageFragmentRoot(); if (root == null) { return;/*from w ww . j a va 2 s.co m*/ } SuperInterfaceSelectionDialog dialog; Shell parent = getObservedPage().getShell(); IRunnableContext context = getObservedPage().getWizard().getContainer(); NewTypeWizardPage page = getObservedPage(); IJavaProject root2 = root.getJavaProject(); dialog = new SuperInterfaceSelectionDialog(parent, context, page, root2); /* dialog = new SuperInterfaceSelectionDialog(getObservedPage().getShell(), getObservedPage().getWizard().getContainer(), getObservedPage(), root.getJavaProject()); */ dialog.setTitle(NewWizardMessages.NewTypeWizardPage_InterfacesDialog_class_title); dialog.setMessage(NewWizardMessages.NewTypeWizardPage_InterfacesDialog_message); dialog.open(); return; }
From source file:org.eclipse.objectteams.otdt.internal.ui.wizards.listeners.NewTypeWizardPageListener.java
License:Open Source License
/** * Gets called when the enclosing type name has changed. The method * validates the enclosing type and returns the status of the validation. * It also updates the enclosing type model. * //from www. ja v a2 s .c o m * @return the status of the validation */ protected IStatus validateEnclosingType() { StatusInfo status = new StatusInfo(); getObservedPage().setEnclosingType(null, true); IPackageFragmentRoot root = getObservedPage().getPackageFragmentRoot(); if (root == null) { status.setError(""); //$NON-NLS-1$ return status; } String enclName = getObservedPage().getEnclosingTypeName(); if (enclName.trim().length() == 0) { handleEnclosingTypeDialogFieldIsEmpty(status); return status; } else { if (_observedPage instanceof NewTeamWizardPage) { _observedPage.getPackageDialogField().setEnabled(false); } } try { IType type = root.getJavaProject().findType(enclName); if (type == null) { status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeNotExists); } else if (type.getCompilationUnit() == null) { status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingNotInCU); } else if (!JavaModelUtil.isEditable(type.getCompilationUnit())) { status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingNotEditable); } else if (type.equals(getObservedPage().getSuperType())) { status.setError( org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewWizardMessages.NewTypeWizardPage_same_enclosing_and_super_error); } if (status.isError()) { return status; } getObservedPage().setEnclosingType(type, true); IPackageFragmentRoot enclosingRoot = JavaModelUtil.getPackageFragmentRoot(type); if (!enclosingRoot.equals(root)) { status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_EnclosingNotInSourceFolder); } validateSuperClass(status); //enable Inlined-Checkbox getObservedPage().getInlineSelectionDialogField().setEnabled(true); return status; } catch (JavaModelException ex) { status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeNotExists); OTDTUIPlugin.logException("", ex); //$NON-NLS-1$ return status; } }
From source file:org.eclipse.objectteams.otdt.internal.ui.wizards.listeners.NewTypeWizardPageListener.java
License:Open Source License
/** * Gets called when the superclass name has changed. The method * validates the superclass name and returns the status of the validation. * // w w w. j ava 2 s . co m * @return the status of the validation */ protected IStatus validateSuperType() { StatusInfo status = new StatusInfo(); IPackageFragmentRoot root = getObservedPage().getPackageFragmentRoot(); getObservedPage().getSuperTypeDialogField().enableButton(root != null); getObservedPage().setSuperType(null); String superTypeName = getObservedPage().getSuperTypeName(); if (superTypeName.trim().length() == 0) { // accept the empty field (stands for java.lang.Object) return status; } IStatus val = NewTypeWizardPage.validateJavaTypeName(superTypeName, getObservedPage().getJavaProject()); if (val.getSeverity() == IStatus.ERROR) { status.setError(NewWizardMessages.NewTypeWizardPage_error_InvalidSuperClassName); return status; } if (root != null) { try { Type type = TypeContextChecker.parseSuperClass(superTypeName); if (type == null) { status.setError(NewWizardMessages.NewTypeWizardPage_error_InvalidSuperClassName); return status; } IType iType = resolveSuperTypeName(root.getJavaProject(), superTypeName); if (iType == null) { status.setError(NewWizardMessages.NewTypeWizardPage_error_InvalidSuperClassName); return status; } if (iType.equals(getObservedPage().getEnclosingType())) { status.setError( org.eclipse.objectteams.otdt.internal.ui.wizards.OTNewWizardMessages.NewTypeWizardPage_same_enclosing_and_super_error); } getObservedPage().setSuperType(iType); validateSuperClass(status); } catch (JavaModelException e) { status.setError(NewWizardMessages.NewTypeWizardPage_error_InvalidSuperClassName); JavaPlugin.log(e); } } else { status.setError(""); //$NON-NLS-1$ } return status; }
From source file:org.eclipse.objectteams.otdt.internal.ui.wizards.listeners.SuperInterfacesListener.java
License:Open Source License
private void chooseSuperInterfaces(ListDialogField field) { IPackageFragmentRoot root = getPage().getPackageFragmentRoot(); if (root == null) { return;//w w w.j a v a 2s. com } SuperInterfaceSelectionDialog dialog; // Note(km): need to change 3rd param from getPage().getSuperInterfacesDialogField() // to get it compiled. dialog = new SuperInterfaceSelectionDialog(getPage().getShell(), getPage().getWizard().getContainer(), getPage(), root.getJavaProject()); dialog.setTitle(NewWizardMessages.NewTypeWizardPage_InterfacesDialog_class_title); dialog.setMessage(NewWizardMessages.NewTypeWizardPage_InterfacesDialog_message); dialog.open(); return; }
From source file:org.eclipse.objectteams.otdt.internal.ui.wizards.NewTypeWizardPage.java
License:Open Source License
/** * Hook method that gets called when the type name has changed. The method validates the * type name and returns the status of the validation. * <p>//www. ja v a 2 s . c o m * Subclasses may extend this method to perform their own validation. * </p> * * @return the status of the validation */ protected IStatus typeNameChanged() { super.typeNameChanged(); StatusInfo status = new StatusInfo(); _currentType = null; String typeNameWithParameters = getTypeName(); // must not be empty if (typeNameWithParameters.length() == 0) { status.setError(NewWizardMessages.NewTypeWizardPage_error_EnterTypeName); return status; } String typeName = getTypeNameWithoutParameters(); if (typeName.indexOf('.') != -1) { status.setError(NewWizardMessages.NewTypeWizardPage_error_QualifiedName); return status; } IStatus val = validateJavaTypeName(typeName, getJavaProject()); if (val.getSeverity() == IStatus.ERROR) { status.setError( Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, val.getMessage())); return status; } else if (val.getSeverity() == IStatus.WARNING) { status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_TypeNameDiscouraged, val.getMessage())); // continue checking } // must not exist if (!isEnclosingTypeSelected()) { IPackageFragment pack = getPackageFragment(); if (pack != null) { ICompilationUnit cu = pack.getCompilationUnit(getCompilationUnitName(typeName)); _currentType = cu.getType(typeName); IResource resource = cu.getResource(); if (resource.exists()) { status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists); return status; } URI location = resource.getLocationURI(); if (location != null) { try { IFileStore store = EFS.getStore(location); if (store.fetchInfo().exists()) { status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExistsDifferentCase); return status; } } catch (CoreException e) { status.setError( Messages.format(NewWizardMessages.NewTypeWizardPage_error_uri_location_unkown, Resources.getLocationString(resource))); } } } } else { IType type = getEnclosingType(); if (type != null) { _currentType = type.getType(typeName); if (_currentType.exists()) { status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists); return status; } } } if (typeNameWithParameters != typeName) { IPackageFragmentRoot root = getPackageFragmentRoot(); if (root != null) { if (!JavaModelUtil.is50OrHigher(root.getJavaProject())) { status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeParameters); return status; } String typeDeclaration = "class " + typeNameWithParameters + " {}"; //$NON-NLS-1$//$NON-NLS-2$ ASTParser parser = ASTParser.newParser(AST.JLS4); parser.setSource(typeDeclaration.toCharArray()); parser.setProject(root.getJavaProject()); CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null); IProblem[] problems = compilationUnit.getProblems(); if (problems.length > 0) { status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, problems[0].getMessage())); return status; } } } return status; }