|
What this is
Other links
The source code/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.refactoring;
import java.lang.reflect.Modifier;
import java.text.MessageFormat;
import javax.jmi.reflect.RefObject;
import org.netbeans.modules.refactoring.api.RefactoringElement;
import org.netbeans.jmi.javamodel.*;
import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
import org.openide.text.PositionBounds;
import org.openide.util.NbBundle;
/**
* Changes the modifier of element.
* For example, it is used by EncapsulateField refactoring -
* field is changed to private as default, but user can
* use another value. You can use it also for other features.
*
* @author Pavel Flaska
*/
public class ChangeModElement implements RefactoringElement {
private int modifier;
private Feature element;
private PositionBounds bounds;
boolean enabled;
private final String text;
private final String displayText;
private int status;
/**
* Creates a new instance of Change field access modifier element.
*
* @param element access modifier will be changed on this parameter
* @param modifier new modifier for the element
*/
public ChangeModElement(Feature element, int modifier) {
this.element = element;
this.modifier = modifier;
bounds = null;
enabled = true;
String elementType;
if (element instanceof Field) {
elementType = "field"; // NOI18N
} else if (element instanceof Constructor) {
elementType = "constructor"; // NOI18N
} else if (element instanceof Method) {
elementType = "method"; // NOI18N
} else {
elementType = "class"; //NOI18N
}
Object[] o = new Object[] {
elementType,
element.getName(),
Modifier.toString(modifier)
};
text = new MessageFormat(
NbBundle.getMessage(ChangeModElement.class, "DSC_ChangeModifier")).format(o);
displayText = new MessageFormat(
NbBundle.getMessage(ChangeModElement.class, "DSC_ChangeModifier_html")).format(o);
if (JavaMetamodel.getManager().isElementGuarded(element)) {
status = RefactoringElement.GUARDED;
} else {
status = RefactoringElement.NORMAL;
}
}
/**
* Returns refactored element.
*
* @return refactored element
*/
public Element getJavaElement() { return element; }
/**
* Returns bounds of the field declaration,
* e.g.
|
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.