/** * Returns the modifier corresponding to the given single-bit flag value, * or <code>null</code> if none or if more than one bit is set. * <p> * <code>fromFlagValue</code> is the converse of <code>toFlagValue</code>: * that is, <code>ModifierKind.fromFlagValue(k.toFlagValue()) == k</code> for * all modifier keywords <code>k</code>. * </p> * * @param flagValue the single-bit flag value for the modifier * @return the modifier keyword, or <code>null</code> if none * @see #toFlagValue() */ public static ModifierKeyword fromFlagValue(int flagValue) { for (Iterator it = KEYWORDS.values().iterator(); it.hasNext(); ) { ModifierKeyword k = (ModifierKeyword) it.next(); if (k.toFlagValue() == flagValue) { return k; } } return null; }
/** * Returns the modifier corresponding to the given single-bit flag value, * or <code>null</code> if none or if more than one bit is set. * <p> * <code>fromFlagValue</code> is the converse of <code>toFlagValue</code>: * that is, <code>ModifierKind.fromFlagValue(k.toFlagValue()) == k</code> for * all modifier keywords <code>k</code>. * </p> * * @param flagValue the single-bit flag value for the modifier * @return the modifier keyword, or <code>null</code> if none * @see #toFlagValue() */ public static ModifierKeyword fromFlagValue(int flagValue) { for (Iterator it = KEYWORDS.values().iterator(); it.hasNext(); ) { ModifierKeyword k = (ModifierKeyword) it.next(); if (k.toFlagValue() == flagValue) { return k; } } return null; }
/** * Returns the modifier corresponding to the given single-bit flag value, * or <code>null</code> if none or if more than one bit is set. * <p> * <code>fromFlagValue</code> is the converse of <code>toFlagValue</code>: * that is, <code>ModifierKind.fromFlagValue(k.toFlagValue()) == k</code> for * all modifier keywords <code>k</code>. * </p> * * @param flagValue the single-bit flag value for the modifier * @return the modifier keyword, or <code>null</code> if none * @see #toFlagValue() */ public static ModifierKeyword fromFlagValue(int flagValue) { for (Iterator it = KEYWORDS.values().iterator(); it.hasNext(); ) { ModifierKeyword k = (ModifierKeyword) it.next(); if (k.toFlagValue() == flagValue) { return k; } } return null; }
/** * Returns the module modifiers explicitly specified on this declaration. * <p> * This method is a convenience method that * computes these flags from <code>modifiers()</code>. * </p> * * @return the bit-wise or of <code>ModuleModifier</code> constants * @see ModuleModifier */ public int getModifiers() { // do not cache - performance could be improved by caching computed flags // but this would require tracking changes to this.modifiers int computedModifierFlags = ModuleModifier.NONE; for (Iterator it = modifiers().iterator(); it.hasNext(); ) { Object x = it.next(); if (x instanceof ModuleModifier) { computedModifierFlags |= ((Modifier) x).getKeyword().toFlagValue(); } } return computedModifierFlags; }
/** * Does the specified member need further visibility adjustment? * * @param member the member to test * @param threshold the visibility threshold to test for * @param adjustments the map of members to visibility adjustments * @return <code>true</code> if the member needs further adjustment, <code>false</code> otherwise */ public static boolean needsVisibilityAdjustments(final IMember member, final int threshold, final Map<IMember, IncomingMemberVisibilityAdjustment> adjustments) { Assert.isNotNull(member); Assert.isTrue(isVisibilityModifier(threshold)); Assert.isNotNull(adjustments); final IncomingMemberVisibilityAdjustment adjustment= adjustments.get(member); if (adjustment != null) { final ModifierKeyword keyword= adjustment.getKeyword(); return hasLowerVisibility(keyword == null ? Modifier.NONE : keyword.toFlagValue(), threshold); } return true; }
/** * Does the specified member need further visibility adjustment? * * @param member the member to test * @param threshold the visibility threshold to test for * @param adjustments the map of members to visibility adjustments * @return <code>true</code> if the member needs further adjustment, <code>false</code> otherwise */ public static boolean needsVisibilityAdjustments(final IMember member, final int threshold, final Map adjustments) { Assert.isNotNull(member); Assert.isTrue(isVisibilityModifier(threshold)); Assert.isNotNull(adjustments); final IncomingMemberVisibilityAdjustment adjustment= (IncomingMemberVisibilityAdjustment) adjustments.get(member); if (adjustment != null) { final ModifierKeyword keyword= adjustment.getKeyword(); return hasLowerVisibility(keyword == null ? Modifier.NONE : keyword.toFlagValue(), threshold); } return true; }
/** * Adjusts the visibility of the specified member. * * @param element the "source" point from which to calculate the visibility * @param referencedMovedElement the moved element which may be adjusted in visibility * @param monitor the progress monitor to use * @throws JavaModelException if the visibility adjustment could not be computed */ private void adjustIncomingVisibility(final IJavaElement element, IMember referencedMovedElement, final IProgressMonitor monitor) throws JavaModelException { final ModifierKeyword threshold= getVisibilityThreshold(element, referencedMovedElement, monitor); int flags= referencedMovedElement.getFlags(); IType declaring= referencedMovedElement.getDeclaringType(); if (declaring.isInterface()) return; if (hasLowerVisibility(flags, threshold == null ? Modifier.NONE : threshold.toFlagValue()) && needsVisibilityAdjustment(referencedMovedElement, threshold)) fAdjustments.put(referencedMovedElement, new IncomingMemberVisibilityAdjustment(referencedMovedElement, threshold, RefactoringStatus.createStatus(fVisibilitySeverity, Messages.format(getMessage(referencedMovedElement), new String[] { getLabel(referencedMovedElement), getLabel(threshold)}), JavaStatusContext.create(referencedMovedElement), null, RefactoringStatusEntry.NO_CODE, null))); }
/** * Does the specified member need further visibility adjustment? * * @param member the member to test * @param threshold the visibility threshold to test for * @param adjustments the map of members to visibility adjustments * @return <code>true</code> if the member needs further adjustment, <code>false</code> otherwise */ public static boolean needsVisibilityAdjustments(final IMember member, final int threshold, final Map<IMember, IncomingMemberVisibilityAdjustment> adjustments) { Assert.isNotNull(member); Assert.isTrue(isVisibilityModifier(threshold)); Assert.isNotNull(adjustments); final IncomingMemberVisibilityAdjustment adjustment= adjustments.get(member); if (adjustment != null) { final ModifierKeyword keyword= adjustment.getKeyword(); return hasLowerVisibility(keyword == null ? Modifier.NONE : keyword.toFlagValue(), threshold); } return true; }
/** * Adjusts the visibility of the specified member. * * @param element the "source" point from which to calculate the visibility * @param referencedMovedElement the moved element which may be adjusted in visibility * @param monitor the progress monitor to use * @throws JavaModelException if the visibility adjustment could not be computed */ private void adjustIncomingVisibility(final IJavaElement element, IMember referencedMovedElement, final IProgressMonitor monitor) throws JavaModelException { final ModifierKeyword threshold= getVisibilityThreshold(element, referencedMovedElement, monitor); int flags= referencedMovedElement.getFlags(); IType declaring= referencedMovedElement.getDeclaringType(); if (declaring != null && declaring.isInterface() || referencedMovedElement instanceof IField && Flags.isEnum(referencedMovedElement.getFlags())) return; if (hasLowerVisibility(flags, threshold == null ? Modifier.NONE : threshold.toFlagValue()) && needsVisibilityAdjustment(referencedMovedElement, threshold)) fAdjustments.put(referencedMovedElement, new IncomingMemberVisibilityAdjustment(referencedMovedElement, threshold, RefactoringStatus.createStatus(fVisibilitySeverity, Messages.format(getMessage(referencedMovedElement), new String[] { getLabel(referencedMovedElement), getLabel(threshold)}), JavaStatusContext.create(referencedMovedElement), null, RefactoringStatusEntry.NO_CODE, null))); }
public static void installLinkedVisibilityProposals(LinkedProposalModel linkedProposalModel, ASTRewrite rewrite, List<IExtendedModifier> modifiers, boolean inInterface, String groupId) { ASTNode modifier= findVisibilityModifier(modifiers); if (modifier != null) { int selected= ((Modifier) modifier).getKeyword().toFlagValue(); LinkedProposalPositionGroup positionGroup= linkedProposalModel.getPositionGroup(groupId, true); positionGroup.addPosition(rewrite.track(modifier), false); positionGroup.addProposal(new ModifierLinkedModeProposal(selected, 10)); // add all others int[] flagValues= inInterface ? new int[] { Modifier.PUBLIC, 0 } : new int[] { Modifier.PUBLIC, 0, Modifier.PROTECTED, Modifier.PRIVATE }; for (int i= 0; i < flagValues.length; i++) { if (flagValues[i] != selected) { positionGroup.addProposal(new ModifierLinkedModeProposal(flagValues[i], 9 - i)); } } } }
public static void installLinkedVisibilityProposals(LinkedProposalModel linkedProposalModel, ASTRewrite rewrite, List modifiers, boolean inInterface) { ASTNode modifier= findVisibilityModifier(modifiers); if (modifier != null) { int selected= ((Modifier) modifier).getKeyword().toFlagValue(); LinkedProposalPositionGroup positionGroup= linkedProposalModel.getPositionGroup(KEY_MODIFIER, true); positionGroup.addPosition(rewrite.track(modifier), false); positionGroup.addProposal(new ModifierLinkedModeProposal(selected, 10)); // add all others int[] flagValues= inInterface ? new int[] { Modifier.PUBLIC, 0 } : new int[] { Modifier.PUBLIC, 0, Modifier.PROTECTED, Modifier.PRIVATE }; for (int i= 0; i < flagValues.length; i++) { if (flagValues[i] != selected) { positionGroup.addProposal(new ModifierLinkedModeProposal(flagValues[i], 9 - i)); } } } }
public static void installLinkedVisibilityProposals(LinkedProposalModel linkedProposalModel, ASTRewrite rewrite, List<IExtendedModifier> modifiers, boolean inInterface, String groupId) { ASTNode modifier= findVisibilityModifier(modifiers); if (modifier != null) { int selected= ((Modifier) modifier).getKeyword().toFlagValue(); LinkedProposalPositionGroup positionGroup= linkedProposalModel.getPositionGroup(groupId, true); positionGroup.addPosition(rewrite.track(modifier), false); positionGroup.addProposal(new ModifierLinkedModeProposal(selected, 10)); // add all others int[] flagValues= inInterface ? new int[] { Modifier.PUBLIC, 0 } : new int[] { Modifier.PUBLIC, 0, Modifier.PROTECTED, Modifier.PRIVATE }; for (int i= 0; i < flagValues.length; i++) { if (flagValues[i] != selected) { positionGroup.addProposal(new ModifierLinkedModeProposal(flagValues[i], 9 - i)); } } } }
/** * Adjusts the visibility of the specified member. * * @param element the "source" point from which to calculate the visibility * @param referencedMovedElement the moved element which may be adjusted in visibility * @param monitor the progress monitor to use * @throws JavaModelException if the visibility adjustment could not be computed */ private void adjustIncomingVisibility(final IJavaElement element, IMember referencedMovedElement, final IProgressMonitor monitor) throws JavaModelException { final ModifierKeyword threshold= getVisibilityThreshold(element, referencedMovedElement, monitor); int flags= referencedMovedElement.getFlags(); IType declaring= referencedMovedElement.getDeclaringType(); if (declaring != null && declaring.isInterface() || referencedMovedElement instanceof IField && Flags.isEnum(referencedMovedElement.getFlags())) return; if (hasLowerVisibility(flags, threshold == null ? Modifier.NONE : threshold.toFlagValue()) && needsVisibilityAdjustment(referencedMovedElement, threshold)) fAdjustments.put(referencedMovedElement, new IncomingMemberVisibilityAdjustment(referencedMovedElement, threshold, RefactoringStatus.createStatus(fVisibilitySeverity, Messages.format(getMessage(referencedMovedElement), new String[] { getLabel(referencedMovedElement), getLabel(threshold)}), JavaStatusContext.create(referencedMovedElement), null, RefactoringStatusEntry.NO_CODE, null))); }
public static void installLinkedVisibilityProposals(LinkedProposalModelCore linkedProposalModel, ASTRewrite rewrite, List<IExtendedModifier> modifiers, boolean inInterface, String groupId) { ASTNode modifier = findVisibilityModifier(modifiers); if (modifier != null) { int selected = ((Modifier) modifier).getKeyword().toFlagValue(); LinkedProposalPositionGroupCore positionGroup = linkedProposalModel.getPositionGroup(groupId, true); positionGroup.addPosition(rewrite.track(modifier), false); positionGroup.addProposal(new ModifierLinkedModeProposal(selected, 10)); // add all others int[] flagValues = inInterface ? new int[] { Modifier.PUBLIC, 0 } : new int[] { Modifier.PUBLIC, 0, Modifier.PROTECTED, Modifier.PRIVATE }; for (int i = 0; i < flagValues.length; i++) { if (flagValues[i] != selected) { positionGroup.addProposal(new ModifierLinkedModeProposal(flagValues[i], 9 - i)); } } } }
public static Modifier findModifierNode(int flag, List<IExtendedModifier> modifiers) { for (int i= 0; i < modifiers.size(); i++) { Object curr= modifiers.get(i); if (curr instanceof Modifier && ((Modifier) curr).getKeyword().toFlagValue() == flag) { return (Modifier) curr; } } return null; }
public static Modifier findModifierNode(int flag, List<IExtendedModifier> modifiers) { for (int i= 0; i < modifiers.size(); i++) { Object curr= modifiers.get(i); if (curr instanceof Modifier && ((Modifier) curr).getKeyword().toFlagValue() == flag) { return (Modifier) curr; } } return null; }
public static Modifier findModifierNode(int flag, List modifiers) { for (int i= 0; i < modifiers.size(); i++) { Object curr= modifiers.get(i); if (curr instanceof Modifier && ((Modifier) curr).getKeyword().toFlagValue() == flag) { return (Modifier) curr; } } return null; }
/** * Does the specified modifier keyword represent a lower visibility than the required threshold? * * @param keyword the visibility keyword to test, or <code>null</code> for default visibility * @param threshold the visibility threshold keyword to compare with, or <code>null</code> to compare with default visibility * @return <code>true</code> if the visibility is lower than required, <code>false</code> otherwise */ public static boolean hasLowerVisibility(final ModifierKeyword keyword, final ModifierKeyword threshold) { Assert.isTrue(isVisibilityKeyword(keyword)); Assert.isTrue(isVisibilityKeyword(threshold)); return hasLowerVisibility(keyword != null ? keyword.toFlagValue() : Modifier.NONE, threshold != null ? threshold.toFlagValue() : Modifier.NONE); }
/** * Does the specified modifier keyword represent a lower visibility than the required threshold? * * @param keyword the visibility keyword to test, or <code>null</code> for default visibility * @param threshold the visibility threshold keyword to compare with, or <code>null</code> to compare with default visibility * @return <code>true</code> if the visibility is lower than required, <code>false</code> otherwise */ public static boolean hasLowerVisibility(final ModifierKeyword keyword, final ModifierKeyword threshold) { Assert.isTrue(isVisibilityKeyword(keyword)); Assert.isTrue(isVisibilityKeyword(threshold)); return hasLowerVisibility(keyword != null ? keyword.toFlagValue() : Modifier.NONE, threshold != null ? threshold.toFlagValue() : Modifier.NONE); }
/** * Does the specified modifier keyword represent a lower visibility than the required threshold? * * @param keyword the visibility keyword to test, or <code>null</code> for default visibility * @param threshold the visibility threshold keyword to compare with, or <code>null</code> to compare with default visibility * @return <code>true</code> if the visibility is lower than required, <code>false</code> otherwise */ public static boolean hasLowerVisibility(final ModifierKeyword keyword, final ModifierKeyword threshold) { Assert.isTrue(isVisibilityKeyword(keyword)); Assert.isTrue(isVisibilityKeyword(threshold)); return hasLowerVisibility(keyword != null ? keyword.toFlagValue() : Modifier.NONE, threshold != null ? threshold.toFlagValue() : Modifier.NONE); }