本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCVariableDecl方法的典型用法代码示例。如果您正苦于以下问题:Java JCTree.JCVariableDecl方法的具体用法?Java JCTree.JCVariableDecl怎么用?Java JCTree.JCVariableDecl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.tree.JCTree
的用法示例。
在下文中一共展示了JCTree.JCVariableDecl方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runField
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private void runField(String code) throws IOException {
String src = prefix +
code + "; }" +
postfix;
try (JavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null, null,
null, Arrays.asList(new MyFileObject(src)));
for (CompilationUnitTree cut : ct.parse()) {
JCTree.JCVariableDecl var =
(JCTree.JCVariableDecl) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0);
checkMatch(code, var);
}
}
}
示例2: run
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
void run(String code) throws IOException {
String src = "public class Test {" + code + ";}";
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null,
null, Arrays.asList(new MyFileObject(src)));
for (CompilationUnitTree cut : ct.parse()) {
JCTree.JCVariableDecl var =
(JCTree.JCVariableDecl) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0);
if (!code.equals(var.toString())) {
System.err.println("Expected: " + code);
System.err.println("Obtained: " + var.toString());
throw new RuntimeException("strings do not match!");
}
}
}
示例3: visitVarDef
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override public void visitVarDef(JCTree.JCVariableDecl jcVariableDecl) {
if ("int".equals(jcVariableDecl.getType().toString())) {
int id = Integer.valueOf(jcVariableDecl.getInitializer().toString());
String resourceName = jcVariableDecl.getName().toString();
QualifiedId qualifiedId = new QualifiedId(respectivePackageName, id);
ids.put(qualifiedId, new Id(id, className, resourceName));
}
}
示例4: visitVariable
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override
@CheckForNull
public Void visitVariable(@NonNull final VariableTree node, @NonNull final Map<Pair<BinaryName, String>, UsagesData<String>> p) {
Symbol s = ((JCTree.JCVariableDecl)node).sym;
if (s != null && s.owner != null && (s.owner.getKind().isClass() || s.owner.getKind().isInterface())) {
addIdent(activeClass.peek(), node.getName(), p, true);
}
return super.visitVariable(node, p);
}
示例5: visitVarDef
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override
public void visitVarDef(JCTree.JCVariableDecl jcVariableDecl) {
if ("int".equals(jcVariableDecl.getType().toString())) {
int id = Integer.valueOf(jcVariableDecl.getInitializer().toString());
String resourceName = jcVariableDecl.getName().toString();
QualifiedId qualifiedId = new QualifiedId(respectivePackageName, id);
ids.put(qualifiedId, new Id(id, className, resourceName));
}
}
示例6: visitIdent
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
/**
* Erase all structural interface type literals to Object
*/
@Override
public void visitIdent( JCTree.JCIdent tree )
{
super.visitIdent( tree );
if( _tp.isGenerate() && !shouldProcessForGeneration() )
{
// Don't process tree during GENERATE, unless the tree was generated e.g., a bridge method
return;
}
if( tree.sym != null && TypeUtil.isStructuralInterface( _tp, tree.sym ) && !isReceiver( tree ) )
{
Symbol.ClassSymbol objectSym = getObjectClass();
Tree parent = _tp.getParent( tree );
JCTree.JCIdent objIdent = _tp.getTreeMaker().Ident( objectSym );
if( parent instanceof JCTree.JCVariableDecl )
{
((JCTree.JCVariableDecl)parent).type = objectSym.type;
long parameterModifier = 8589934592L; // Flag.Flag.PARAMETER.value
if( (((JCTree.JCVariableDecl)parent).mods.flags & parameterModifier) != 0 )
{
objIdent.type = objectSym.type;
((JCTree.JCVariableDecl)parent).sym.type = objectSym.type;
((JCTree.JCVariableDecl)parent).vartype = objIdent;
}
}
else if( parent instanceof JCTree.JCWildcard )
{
JCTree.JCWildcard wildcard = (JCTree.JCWildcard)parent;
wildcard.type = new Type.WildcardType( objectSym.type, wildcard.kind.kind, wildcard.type.tsym );
}
tree = objIdent;
tree.type = objectSym.type;
}
result = tree;
}
示例7: visitSelect
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
/**
* Erase all structural interface type literals to Object
*/
@Override
public void visitSelect( JCTree.JCFieldAccess tree )
{
super.visitSelect( tree );
if( _tp.isGenerate() && !shouldProcessForGeneration() )
{
// Don't process tree during GENERATE, unless the tree was generated e.g., a bridge method
return;
}
if( TypeUtil.isStructuralInterface( _tp, tree.sym ) && !isReceiver( tree ) )
{
Symbol.ClassSymbol objectSym = getObjectClass();
JCTree.JCIdent objIdent = _tp.getTreeMaker().Ident( objectSym );
Tree parent = _tp.getParent( tree );
if( parent instanceof JCTree.JCVariableDecl )
{
((JCTree.JCVariableDecl)parent).type = objectSym.type;
long parameterModifier = 8589934592L; // Flag.Flag.PARAMETER.value
if( (((JCTree.JCVariableDecl)parent).mods.flags & parameterModifier) != 0 )
{
objIdent.type = objectSym.type;
((JCTree.JCVariableDecl)parent).sym.type = objectSym.type;
((JCTree.JCVariableDecl)parent).vartype = objIdent;
}
}
else if( parent instanceof JCTree.JCWildcard )
{
JCTree.JCWildcard wildcard = (JCTree.JCWildcard)parent;
wildcard.type = new Type.WildcardType( objectSym.type, wildcard.kind.kind, wildcard.type.tsym );
}
result = objIdent;
}
else
{
result = tree;
}
}