本文整理匯總了Java中com.sun.source.tree.VariableTree.getModifiers方法的典型用法代碼示例。如果您正苦於以下問題:Java VariableTree.getModifiers方法的具體用法?Java VariableTree.getModifiers怎麽用?Java VariableTree.getModifiers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.source.tree.VariableTree
的用法示例。
在下文中一共展示了VariableTree.getModifiers方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: performRewrite
import com.sun.source.tree.VariableTree; //導入方法依賴的package包/類
@Override
protected void performRewrite(TransformationContext ctx) {
WorkingCopy wc = ctx.getWorkingCopy();
TreePath tp = ctx.getPath();
VariableTree vt = (VariableTree) tp.getLeaf();
ModifiersTree mt = vt.getModifiers();
Set<Modifier> modifiers = EnumSet.noneOf(Modifier.class);
modifiers.addAll(mt.getFlags());
modifiers.add(Modifier.FINAL);
modifiers.add(Modifier.STATIC);
ModifiersTree newMod = wc.getTreeMaker().Modifiers(modifiers, mt.getAnnotations());
wc.rewrite(mt, newMod);
}
示例2: testRemoveVariableModifier
import com.sun.source.tree.VariableTree; //導入方法依賴的package包/類
public void testRemoveVariableModifier() throws Exception {
testFile = new File(getWorkDir(), "Test.java");
TestUtilities.copyStringToFile(testFile,
"package flaska;\n" +
"\n" +
"public class Test {\n" +
" private int a;\n" +
"}\n"
);
String golden =
"package flaska;\n" +
"\n" +
"public class Test {\n" +
" int a;\n" +
"}\n";
JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
Task<WorkingCopy> task = new Task<WorkingCopy>() {
public void run(WorkingCopy workingCopy) throws java.io.IOException {
workingCopy.toPhase(Phase.RESOLVED);
TreeMaker make = workingCopy.getTreeMaker();
ClassTree clazz = (ClassTree) workingCopy.getCompilationUnit().getTypeDecls().get(0);
VariableTree var = (VariableTree) clazz.getMembers().get(1);
ModifiersTree mods = var.getModifiers();
ModifiersTree copy = make.Modifiers(EnumSet.noneOf(Modifier.class), mods.getAnnotations());
workingCopy.rewrite(mods, copy);
}
};
testSource.runModificationTask(task).commit();
String res = TestUtilities.copyFileToString(testFile);
System.err.println(res);
assertEquals(golden, res);
}
示例3: removeFinal
import com.sun.source.tree.VariableTree; //導入方法依賴的package包/類
private static VariableTree removeFinal(
final WorkingCopy wc,
final VariableTree varTree) {
final ModifiersTree oldMods = varTree.getModifiers();
if (oldMods != null && oldMods.getFlags().contains(Modifier.FINAL)) {
final ModifiersTree newMods = wc.getTreeMaker().removeModifiersModifier(oldMods, Modifier.FINAL);
rewriteCopyComments(wc, oldMods, newMods);
}
return varTree;
}
示例4: testChangeToFinalLocVar
import com.sun.source.tree.VariableTree; //導入方法依賴的package包/類
/**
* Tests the change of modifier in local variable
*/
public void testChangeToFinalLocVar() throws Exception {
testFile = new File(getWorkDir(), "Test.java");
TestUtilities.copyStringToFile(testFile,
"package hierbas.del.litoral;\n\n" +
"import java.io.*;\n\n" +
"public class Test {\n" +
" public void taragui() {\n" +
" int i = 10;\n" +
" }\n" +
"}\n"
);
String golden =
"package hierbas.del.litoral;\n\n" +
"import java.io.*;\n\n" +
"public class Test {\n" +
" public void taragui() {\n" +
" final int i = 10;\n" +
" }\n" +
"}\n";
JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
Task<WorkingCopy> task = new Task<WorkingCopy>() {
public void run(WorkingCopy workingCopy) throws java.io.IOException {
workingCopy.toPhase(Phase.RESOLVED);
TreeMaker make = workingCopy.getTreeMaker();
// finally, find the correct body and rewrite it.
ClassTree clazz = (ClassTree) workingCopy.getCompilationUnit().getTypeDecls().get(0);
MethodTree method = (MethodTree) clazz.getMembers().get(1);
BlockTree block = method.getBody();
VariableTree vt = (VariableTree) block.getStatements().get(0);
ModifiersTree mods = vt.getModifiers();
workingCopy.rewrite(mods, make.Modifiers(Collections.<Modifier>singleton(Modifier.FINAL)));
}
};
testSource.runModificationTask(task).commit();
String res = TestUtilities.copyFileToString(testFile);
System.err.println(res);
assertEquals(golden, res);
}
示例5: getSourceModifiers
import com.sun.source.tree.VariableTree; //導入方法依賴的package包/類
protected ModifiersTree getSourceModifiers(VariableTree fieldTree, MethodTree methodTree) {
return fieldTree.getModifiers();
}
示例6: getTargetModifiers
import com.sun.source.tree.VariableTree; //導入方法依賴的package包/類
protected ModifiersTree getTargetModifiers(VariableTree fieldTree, MethodTree methodTree) {
return fieldTree.getModifiers();
}