Java Code Examples for org.eclipse.jdt.core.IType#exists()
The following examples show how to use
org.eclipse.jdt.core.IType#exists() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PullUpRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public IType[] getCandidateTypes(final RefactoringStatus status, final IProgressMonitor monitor) throws JavaModelException { final IType declaring= getDeclaringType(); final IType[] superTypes= declaring.newSupertypeHierarchy(fOwner, monitor).getAllSupertypes(declaring); final List<IType> list= new ArrayList<IType>(superTypes.length); int binary= 0; for (int index= 0; index < superTypes.length; index++) { final IType type= superTypes[index]; if (type != null && type.exists() && !type.isReadOnly() && !type.isBinary() && !"java.lang.Object".equals(type.getFullyQualifiedName())) { //$NON-NLS-1$ list.add(type); } else { if (type != null && type.isBinary()) { binary++; } } } if (superTypes.length == 1 && superTypes[0].getFullyQualifiedName().equals("java.lang.Object")) //$NON-NLS-1$ status.addFatalError(RefactoringCoreMessages.PullUPRefactoring_not_java_lang_object); else if (superTypes.length == binary) status.addFatalError(RefactoringCoreMessages.PullUPRefactoring_no_all_binary); Collections.reverse(list); return list.toArray(new IType[list.size()]); }
Example 2
Source File: JavaASTUtils.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
public static ITypeBinding resolveType(IJavaProject javaProject, String qualifiedTypeName) throws JavaModelException { IType type = javaProject.findType(qualifiedTypeName); if (type == null || !type.exists()) { return null; } ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setProject(javaProject); IBinding[] bindings = parser.createBindings(new IJavaElement[] {type}, null); if (bindings == null) { return null; } return (ITypeBinding) bindings[0]; }
Example 3
Source File: RefactoringAvailabilityTester.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static IMember[] getPullUpMembers(final IType type) throws JavaModelException { final List<IMember> list= new ArrayList<IMember>(3); if (type.exists()) { IMember[] members= type.getFields(); for (int index= 0; index < members.length; index++) { if (isPullUpAvailable(members[index])) list.add(members[index]); } members= type.getMethods(); for (int index= 0; index < members.length; index++) { if (isPullUpAvailable(members[index])) list.add(members[index]); } members= type.getTypes(); for (int index= 0; index < members.length; index++) { if (isPullUpAvailable(members[index])) list.add(members[index]); } } return list.toArray(new IMember[list.size()]); }
Example 4
Source File: RefactoringAvailabilityTester.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public static IMember[] getPullUpMembers(final IType type) throws JavaModelException { final List<IMember> list = new ArrayList<>(3); if (type.exists()) { IMember[] members = type.getFields(); for (int index = 0; index < members.length; index++) { if (isPullUpAvailable(members[index])) { list.add(members[index]); } } members = type.getMethods(); for (int index = 0; index < members.length; index++) { if (isPullUpAvailable(members[index])) { list.add(members[index]); } } members = type.getTypes(); for (int index = 0; index < members.length; index++) { if (isPullUpAvailable(members[index])) { list.add(members[index]); } } } return list.toArray(new IMember[list.size()]); }
Example 5
Source File: FindBrokenNLSKeysAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static boolean isPotentialNLSAccessor(ICompilationUnit unit) throws JavaModelException { IType type= unit.getTypes()[0]; if (!type.exists()) return false; IField bundleNameField= getBundleNameField(type.getFields()); if (bundleNameField == null) return false; if (importsOSGIUtil(unit)) { //new school IInitializer[] initializers= type.getInitializers(); for (int i= 0; i < initializers.length; i++) { if (Modifier.isStatic(initializers[0].getFlags())) return true; } } else { //old school IMethod[] methods= type.getMethods(); for (int i= 0; i < methods.length; i++) { IMethod method= methods[i]; if (isValueAccessor(method)) return true; } } return false; }
Example 6
Source File: JavaElementUtil.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public static boolean isMainType(IType type) throws JavaModelException{ if (! type.exists()) { return false; } if (type.isBinary()) { return false; } if (type.getCompilationUnit() == null) { return false; } if (type.getDeclaringType() != null) { return false; } return isPrimaryType(type) || isCuOnlyType(type); }
Example 7
Source File: DeltaConverter.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * We don't include nested types because structural changes of nested types should not affect Xtend classes which * use top level types. * * @deprecated This method is not used anymore. */ @Deprecated protected void traverseType(IType type, NameBasedEObjectDescriptionBuilder acceptor) { try { if (type.exists()) { for (IField field : type.getFields()) { if (!Flags.isSynthetic(field.getFlags())) { String fieldName = field.getElementName(); acceptor.accept(fieldName); } } for (IMethod method : type.getMethods()) { if (!Flags.isSynthetic(method.getFlags())) { String methodName = method.getElementName(); acceptor.accept(methodName); } } } } catch (JavaModelException e) { if (LOGGER.isDebugEnabled()) LOGGER.debug(e, e); } }
Example 8
Source File: JdtTypeProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.9 */ protected IType findSecondaryTypeInSourceFolders(String packageName, final String typeName, IPackageFragmentRoot[] sourceFolders) throws JavaModelException { for(IPackageFragmentRoot sourceFolder: sourceFolders) { IPackageFragment packageFragment = sourceFolder.getPackageFragment(Strings.emptyIfNull(packageName)); if (packageFragment.exists()) { ICompilationUnit[] units = packageFragment.getCompilationUnits(); for(ICompilationUnit unit: units) { IType type = unit.getType(typeName); if (type.exists()) { return type; } } } } return null; }
Example 9
Source File: JavaProject.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
IType findType(String fullyQualifiedName, NameLookup lookup, boolean considerSecondaryTypes, IProgressMonitor progressMonitor) throws JavaModelException { NameLookup.Answer answer = lookup.findType( fullyQualifiedName, false, NameLookup.ACCEPT_ALL, considerSecondaryTypes, true, /* wait for indexes (only if consider secondary types)*/ false/*don't check restrictions*/, progressMonitor); if (answer == null) { // try to find enclosing type int lastDot = fullyQualifiedName.lastIndexOf('.'); if (lastDot == -1) return null; IType type = findType(fullyQualifiedName.substring(0, lastDot), lookup, considerSecondaryTypes, progressMonitor); if (type != null) { type = type.getType(fullyQualifiedName.substring(lastDot+1)); if (!type.exists()) { return null; } } return type; } return answer.type; }
Example 10
Source File: ProjectAwareUniqueClassNameValidator.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
private SourceTraversal doCheckUniqueInProjectSource(String packageName, String typeName, JvmDeclaredType type, List<IPackageFragmentRoot> sourceFolders) throws JavaModelException { IndexManager indexManager = JavaModelManager.getIndexManager(); for (IPackageFragmentRoot sourceFolder : sourceFolders) { if (indexManager.awaitingJobsCount() > 0) { if (!isDerived(sourceFolder.getResource())) { IPackageFragment packageFragment = sourceFolder.getPackageFragment(packageName); if (packageFragment.exists()) { for (ICompilationUnit unit : packageFragment.getCompilationUnits()) { if (!isDerived(unit.getResource())) { IType javaType = unit.getType(typeName); if (javaType.exists()) { addIssue(type, unit.getElementName()); return SourceTraversal.DUPLICATE; } } } } } } else { return SourceTraversal.INTERRUPT; } } return SourceTraversal.UNIQUE; }
Example 11
Source File: ClasspathPipelineOptionsHierarchyFactory.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@Override public PipelineOptionsHierarchy forProject( IProject project, MajorVersion version, IProgressMonitor monitor) throws PipelineOptionsRetrievalException { IJavaElement javaElement = project.getAdapter(IJavaElement.class); checkNotNull( javaElement, "%s cannot be created for a non-java project: %s", JavaProjectPipelineOptionsHierarchy.class.getSimpleName(), project); try { IJavaProject javaProject = javaElement.getJavaProject(); IType rootType = javaProject.findType(PipelineOptionsNamespaces.rootType(version)); if (rootType == null || !rootType.exists()) { return global(monitor); } return new JavaProjectPipelineOptionsHierarchy(javaProject, version, monitor); } catch (JavaModelException e) { DataflowCorePlugin.logError(e, "Error while constructing Pipeline Options Hierarchy for project %s", project.getName()); throw new PipelineOptionsRetrievalException(e); } }
Example 12
Source File: Binding2JavaModel.java From lapse-plus with GNU General Public License v3.0 | 5 votes |
/** * Finds a type by its qualified type name (dot separated). * @param jproject The java project to search in * @param str The fully qualified name (type name with enclosing type names and package (all separated by dots)) * @return The type found, or null if not existing */ public static IType findType(IJavaProject jproject, String fullyQualifiedName) throws JavaModelException { //workaround for bug 22883 IType type= jproject.findType(fullyQualifiedName); if (type != null) return type; IPackageFragmentRoot[] roots= jproject.getPackageFragmentRoots(); for (int i= 0; i < roots.length; i++) { IPackageFragmentRoot root= roots[i]; type= findType(root, fullyQualifiedName); if (type != null && type.exists()) return type; } return null; }
Example 13
Source File: MoveInnerToTopRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private RefactoringStatus checkTypeNameInPackage() throws JavaModelException { IType type= Checks.findTypeInPackage(fType.getPackageFragment(), fType.getElementName()); if (type == null || !type.exists() || fType.equals(type)) { return null; } String message= Messages.format(RefactoringCoreMessages.MoveInnerToTopRefactoring_type_exists, new String[] { BasicElementLabels.getJavaElementName(fType.getElementName()), JavaElementLabels.getElementLabel(fType.getPackageFragment(), JavaElementLabels.ALL_DEFAULT)}); return RefactoringStatus.createErrorStatus(message); }
Example 14
Source File: RenameTypeProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private RefactoringStatus checkTypesInCompilationUnit() { RefactoringStatus result= new RefactoringStatus(); if (! Checks.isTopLevel(fType)){ //the other case checked in checkTypesInPackage IType siblingType= fType.getDeclaringType().getType(getNewElementName()); if (siblingType.exists()){ String msg= Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_member_type_exists, new String[] { getNewElementLabel(), BasicElementLabels.getJavaElementName(fType.getDeclaringType().getFullyQualifiedName('.'))}); result.addError(msg, JavaStatusContext.create(siblingType)); } } return result; }
Example 15
Source File: TypeSelectionDialog2.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected void computeResult() { TypeNameMatch[] selected= fContent.getSelection(); if (selected == null || selected.length == 0) { setResult(null); return; } // If the scope is null then it got computed by the type selection component. if (fScope == null) { fScope= fContent.getScope(); } OpenTypeHistory history= OpenTypeHistory.getInstance(); List result= new ArrayList(selected.length); for (int i= 0; i < selected.length; i++) { TypeNameMatch typeInfo= selected[i]; IType type= typeInfo.getType(); if (!type.exists()) { String title= JavaUIMessages.TypeSelectionDialog_errorTitle; IPackageFragmentRoot root= typeInfo.getPackageFragmentRoot(); String containerName= JavaElementLabels.getElementLabel(root, JavaElementLabels.ROOT_QUALIFIED); String message= Messages.format(JavaUIMessages.TypeSelectionDialog_dialogMessage, new String[] { typeInfo.getFullyQualifiedName(), containerName }); MessageDialog.openError(getShell(), title, message); history.remove(typeInfo); setResult(null); } else { history.accessed(typeInfo); result.add(type); } } setResult(result); }
Example 16
Source File: PushDownRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IType[] getAbstractDestinations(IProgressMonitor monitor) throws JavaModelException { IType[] allDirectSubclasses= getHierarchyOfDeclaringClass(monitor).getSubclasses(getDeclaringType()); List<IType> result= new ArrayList<IType>(allDirectSubclasses.length); for (int index= 0; index < allDirectSubclasses.length; index++) { IType subclass= allDirectSubclasses[index]; if (subclass.exists() && !subclass.isBinary() && !subclass.isReadOnly() && subclass.getCompilationUnit() != null && subclass.isStructureKnown()) result.add(subclass); } return result.toArray(new IType[result.size()]); }
Example 17
Source File: IntroduceIndirectionRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * @param fullyQualifiedTypeName the fully qualified name of the intermediary method * @return status for type name. Use {@link #setIntermediaryMethodName(String)} to check for overridden methods. */ public RefactoringStatus setIntermediaryTypeName(String fullyQualifiedTypeName) { IType target= null; try { if (fullyQualifiedTypeName.length() == 0) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_type_not_selected_error); // find type (now including secondaries) target= getProject().findType(fullyQualifiedTypeName, new NullProgressMonitor()); if (target == null || !target.exists()) return RefactoringStatus.createErrorStatus(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_type_does_not_exist_error, BasicElementLabels.getJavaElementName(fullyQualifiedTypeName))); if (target.isAnnotation()) return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_create_in_annotation); if (target.isInterface() && !(JavaModelUtil.is18OrHigher(target.getJavaProject()) && JavaModelUtil.is18OrHigher(getProject()))) return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_create_on_interface); } catch (JavaModelException e) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_unable_determine_declaring_type); } if (target.isReadOnly()) return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_create_in_readonly); if (target.isBinary()) return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_create_in_binary); fIntermediaryType= target; return new RefactoringStatus(); }
Example 18
Source File: RenameTypeProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private RefactoringStatus checkTypesInPackage() throws CoreException { IType type= Checks.findTypeInPackage(fType.getPackageFragment(), getNewElementName()); if (type == null || ! type.exists()) return null; String msg= Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_exists, new String[] {getNewElementLabel(), JavaElementLabels.getElementLabel(fType.getPackageFragment(), JavaElementLabels.ALL_DEFAULT)}); return RefactoringStatus.createErrorStatus(msg, JavaStatusContext.create(type)); }
Example 19
Source File: ProjectAwareUniqueClassNameValidator.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
public boolean doCheckUniqueInProject(QualifiedName name, JvmDeclaredType type) throws JavaModelException { IJavaProject javaProject = javaProjectProvider.getJavaProject(type.eResource().getResourceSet()); getContext().put(ProjectAwareUniqueClassNameValidator.OUTPUT_CONFIGS, outputConfigurationProvider.getOutputConfigurations(type.eResource())); String packageName = type.getPackageName(); String typeName = type.getSimpleName(); IndexManager indexManager = JavaModelManager.getIndexManager(); List<IPackageFragmentRoot> sourceFolders = new ArrayList<>(); for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { sourceFolders.add(root); } } if (sourceFolders.isEmpty() || indexManager.awaitingJobsCount() > 0) { // still indexing - don't enter a busy wait loop but ask the source folders directly SourceTraversal sourceTraversal = doCheckUniqueInProjectSource(packageName != null ? packageName : "", typeName, type, sourceFolders); if (sourceTraversal == SourceTraversal.DUPLICATE) { return false; } else if (sourceTraversal == SourceTraversal.UNIQUE) { return true; } } Set<String> workingCopyPaths = new HashSet<>(); ICompilationUnit[] copies = getWorkingCopies(type); if (copies != null) { for (ICompilationUnit workingCopy : copies) { IPath path = workingCopy.getPath(); if (javaProject.getPath().isPrefixOf(path) && !isDerived(workingCopy.getResource())) { if (workingCopy.getPackageDeclaration(packageName).exists()) { IType result = workingCopy.getType(typeName); if (result.exists()) { addIssue(type, workingCopy.getElementName()); return false; } } workingCopyPaths.add(workingCopy.getPath().toString()); } } } // The code below is adapted from BasicSearchEnginge.searchAllSecondaryTypes // The Index is ready, query it for a secondary type char[] pkg = packageName == null ? CharOperation.NO_CHAR : packageName.toCharArray(); TypeDeclarationPattern pattern = new TypeDeclarationPattern(pkg, // CharOperation.NO_CHAR_CHAR, // top level type - no enclosing type names typeName.toCharArray(), // IIndexConstants.TYPE_SUFFIX, // SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); IndexQueryRequestor searchRequestor = new IndexQueryRequestor() { @Override public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant, AccessRuleSet access) { if (workingCopyPaths.contains(documentPath)) { return true; // filter out working copies } IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(documentPath)); if (!isDerived(file)) { addIssue(type, file.getName()); return false; } return true; } }; try { SearchParticipant searchParticipant = BasicSearchEngine.getDefaultSearchParticipant(); // Java search only IJavaSearchScope javaSearchScope = BasicSearchEngine.createJavaSearchScope(sourceFolders.toArray(new IJavaElement[0])); PatternSearchJob patternSearchJob = new PatternSearchJob(pattern, searchParticipant, javaSearchScope, searchRequestor); indexManager.performConcurrentJob(patternSearchJob, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); return true; } catch (Throwable OperationCanceledException) { return false; } }
Example 20
Source File: RenameMethodProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
/** * Initializes the refactoring from scripting arguments. * Used by {@link RenameVirtualMethodProcessor} and {@link RenameNonVirtualMethodProcessor} * * @param extended the arguments * @return the resulting status */ protected final RefactoringStatus initialize(JavaRefactoringArguments extended) { fInitialized= true; final String handle= extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT); if (handle != null) { final IJavaElement element= JavaRefactoringDescriptorUtil.handleToElement(extended.getProject(), handle, false); final String refactoring= getProcessorName(); if (element instanceof IMethod) { final IMethod method= (IMethod) element; final IType declaring= method.getDeclaringType(); if (declaring != null && declaring.exists()) { final IMethod[] methods= declaring.findMethods(method); if (methods != null && methods.length == 1 && methods[0] != null) { if (!methods[0].exists()) { return JavaRefactoringDescriptorUtil.createInputFatalStatus(methods[0], refactoring, IJavaRefactorings.RENAME_METHOD); } fMethod= methods[0]; initializeWorkingCopyOwner(); } else { return JavaRefactoringDescriptorUtil.createInputFatalStatus(null, refactoring, IJavaRefactorings.RENAME_METHOD); } } else { return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, refactoring, IJavaRefactorings.RENAME_METHOD); } } else { return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, refactoring, IJavaRefactorings.RENAME_METHOD); } } else { return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT)); } final String name= extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME); if (name != null && !"".equals(name)) { setNewElementName(name); } else { return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME)); } final String references= extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_REFERENCES); if (references != null) { fUpdateReferences= Boolean.valueOf(references).booleanValue(); } else { return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_REFERENCES)); } final String delegate= extended.getAttribute(ATTRIBUTE_DELEGATE); if (delegate != null) { fDelegateUpdating= Boolean.valueOf(delegate).booleanValue(); } else { return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_DELEGATE)); } final String deprecate= extended.getAttribute(ATTRIBUTE_DEPRECATE); if (deprecate != null) { fDelegateDeprecation= Boolean.valueOf(deprecate).booleanValue(); } else { return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_DEPRECATE)); } return new RefactoringStatus(); }