Java Code Examples for org.eclipse.jdt.core.dom.Modifier#NONE

The following examples show how to use org.eclipse.jdt.core.dom.Modifier#NONE . 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: VariableDeclarationFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static ModifierChangeOperation createAddFinalOperation(SimpleName name, ASTNode decl) {
	if (decl == null)
		return null;

	IBinding binding= name.resolveBinding();
	if (!canAddFinal(binding, decl))
		return null;

	if (decl instanceof SingleVariableDeclaration) {
		return new ModifierChangeOperation(decl, new ArrayList<VariableDeclarationFragment>(), Modifier.FINAL, Modifier.NONE);
	} else if (decl instanceof VariableDeclarationExpression) {
		return new ModifierChangeOperation(decl, new ArrayList<VariableDeclarationFragment>(), Modifier.FINAL, Modifier.NONE);
	} else if (decl instanceof VariableDeclarationFragment){
		VariableDeclarationFragment frag= (VariableDeclarationFragment)decl;
		decl= decl.getParent();
		if (decl instanceof FieldDeclaration || decl instanceof VariableDeclarationStatement) {
			List<VariableDeclarationFragment> list= new ArrayList<VariableDeclarationFragment>();
			list.add(frag);
			return new ModifierChangeOperation(decl, list, Modifier.FINAL, Modifier.NONE);
		} else if (decl instanceof VariableDeclarationExpression) {
			return new ModifierChangeOperation(decl, new ArrayList<VariableDeclarationFragment>(), Modifier.FINAL, Modifier.NONE);
		}
	}

	return null;
}
 
Example 2
Source File: JdtFlags.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Compares two visibilities.
 *
 * @param newVisibility the 'new' visibility
 * @param oldVisibility the 'old' visibility
 * @return <code>true</code> iff the 'new' visibility is strictly higher than the old visibility
 *
 * @see Modifier#PUBLIC
 * @see Modifier#PROTECTED
 * @see Modifier#NONE
 * @see Modifier#PRIVATE
 */
public static boolean isHigherVisibility(int newVisibility, int oldVisibility){
	assertVisibility(oldVisibility);
	assertVisibility(newVisibility);
	switch (oldVisibility) {
		case Modifier.PRIVATE :
			return 	newVisibility == Modifier.NONE
					||	newVisibility == Modifier.PUBLIC
					||  newVisibility == Modifier.PROTECTED;
		case Modifier.NONE :
			return 	newVisibility == Modifier.PUBLIC
					||  newVisibility == Modifier.PROTECTED;

		case Modifier.PROTECTED :
			return newVisibility == Modifier.PUBLIC;

		case Modifier.PUBLIC :
			return false;
		default:
			Assert.isTrue(false);
			return false;
	}
}
 
Example 3
Source File: VariableDeclarationFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean handleFragments(List<VariableDeclarationFragment> list, ASTNode declaration) {
	List<VariableDeclarationFragment> toChange= new ArrayList<VariableDeclarationFragment>();

	for (Iterator<VariableDeclarationFragment> iter= list.iterator(); iter.hasNext();) {
		VariableDeclarationFragment fragment= iter.next();
		SimpleName name= fragment.getName();
		IBinding resolveBinding= name.resolveBinding();
		if (canAddFinal(resolveBinding, declaration)) {
			IVariableBinding varbinding= (IVariableBinding)resolveBinding;
			if (varbinding.isField()) {
				if (fieldCanBeFinal(fragment, varbinding))
					toChange.add(fragment);
			} else {
				if (!fWrittenVariables.containsKey(resolveBinding))
					toChange.add(fragment);
			}
		}
	}

	if (toChange.size() == 0)
		return false;

	ModifierChangeOperation op= new ModifierChangeOperation(declaration, toChange, Modifier.FINAL, Modifier.NONE);
	fResult.add(op);
	return false;
}
 
Example 4
Source File: JdtFlags.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static int getVisibilityCode(BodyDeclaration bodyDeclaration) {
	if (isPublic(bodyDeclaration)) {
		return Modifier.PUBLIC;
	} else if (isProtected(bodyDeclaration)) {
		return Modifier.PROTECTED;
	} else if (isPackageVisible(bodyDeclaration)) {
		return Modifier.NONE;
	} else if (isPrivate(bodyDeclaration)) {
		return Modifier.PRIVATE;
	}
	Assert.isTrue(false);
	return VISIBILITY_CODE_INVALID;
}
 
Example 5
Source File: SourceActionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected Composite addVisibilityAndModifiersChoices(Composite buttonComposite) {
	// Add visibility and modifiers buttons: http://bugs.eclipse.org/bugs/show_bug.cgi?id=35870
	// Add persistence of options: http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
	IVisibilityChangeListener visibilityChangeListener= new IVisibilityChangeListener(){
		public void visibilityChanged(int newVisibility) {
			setVisibility(newVisibility);
		}
		public void modifierChanged(int modifier, boolean isChecked) {
			switch (modifier) {
				case Modifier.FINAL:  {
					setFinal(isChecked);
					return;
				}
				case Modifier.SYNCHRONIZED:  {
					setSynchronized(isChecked);
					return;
				}
				default: return;
			}
		}
	};

	int initialVisibility= getVisibilityModifier();
	int[] availableVisibilities= new int[]{Modifier.PUBLIC, Modifier.PROTECTED, Modifier.PRIVATE, Modifier.NONE};

	Composite visibilityComposite= createVisibilityControlAndModifiers(buttonComposite, visibilityChangeListener, availableVisibilities, initialVisibility);
	return visibilityComposite;
}
 
Example 6
Source File: JdtFlags.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static int getVisibilityCode(IBinding binding) {
	if (isPublic(binding))
		return Modifier.PUBLIC;
	else if (isProtected(binding))
		return Modifier.PROTECTED;
	else if (isPackageVisible(binding))
		return Modifier.NONE;
	else if (isPrivate(binding))
		return Modifier.PRIVATE;
	Assert.isTrue(false);
	return VISIBILITY_CODE_INVALID;
}
 
Example 7
Source File: JdtFlags.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static int getVisibilityCode(BodyDeclaration bodyDeclaration) {
	if (isPublic(bodyDeclaration))
		return Modifier.PUBLIC;
	else if (isProtected(bodyDeclaration))
		return Modifier.PROTECTED;
	else if (isPackageVisible(bodyDeclaration))
		return Modifier.NONE;
	else if (isPrivate(bodyDeclaration))
		return Modifier.PRIVATE;
	Assert.isTrue(false);
	return VISIBILITY_CODE_INVALID;
}
 
Example 8
Source File: JdtFlags.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static int getVisibilityCode(IMember member) throws JavaModelException {
	if (isPublic(member))
		return Modifier.PUBLIC;
	else if (isProtected(member))
		return Modifier.PROTECTED;
	else if (isPackageVisible(member))
		return Modifier.NONE;
	else if (isPrivate(member))
		return Modifier.PRIVATE;
	Assert.isTrue(false);
	return VISIBILITY_CODE_INVALID;
}
 
Example 9
Source File: ChangeSignatureWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private String getAccessModifierString(int modifier) {
	switch (modifier) {
		case Modifier.PUBLIC :
			return JdtFlags.VISIBILITY_STRING_PUBLIC;
		case Modifier.PROTECTED :
			return JdtFlags.VISIBILITY_STRING_PROTECTED;
		case Modifier.NONE :
			return RefactoringMessages.ChangeSignatureInputPage_default;
		case Modifier.PRIVATE :
			return JdtFlags.VISIBILITY_STRING_PRIVATE;
		default :
			throw new IllegalArgumentException("\"" + modifier + "\" is not a Modifier constant"); //$NON-NLS-1$ //$NON-NLS-2$
	}
}
 
Example 10
Source File: ConvertAnonymousToNestedRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public int[] getAvailableVisibilities() {
    if (isLocalInnerType()) {
        return new int[] { Modifier.NONE };
    } else {
        return new int[] { Modifier.PUBLIC, Modifier.PROTECTED, Modifier.NONE, Modifier.PRIVATE };
    }
}
 
Example 11
Source File: ChangeSignatureProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static int getAccessModifier(AbstractTypeDeclaration subclass) {
	int modifiers= subclass.getModifiers();
	if (Modifier.isPublic(modifiers))
		return Modifier.PUBLIC;
	else if (Modifier.isProtected(modifiers))
		return Modifier.PROTECTED;
	else if (Modifier.isPrivate(modifiers))
		return Modifier.PRIVATE;
	else
		return Modifier.NONE;
}
 
Example 12
Source File: ChangeSignatureProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public int[] getAvailableVisibilities() throws JavaModelException{
	if (fTopMethod.getDeclaringType().isInterface())
		return new int[]{Modifier.PUBLIC};
	else if (fTopMethod.getDeclaringType().isEnum() && fTopMethod.isConstructor())
		return new int[]{	Modifier.NONE,
							Modifier.PRIVATE};
	else
		return new int[]{	Modifier.PUBLIC,
							Modifier.PROTECTED,
							Modifier.NONE,
							Modifier.PRIVATE};
}
 
Example 13
Source File: MoveStaticMembersProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isVisibleFrom(IType newMemberDeclaringType, IType accessingType) throws JavaModelException {
	int memberVisibility= JdtFlags.getVisibilityCode(newMemberDeclaringType);

	IType declaringType= newMemberDeclaringType.getDeclaringType();
	while (declaringType != null) { //get lowest visibility in all parent types of newMemberDeclaringType
		memberVisibility= JdtFlags.getLowerVisibility(
				memberVisibility, JdtFlags.getVisibilityCode(declaringType));
		declaringType= declaringType.getDeclaringType();
	}

	switch (memberVisibility) {
		case Modifier.PRIVATE :
			return isEqualOrEnclosedType(accessingType, newMemberDeclaringType);

		case Modifier.NONE :
			return JavaModelUtil.isSamePackage(accessingType.getPackageFragment(), newMemberDeclaringType.getPackageFragment());

		case Modifier.PROTECTED :
			return JavaModelUtil.isSamePackage(accessingType.getPackageFragment(), newMemberDeclaringType.getPackageFragment())
					|| accessingType.newSupertypeHierarchy(null).contains(newMemberDeclaringType);

		case Modifier.PUBLIC :
			return true;

		default:
			Assert.isTrue(false);
			return false;
	}
}
 
Example 14
Source File: JdtFlags.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static int getVisibilityCode(IBinding binding) {
	if (isPublic(binding)) {
		return Modifier.PUBLIC;
	} else if (isProtected(binding)) {
		return Modifier.PROTECTED;
	} else if (isPackageVisible(binding)) {
		return Modifier.NONE;
	} else if (isPrivate(binding)) {
		return Modifier.PRIVATE;
	}
	Assert.isTrue(false);
	return VISIBILITY_CODE_INVALID;
}
 
Example 15
Source File: JdtFlags.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static int getVisibilityCode(IMember member) throws JavaModelException {
	if (isPublic(member)) {
		return Modifier.PUBLIC;
	} else if (isProtected(member)) {
		return Modifier.PROTECTED;
	} else if (isPackageVisible(member)) {
		return Modifier.NONE;
	} else if (isPrivate(member)) {
		return Modifier.PRIVATE;
	}
	Assert.isTrue(false);
	return VISIBILITY_CODE_INVALID;
}
 
Example 16
Source File: ConvertAnonymousToNestedRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void initializeDefaults() {
    fVisibility= isLocalInnerType() ? Modifier.NONE : Modifier.PRIVATE;
    fDeclareStatic = mustInnerClassBeStatic();
}
 
Example 17
Source File: PromoteTempToFieldRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public int[] getAvailableVisibilities(){
	return new int[]{Modifier.PUBLIC, Modifier.PROTECTED, Modifier.NONE, Modifier.PRIVATE};
}
 
Example 18
Source File: InputPageUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static Composite createVisibilityControl(Composite parent, final IVisibilityChangeListener visibilityChangeListener, int[] availableVisibilities, int correctVisibility) {
	List<Integer> allowedVisibilities= convertToIntegerList(availableVisibilities);
	if (allowedVisibilities.size() == 1)
		return null;

	Group group= new Group(parent, SWT.NONE);
	group.setText(RefactoringMessages.VisibilityControlUtil_Access_modifier);
	GridData gd= new GridData(GridData.FILL_HORIZONTAL);
	group.setLayoutData(gd);
	GridLayout layout= new GridLayout();
	layout.makeColumnsEqualWidth= true;
	layout.numColumns= 4;
	group.setLayout(layout);

	String[] labels= new String[] {
		"&public", //$NON-NLS-1$
		"pro&tected", //$NON-NLS-1$
		RefactoringMessages.VisibilityControlUtil_defa_ult_4,
		"pri&vate" //$NON-NLS-1$
	};
	Integer[] data= new Integer[] {
				new Integer(Modifier.PUBLIC),
				new Integer(Modifier.PROTECTED),
				new Integer(Modifier.NONE),
				new Integer(Modifier.PRIVATE)};
	Integer initialVisibility= new Integer(correctVisibility);
	for (int i= 0; i < labels.length; i++) {
		Button radio= new Button(group, SWT.RADIO);
		Integer visibilityCode= data[i];
		radio.setText(labels[i]);
		radio.setData(visibilityCode);
		radio.setSelection(visibilityCode.equals(initialVisibility));
		radio.setEnabled(allowedVisibilities.contains(visibilityCode));
		radio.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent event) {
				visibilityChangeListener.visibilityChanged(((Integer)event.widget.getData()).intValue());
			}
		});
	}
	group.setLayoutData((new GridData(GridData.FILL_HORIZONTAL)));
	return group;
}
 
Example 19
Source File: SourceActionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected Composite createVisibilityControl(Composite parent, final IVisibilityChangeListener visibilityChangeListener, int[] availableVisibilities, int correctVisibility) {
	fAllowedVisibilities= convertToIntegerList(availableVisibilities);
	if (fAllowedVisibilities.size() == 1)
		return null;

	Group group= new Group(parent, SWT.NONE);
	group.setText(ActionMessages.SourceActionDialog_modifier_group);
	GridData gd= new GridData(GridData.FILL_BOTH);
	group.setLayoutData(gd);
	GridLayout layout= new GridLayout();
	layout.makeColumnsEqualWidth= true;
	layout.numColumns= 4;
	group.setLayout(layout);

	String[] labels= new String[] {
		ActionMessages.SourceActionDialog_modifier_public,
		ActionMessages.SourceActionDialog_modifier_protected,
		ActionMessages.SourceActionDialog_modifier_default,
		ActionMessages.SourceActionDialog_modifier_private,
	};
	Integer[] data= new Integer[] {
				new Integer(Modifier.PUBLIC),
				new Integer(Modifier.PROTECTED),
				new Integer(Modifier.NONE),
				new Integer(Modifier.PRIVATE)};
	Integer initialVisibility= new Integer(correctVisibility);
	for (int i= 0; i < labels.length; i++) {
		Button radio= new Button(group, SWT.RADIO);
		Integer visibilityCode= data[i];
		radio.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
		radio.setText(labels[i]);
		radio.setData(visibilityCode);
		radio.setSelection(visibilityCode.equals(initialVisibility));
		radio.setEnabled(fAllowedVisibilities.contains(visibilityCode));
		radio.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent event) {
				visibilityChangeListener.visibilityChanged(((Integer)event.widget.getData()).intValue());
			}
		});
	}
	return group;
}
 
Example 20
Source File: MemberVisibilityAdjustor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Is the specified modifier a visibility modifier?
 *
 * @param modifier the keyword to test
 * @return <code>true</code> if it is a visibility modifier, <code>false</code> otherwise
 */
private static boolean isVisibilityModifier(final int modifier) {
	return modifier == Modifier.NONE || modifier == Modifier.PUBLIC || modifier == Modifier.PROTECTED || modifier == Modifier.PRIVATE;
}