private ImportReferencesCollector(IJavaProject project, CompilationUnit astRoot, Region rangeLimit, Collection resultingTypeImports, Collection resultingStaticImports) { super(true); fTypeImports= resultingTypeImports; fStaticImports= resultingStaticImports; fSubRange= rangeLimit; if (project == null || !JavaModelUtil.is50OrHigher(project)) { fStaticImports= null; // do not collect } fASTRoot= astRoot; }
private boolean isSameType(ITypeBinding binding, String qualifier, String name) { String qualifiedName= JavaModelUtil.concatenateName(qualifier, name); return binding.getQualifiedName().equals(qualifiedName); }
IMethod method= findMethod(name, paramTypes, isConstructor, type); if (method != null) { return method; IMethod res= findMethodInHierarchy(hierarchy, superClass, name, paramTypes, isConstructor); if (res != null) { return res; IType[] superInterfaces= hierarchy.getSuperInterfaces(type); for (int i= 0; i < superInterfaces.length; i++) { IMethod res= findMethodInHierarchy(hierarchy, superInterfaces[i], name, paramTypes, false); if (res != null) { return res;
private boolean isRequiredOrGreaterVMInstall(IVMInstall install) { if (install instanceof IVMInstall2) { String compliance= JavaModelUtil.getCompilerCompliance((IVMInstall2) install, JavaCore.VERSION_1_3); return !JavaModelUtil.isVersionLessThan(compliance, fRequiredVersion); } return false; }
/** * Checks if the given project or workspace has source compliance 1.5 or greater. * * @param project the project to test or <code>null</code> to test the workspace settings * @return <code>true</code> if the given project or workspace has source compliance 1.5 or greater. */ public static boolean is50OrHigher(IJavaProject project) { return is50OrHigher(getSourceCompliance(project)); }
private boolean is50orGreaterVMInstall(IVMInstall install) { if (install instanceof IVMInstall2) { String compliance= JavaModelUtil.getCompilerCompliance((IVMInstall2) install, JavaCore.VERSION_1_3); return JavaModelUtil.is50OrHigher(compliance); } return false; }
public static IMethod getGetter(IField field) throws JavaModelException{ String getterName= getGetterName(field, EMPTY, true); IMethod primaryCandidate= JavaModelUtil.findMethod(getterName, new String[0], false, field.getDeclaringType()); if (! JavaModelUtil.isBoolean(field) || (primaryCandidate != null && primaryCandidate.exists())) return primaryCandidate; //bug 30906 describes why we need to look for other alternatives here (try with get... for booleans) String secondCandidateName= getGetterName(field, EMPTY, false); return JavaModelUtil.findMethod(secondCandidateName, new String[0], false, field.getDeclaringType()); }
private IPackageFragmentRoot getPackageFragmentRoot(Object element) { if (element instanceof PackageFragmentRootContainer) { // return first package fragment root from the container PackageFragmentRootContainer cp= (PackageFragmentRootContainer)element; Object[] roots= cp.getPackageFragmentRoots(); if (roots.length > 0) return (IPackageFragmentRoot)roots[0]; // non resolvable - return null return null; } return JavaModelUtil.getPackageFragmentRoot((IJavaElement)element); }
IType superClass= hierarchy.getSuperclass(type); if (superClass != null) { IMethod res= JavaModelUtil.findMethodInHierarchy(hierarchy, superClass, name, paramTypes, false); if (res != null && !Flags.isPrivate(res.getFlags()) && JavaModelUtil.isVisibleInHierarchy(res, type.getPackageFragment())) { if (JdtFlags.isAbstract(res)) { return JavaElementImageDescriptor.IMPLEMENTS; IMethod res= JavaModelUtil.findMethodInHierarchy(hierarchy, interfaces[i], name, paramTypes, false); if (res != null) { if (JdtFlags.isAbstract(res)) {
@Override protected RefactoringStatus validateNewName(String newName) { String fullName= JavaModelUtil.getRenamedCUName(getCompilationUnit(), newName); return super.validateNewName(fullName); }
@Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { JavaModelUtil.applyEdit(unit, rewrite.rewriteImports(monitor), false, null); } catch (CoreException e) { throw new InvocationTargetException(e); } } });
/** * Helper method that tests if an classpath entry can be found in a * container. <code>null</code> is returned if the entry can not be found * or if the container does not allows the configuration of source * attachments * @param jproject The container's parent project * @param containerPath The path of the container * @param libPath The path of the library to be found * @return IClasspathEntry A classpath entry from the container of * <code>null</code> if the container can not be modified. * @throws JavaModelException thrown if accessing the container failed */ public static IClasspathEntry getClasspathEntryToEdit(IJavaProject jproject, IPath containerPath, IPath libPath) throws JavaModelException { IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject); ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0)); if (container != null && initializer != null && initializer.canUpdateClasspathContainer(containerPath, jproject)) { return findEntryInContainer(container, libPath); } return null; // attachment not possible }
/** * Resolves a type name in the context of the declaring type. * * @param refTypeSig the type name in signature notation (for example 'QVector') this can also be an array type, but dimensions will be ignored. * @param declaringType the context for resolving (type where the reference was made in) * @return returns the fully qualified type name or build-in-type name. if a unresolved type couldn't be resolved null is returned * @throws JavaModelException thrown when the type can not be accessed */ public static String getResolvedTypeName(String refTypeSig, IType declaringType) throws JavaModelException { return getResolvedTypeName(refTypeSig, declaringType, '.'); }
private String getVMVersion(IVMInstall vm) { if (vm instanceof IVMInstall2) { IVMInstall2 vm2= (IVMInstall2) vm; return JavaModelUtil.getCompilerCompliance(vm2, null); } else { return null; } } }
boolean is18OrHigher= JavaModelUtil.is18OrHigher(meth.getJavaProject()); buf.append(is18OrHigher ? '-' : '('); String[] params= meth.getParameterTypes(); String fullName= JavaModelUtil.getResolvedTypeName(curr, declaringType); if (fullName == null) { // e.g. a type parameter "QE;" fullName= Signature.toString(Signature.getElementType(curr));
public static IMethod getSetter(IField field) throws JavaModelException{ String[] args= new String[] { field.getTypeSignature() }; return JavaModelUtil.findMethod(getSetterName(field, EMPTY), args, false, field.getDeclaringType()); }
boolean canEditEncoding = true; try { entry = JavaModelUtil.getClasspathEntry(root); } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("getting ClasspathEntry from the PackageFragmentRoot ", e); entry = JavaModelUtil.findEntryInContainer(container, root.getPath()); if (entry == null) { throw constructCoreException(Messages.format("Cannot find the ClasspathEntry from container '{0}'.", containerName));
private RefactoringStatus checkNewAccessor(IMethod existingAccessor, String newAccessorName) throws CoreException{ RefactoringStatus result= new RefactoringStatus(); IMethod accessor= JavaModelUtil.findMethod(newAccessorName, existingAccessor.getParameterTypes(), false, fField.getDeclaringType()); if (accessor == null || !accessor.exists()) return null; String message= Messages.format(RefactoringCoreMessages.RenameFieldRefactoring_already_exists, new String[]{JavaElementUtil.createMethodSignature(accessor), JavaModelUtil.getFullyQualifiedName(fField.getDeclaringType())}); result.addError(message, JavaStatusContext.create(accessor)); return result; }
public static IMethod getGetter(IField field) throws JavaModelException{ String getterName= getGetterName(field, EMPTY, true); IMethod primaryCandidate= JavaModelUtil.findMethod(getterName, new String[0], false, field.getDeclaringType()); if (! JavaModelUtil.isBoolean(field) || (primaryCandidate != null && primaryCandidate.exists())) return primaryCandidate; //bug 30906 describes why we need to look for other alternatives here (try with get... for booleans) String secondCandidateName= getGetterName(field, EMPTY, false); return JavaModelUtil.findMethod(secondCandidateName, new String[0], false, field.getDeclaringType()); }
private IPackageFragmentRoot getPackageFragmentRoot(Object element) { if (element instanceof PackageFragmentRootContainer) { // return first package fragment root from the container PackageFragmentRootContainer cp= (PackageFragmentRootContainer)element; Object[] roots= cp.getPackageFragmentRoots(); if (roots.length > 0) return (IPackageFragmentRoot)roots[0]; // non resolvable - return null return null; } return JavaModelUtil.getPackageFragmentRoot((IJavaElement)element); }