Java Code Examples for org.eclipse.jdt.core.Flags#isPrivate()
The following examples show how to use
org.eclipse.jdt.core.Flags#isPrivate() .
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: OpenSuperImplementationAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private boolean checkMethod(IMethod method) { try { int flags= method.getFlags(); if (!Flags.isStatic(flags) && !Flags.isPrivate(flags)) { IType declaringType= method.getDeclaringType(); if (SuperTypeHierarchyCache.hasInCache(declaringType)) { if (findSuperImplementation(method) == null) { return false; } } return true; } } catch (JavaModelException e) { if (!e.isDoesNotExist()) { JavaPlugin.log(e); } } return false; }
Example 2
Source File: MethodOverrideTester.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Finds an overriding method in a type. * @param overridingType The type to find methods in * @param overridden The overridden method * @return The overriding method or <code>null</code> if no method is overriding. * @throws JavaModelException if a problem occurs */ public IMethod findOverridingMethodInType(IType overridingType, IMethod overridden) throws JavaModelException { int flags= overridden.getFlags(); if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overridden.isConstructor()) return null; IMethod[] overridingMethods= overridingType.getMethods(); for (int i= 0; i < overridingMethods.length; i++) { IMethod overriding= overridingMethods[i]; flags= overriding.getFlags(); if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overriding.isConstructor()) continue; if (isSubsignature(overriding, overridden)) { return overriding; } } return null; }
Example 3
Source File: SelfEncapsulateFieldInputPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private Object[] createData(int visibility) { String pub= RefactoringMessages.SelfEncapsulateFieldInputPage_public; String pro= RefactoringMessages.SelfEncapsulateFieldInputPage_protected; String def= RefactoringMessages.SelfEncapsulateFieldInputPage_default; String priv= RefactoringMessages.SelfEncapsulateFieldInputPage_private; String[] labels= null; Integer[] data= null; if (Flags.isPrivate(visibility)) { labels= new String[] { pub, pro, def, priv }; data= new Integer[] {new Integer(Flags.AccPublic), new Integer(Flags.AccProtected), new Integer(0), new Integer(Flags.AccPrivate) }; } else if (Flags.isProtected(visibility)) { labels= new String[] { pub, pro }; data= new Integer[] {new Integer(Flags.AccPublic), new Integer(Flags.AccProtected)}; } else { labels= new String[] { pub, def }; data= new Integer[] {new Integer(Flags.AccPublic), new Integer(0)}; } return new Object[] {labels, data}; }
Example 4
Source File: TypeHierarchyContentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private boolean hasCompatibleMethod(IMethod filterMethod, IType typeToFindIn) throws JavaModelException { int flags= filterMethod.getFlags(); if (Flags.isPrivate(flags) || Flags.isStatic(flags) || filterMethod.isConstructor()) return false; synchronized (fTypeHierarchyLifeCycleListener) { boolean filterMethodOverrides= initializeMethodOverrideTester(filterMethod, typeToFindIn); IMethod[] methods= typeToFindIn.getMethods(); for (int i= 0; i < methods.length; i++) { IMethod curr= methods[i]; flags= curr.getFlags(); if (Flags.isPrivate(flags) || Flags.isStatic(flags) || curr.isConstructor()) continue; if (isCompatibleMethod(filterMethod, curr, filterMethodOverrides)) { return true; } } return false; } }
Example 5
Source File: AbstractHierarchyViewerSorter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private IType getDefiningType(IMethod method) throws JavaModelException { int flags= method.getFlags(); if (Flags.isPrivate(flags) || Flags.isStatic(flags) || method.isConstructor()) { return null; } IType declaringType= method.getDeclaringType(); ITypeHierarchy hierarchy= getHierarchy(declaringType); if (hierarchy != null) { MethodOverrideTester tester= new MethodOverrideTester(declaringType, hierarchy); IMethod res= tester.findDeclaringMethod(method, true); if (res != null) { return res.getDeclaringType(); } } return null; }
Example 6
Source File: JavaModelUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Evaluates if a member in the focus' element hierarchy is visible from * elements in a package. * @param member The member to test the visibility for * @param pack The package of the focus element focus * @return returns <code>true</code> if the member is visible from the package * @throws JavaModelException thrown when the member can not be accessed */ public static boolean isVisibleInHierarchy(IMember member, IPackageFragment pack) throws JavaModelException { int type= member.getElementType(); if (type == IJavaElement.INITIALIZER || (type == IJavaElement.METHOD && member.getElementName().startsWith("<"))) { //$NON-NLS-1$ return false; } int otherflags= member.getFlags(); IType declaringType= member.getDeclaringType(); if (Flags.isPublic(otherflags) || Flags.isProtected(otherflags) || (declaringType != null && isInterfaceOrAnnotation(declaringType))) { return true; } else if (Flags.isPrivate(otherflags)) { return false; } IPackageFragment otherpack= (IPackageFragment) member.getAncestor(IJavaElement.PACKAGE_FRAGMENT); return (pack != null && pack.equals(otherpack)); }
Example 7
Source File: XtendProposalProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public boolean accept(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { if (TypeMatchFilters.isNotInternal(getSearchFor()).accept(modifiers, packageName, simpleTypeName, enclosingTypeNames, path) && TypeMatchFilters.isAcceptableByPreference().accept(modifiers, packageName, simpleTypeName, enclosingTypeNames, path)) { XtendFile file = (XtendFile) context.getRootModel(); final char[] contextPackageName = Strings.emptyIfNull(file.getPackage()).toCharArray(); if ("org.eclipse.xtend.lib".equals(String.valueOf(packageName))) { if ("Property".equals(String.valueOf(simpleTypeName))||"Data".equals(String.valueOf(simpleTypeName))) { return false; } } if (Flags.isPublic(modifiers)) { return true; } if (Flags.isPrivate(modifiers)) { return false; } if (Arrays.equals(contextPackageName, packageName)) { return true; } } return false; }
Example 8
Source File: MembersOrderPreferenceCache.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public int getVisibilityIndex(int modifierFlags) { if (fVisibilityOffsets == null) { fVisibilityOffsets= getVisibilityOffsets(); } int kind= DEFAULT_INDEX; if (Flags.isPublic(modifierFlags)) { kind= PUBLIC_INDEX; } else if (Flags.isProtected(modifierFlags)) { kind= PROTECTED_INDEX; } else if (Flags.isPrivate(modifierFlags)) { kind= PRIVATE_INDEX; } return fVisibilityOffsets[kind]; }
Example 9
Source File: JavaElementImageProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static ImageDescriptor getInnerEnumImageDescriptor(boolean isInInterfaceOrAnnotation, int flags) { if (Flags.isPublic(flags) || isInInterfaceOrAnnotation) return JavaPluginImages.DESC_OBJS_ENUM; else if (Flags.isPrivate(flags)) return JavaPluginImages.DESC_OBJS_ENUM_PRIVATE; else if (Flags.isProtected(flags)) return JavaPluginImages.DESC_OBJS_ENUM_PROTECTED; else return JavaPluginImages.DESC_OBJS_ENUM_DEFAULT; }
Example 10
Source File: ChangeSignatureProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected int getDescriptorFlags() { int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE; try { if (!Flags.isPrivate(fMethod.getFlags())) flags|= RefactoringDescriptor.MULTI_CHANGE; final IType declaring= fMethod.getDeclaringType(); if (declaring.isAnonymous() || declaring.isLocal()) flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; } catch (JavaModelException exception) { JavaPlugin.log(exception); } return flags; }
Example 11
Source File: AddImportsOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean isVisible(TypeNameMatch curr) { int flags= curr.getModifiers(); if (Flags.isPrivate(flags)) { return false; } if (Flags.isPublic(flags) || Flags.isProtected(flags)) { return true; } return curr.getPackageName().equals(fCompilationUnit.getParent().getElementName()); }
Example 12
Source File: SelfEncapsulateFieldRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private int createModifiers() throws JavaModelException { int result = 0; if (Flags.isPublic(fVisibility)) { result |= Modifier.PUBLIC; } else if (Flags.isProtected(fVisibility)) { result |= Modifier.PROTECTED; } else if (Flags.isPrivate(fVisibility)) { result |= Modifier.PRIVATE; } if (JdtFlags.isStatic(fField)) { result |= Modifier.STATIC; } return result; }
Example 13
Source File: InlineConstantRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Change createChange(IProgressMonitor pm) throws CoreException { try { pm.beginTask(RefactoringCoreMessages.InlineConstantRefactoring_preview, 2); final Map<String, String> arguments= new HashMap<String, String>(); String project= null; IJavaProject javaProject= fSelectionCu.getJavaProject(); if (javaProject != null) project= javaProject.getElementName(); int flags= RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; try { if (!Flags.isPrivate(fField.getFlags())) flags|= RefactoringDescriptor.MULTI_CHANGE; } catch (JavaModelException exception) { JavaPlugin.log(exception); } final String description= Messages.format(RefactoringCoreMessages.InlineConstantRefactoring_descriptor_description_short, JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_DEFAULT)); final String header= Messages.format(RefactoringCoreMessages.InlineConstantRefactoring_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(fField.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED)}); final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header); comment.addSetting(Messages.format(RefactoringCoreMessages.InlineConstantRefactoring_original_pattern, JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED))); if (fRemoveDeclaration) comment.addSetting(RefactoringCoreMessages.InlineConstantRefactoring_remove_declaration); if (fReplaceAllReferences) comment.addSetting(RefactoringCoreMessages.InlineConstantRefactoring_replace_references); final InlineConstantDescriptor descriptor= RefactoringSignatureDescriptorFactory.createInlineConstantDescriptor(project, description, comment.asString(), arguments, flags); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fSelectionCu)); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString()); //$NON-NLS-1$ arguments.put(ATTRIBUTE_REMOVE, Boolean.valueOf(fRemoveDeclaration).toString()); arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplaceAllReferences).toString()); return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.InlineConstantRefactoring_inline, fChanges); } finally { pm.done(); fChanges= null; } }
Example 14
Source File: SelfEncapsulateFieldRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private int createModifiers() throws JavaModelException { int result= 0; if (Flags.isPublic(fVisibility)) result |= Modifier.PUBLIC; else if (Flags.isProtected(fVisibility)) result |= Modifier.PROTECTED; else if (Flags.isPrivate(fVisibility)) result |= Modifier.PRIVATE; if (JdtFlags.isStatic(fField)) result |= Modifier.STATIC; return result; }
Example 15
Source File: JavaElementImageProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static ImageDescriptor getInnerInterfaceImageDescriptor(boolean isInInterfaceOrAnnotation, int flags) { if (Flags.isPublic(flags) || isInInterfaceOrAnnotation) return JavaPluginImages.DESC_OBJS_INNER_INTERFACE_PUBLIC; else if (Flags.isPrivate(flags)) return JavaPluginImages.DESC_OBJS_INNER_INTERFACE_PRIVATE; else if (Flags.isProtected(flags)) return JavaPluginImages.DESC_OBJS_INNER_INTERFACE_PROTECTED; else return JavaPluginImages.DESC_OBJS_INTERFACE_DEFAULT; }
Example 16
Source File: Jdt2Ecore.java From sarl with Apache License 2.0 | 5 votes |
/** Replies if the target feature is visible from the type. * * <p>The type finder could be obtained with {@link #toTypeFinder(IJavaProject)}. * * @param typeFinder the type finder to be used for finding the type definitions. * @param fromType the type from which the feature visibility is tested. * @param target the feature to test for the visibility. * @return <code>true</code> if the given type can see the target feature. * @throws JavaModelException if the Java model is invalid. * @see #toTypeFinder(IJavaProject) */ public boolean isVisible(TypeFinder typeFinder, IType fromType, IMember target) throws JavaModelException { final int flags = target.getFlags(); if (Flags.isPublic(flags)) { return true; } final String fromTypeName = fromType.getFullyQualifiedName(); final String memberType = target.getDeclaringType().getFullyQualifiedName(); if (Flags.isPrivate(flags)) { return target.getDeclaringType().getFullyQualifiedName().equals(fromTypeName); } if (Flags.isProtected(flags)) { IType t = fromType; while (t != null) { if (memberType.equals(t.getFullyQualifiedName())) { return true; } final String typeName = t.getSuperclassName(); if (Strings.isNullOrEmpty(typeName)) { t = null; } else { t = typeFinder.findType(typeName); } } } final IPackageFragment f1 = target.getDeclaringType().getPackageFragment(); final IPackageFragment f2 = fromType.getPackageFragment(); if (f1.isDefaultPackage()) { return f2.isDefaultPackage(); } return f1.getElementName().equals(f2.getElementName()); }
Example 17
Source File: JavaElementImageProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static ImageDescriptor getEnumImageDescriptor(int flags) { if (Flags.isPublic(flags) || Flags.isProtected(flags) || Flags.isPrivate(flags)) return JavaPluginImages.DESC_OBJS_ENUM; else return JavaPluginImages.DESC_OBJS_ENUM_DEFAULT; }
Example 18
Source File: JavaElementImageProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static ImageDescriptor getInterfaceImageDescriptor(int flags) { if (Flags.isPublic(flags) || Flags.isProtected(flags) || Flags.isPrivate(flags)) return JavaPluginImages.DESC_OBJS_INTERFACE; else return JavaPluginImages.DESC_OBJS_INTERFACE_DEFAULT; }
Example 19
Source File: RenameTypeProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Override public Change createChange(IProgressMonitor monitor) throws CoreException { try { monitor.beginTask(RefactoringCoreMessages.RenameTypeRefactoring_creating_change, 4); String project = null; IJavaProject javaProject = fType.getJavaProject(); if (javaProject != null) { project = javaProject.getElementName(); } int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE; try { if (!Flags.isPrivate(fType.getFlags())) { flags |= RefactoringDescriptor.MULTI_CHANGE; } if (fType.isAnonymous() || fType.isLocal()) { flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; } } catch (JavaModelException exception) { JavaLanguageServerPlugin.log(exception); } final String description = Messages.format(RefactoringCoreMessages.RenameTypeProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fType.getElementName())); final String header = Messages.format(RefactoringCoreMessages.RenameTypeProcessor_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fType, JavaElementLabels.ALL_FULLY_QUALIFIED), getNewElementLabel() }); final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString(); final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE); descriptor.setProject(project); descriptor.setDescription(description); descriptor.setComment(comment); descriptor.setFlags(flags); descriptor.setJavaElement(fType); descriptor.setNewName(getNewElementName()); descriptor.setUpdateQualifiedNames(fUpdateQualifiedNames); descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches); descriptor.setUpdateReferences(fUpdateReferences); if (fUpdateQualifiedNames && fFilePatterns != null && !"".equals(fFilePatterns)) { descriptor.setFileNamePatterns(fFilePatterns); } descriptor.setUpdateSimilarDeclarations(fUpdateSimilarElements); descriptor.setMatchStrategy(fRenamingStrategy); final DynamicValidationRefactoringChange result = new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameTypeProcessor_change_name); if (fChangeManager.containsChangesIn(fType.getCompilationUnit())) { TextChange textChange = fChangeManager.get(fType.getCompilationUnit()); if (textChange instanceof TextFileChange) { ((TextFileChange) textChange).setSaveMode(TextFileChange.FORCE_SAVE); } } if (willRenameCU()) { IResource resource = fType.getCompilationUnit().getResource(); if (resource != null && resource.isLinked()) { result.addAll(fChangeManager.getAllChanges()); String ext = resource.getFileExtension(); String renamedResourceName; if (ext == null) { renamedResourceName = getNewElementName(); } else { renamedResourceName = getNewElementName() + '.' + ext; } result.add(new RenameResourceChange(fType.getCompilationUnit().getPath(), renamedResourceName)); } else { addTypeDeclarationUpdate(fChangeManager); addConstructorRenames(fChangeManager); result.addAll(fChangeManager.getAllChanges()); String renamedCUName = JavaModelUtil.getRenamedCUName(fType.getCompilationUnit(), getNewElementName()); result.add(new RenameCompilationUnitChange(fType.getCompilationUnit(), renamedCUName)); } } else { result.addAll(fChangeManager.getAllChanges()); } monitor.worked(1); return result; } finally { fChangeManager = null; } }
Example 20
Source File: JavaElementImageProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static boolean isDefaultFlag(int flags) { return !Flags.isPublic(flags) && !Flags.isProtected(flags) && !Flags.isPrivate(flags); }