当前位置: 首页>>代码示例>>Java>>正文


Java JCIdent类代码示例

本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCIdent的典型用法代码示例。如果您正苦于以下问题:Java JCIdent类的具体用法?Java JCIdent怎么用?Java JCIdent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JCIdent类属于com.sun.tools.javac.tree.JCTree包,在下文中一共展示了JCIdent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitMethodInvocation

import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
    super.visitMethodInvocation(node, p);
    JCMethodInvocation apply = (JCMethodInvocation)node;
    JCIdent ident = (JCIdent)apply.meth;
    Symbol oldSym = ident.sym;
    if (!oldSym.isConstructor()) {
        Object[] staticArgs = new Object[arity.arity];
        for (int i = 0; i < arity.arity ; i++) {
            staticArgs[i] = saks[i].getValue(syms, names, types);
        }
        ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name,
                oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs);
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:TestInvokeDynamic.java

示例2: visitIdent

import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
@Override
public void visitIdent(final JCIdent node) {

	if (node.sym instanceof ClassSymbol) {
		// If this is a ClassSymbol, then we have the type. Apply
		// substitution if necessary.
		print(substitutionInventory.applyTypeSubstitution(node.type));
	} else {
		// Not a type.
		// Attempt template field substitution.
		final String identifier = node.name.toString();
		print(currentSubstitution()
				.filter(field -> substitutionInventory.isSubstitutableFieldName(identifier))
				.orElse(identifier));// Neither a substitutable type nor a substitutable field.
	}
}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:17,代码来源:AstSubstitutionProcessor.java

示例3: calculateGuess

import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
/**
 * Turns an expression into a guessed intended literal. Only works for
 * literals, as you can imagine.
 * 
 * Will for example turn a TrueLiteral into 'Boolean.valueOf(true)'.
 */
public static Object calculateGuess(JCExpression expr) {
	if (expr instanceof JCLiteral) {
		JCLiteral lit = (JCLiteral) expr;
		if (lit.getKind() == com.sun.source.tree.Tree.Kind.BOOLEAN_LITERAL) {
			return ((Number) lit.value).intValue() == 0 ? false : true;
		}
		return lit.value;
	} else if (expr instanceof JCIdent || expr instanceof JCFieldAccess) {
		String x = expr.toString();
		if (x.endsWith(".class")) x = x.substring(0, x.length() - 6);
		else {
			int idx = x.lastIndexOf('.');
			if (idx > -1) x = x.substring(idx + 1);
		}
		return x;
	} else
		return null;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:25,代码来源:Javac.java

示例4: suppress

import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
private boolean suppress(JCTree tree) {
	if (tree instanceof JCBlock) {
		JCBlock block = (JCBlock) tree;
		return (Position.NOPOS == block.pos) && block.stats.isEmpty();
	}
	
	if (tree instanceof JCExpressionStatement) {
		JCExpression expr = ((JCExpressionStatement)tree).expr;
		if (expr instanceof JCMethodInvocation) {
			JCMethodInvocation inv = (JCMethodInvocation) expr;
			if (!inv.typeargs.isEmpty() || !inv.args.isEmpty()) return false;
			if (!(inv.meth instanceof JCIdent)) return false;
			return ((JCIdent) inv.meth).name.toString().equals("super");
		}
	}
	
	return false;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:19,代码来源:PrettyPrinter.java

示例5: visitAnnotation

import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
@Override public void visitAnnotation(JCAnnotation tree) {
	print("@");
	print(tree.annotationType);
	if (tree.args.isEmpty()) return;
	print("(");
	boolean done = false;
	if (tree.args.length() == 1 && tree.args.get(0) instanceof JCAssign) {
		JCAssign arg1 = (JCAssign) tree.args.get(0);
		JCIdent arg1Name = arg1.lhs instanceof JCIdent ? ((JCIdent) arg1.lhs) : null;
		if (arg1Name != null && arg1Name.name == name_value(arg1Name.name)) {
			print(arg1.rhs);
			done = true;
		}
	}
	if (!done) print(tree.args, ", ");
	print(")");
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:18,代码来源:PrettyPrinter.java

示例6: isConstructorCall

import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
public static boolean isConstructorCall(final JCStatement statement) {
	if (!(statement instanceof JCExpressionStatement)) return false;
	JCExpression expr = ((JCExpressionStatement) statement).expr;
	if (!(expr instanceof JCMethodInvocation)) return false;
	JCExpression invocation = ((JCMethodInvocation) expr).meth;
	String name;
	if (invocation instanceof JCFieldAccess) {
		name = ((JCFieldAccess) invocation).name.toString();
	} else if (invocation instanceof JCIdent) {
		name = ((JCIdent) invocation).name.toString();
	} else {
		name = "";
	}
	
	return "super".equals(name) || "this".equals(name);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:17,代码来源:JavacHandlerUtil.java

示例7: unpack

import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
private static void unpack(StringBuilder sb, JCExpression expr) {
	if (expr instanceof JCIdent) {
		sb.append(((JCIdent) expr).name.toString());
		return;
	}
	
	if (expr instanceof JCFieldAccess) {
		JCFieldAccess jcfa = (JCFieldAccess) expr;
		unpack(sb, jcfa.selected);
		sb.append(".").append(jcfa.name.toString());
		return;
	}
	
	if (expr instanceof JCTypeApply) {
		sb.setLength(0);
		sb.append("ERR:");
		sb.append("@Builder(toBuilder=true) is not supported if returning a type with generics applied to an intermediate.");
		sb.append("__ERR__");
		return;
	}
	
	sb.setLength(0);
	sb.append("ERR:");
	sb.append("Expected a type of some sort, not a " + expr.getClass().getName());
	sb.append("__ERR__");
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:27,代码来源:HandleBuilder.java

示例8: visit

import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
@Override
  public JCTree visit(final PackageDeclaration n, final Object arg) {
      //ARG0: JCExpression
      // It returns a full qualified name
      JCExpression arg0 = (JCExpression) n.getName().accept(this, arg);

       /* TODO - Not supporting annotations
if (n.getAnnotations() != null) {
   for (final AnnotationExpr a : n.getAnnotations()) {
  JCTree result = a.accept(this, arg);
   }
}
       */

      if (arg0 instanceof JCIdent) {
          return new AJCIdent((JCIdent) arg0, ((n.getComment() != null) ? n.getComment().getContent() : null));
      }

      return new AJCFieldAccess((JCFieldAccess) arg0, ((n.getComment() != null) ? n.getComment().getContent() : null));
  }
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:21,代码来源:JavaParser2JCTree.java

示例9: visitAnnotation

import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
public void visitAnnotation(JCAnnotation tree) {
	try {
		print("@");
		printExpr(tree.annotationType);
		if (tree.args.nonEmpty()) {
			print("(");
			if (tree.args.length() == 1 && tree.args.get(0) instanceof JCAssign) {
				 JCExpression lhs = ((JCAssign)tree.args.get(0)).lhs;
				 if (lhs instanceof JCIdent && ((JCIdent)lhs).name.toString().equals("value")) tree.args = List.of(((JCAssign)tree.args.get(0)).rhs);
			}
			printExprs(tree.args);
			print(")");
		}
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
开发者ID:mobmead,项目名称:EasyMPermission,代码行数:18,代码来源:PrettyCommentsPrinter.java

示例10: visitClass

import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
@Override
public Object visitClass (ClassTree classTree, Trees trees) {
	Tree extendTree = classTree.getExtendsClause();

	if (extendTree instanceof JCTypeApply) { //generic classes case
		JCTypeApply generic = (JCTypeApply) extendTree;
		extendTree = generic.clazz;
	}

	if (extendTree instanceof JCIdent) {
		JCIdent tree = (JCIdent) extendTree;
		Scope members = tree.sym.members();

		if (checkScope(members))
			return super.visitClass(classTree, trees);

		if (checkSuperTypes((ClassType) tree.type))
			return super.visitClass(classTree, trees);

	}
	callSuperUsed = false;

	return super.visitClass(classTree, trees);
}
 
开发者ID:kotcrab,项目名称:callsuper-annotation,代码行数:25,代码来源:CodeAnalyzerTreeScanner.java

示例11: visitTypeReferencePart

import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
@Override
public boolean visitTypeReferencePart(TypeReferencePart node) {
	JCIdent ident = (JCIdent) toTree(node.astIdentifier());
	
	List<JCExpression> typeArguments = toList(JCExpression.class, node.astTypeArguments());
	if (typeArguments.isEmpty()) {
		return set(node, ident);
	} else {
		JCTypeApply typeApply = treeMaker.TypeApply(ident, typeArguments);
		Position jcOpenBracketPos = getConversionPositionInfo(node, "<");
		if (jcOpenBracketPos == null) {
			setPos(posOfStructure(node, "<", true), node.getPosition().getEnd(), typeApply);
		} else {
			setPos(jcOpenBracketPos.getStart(), node.getPosition().getEnd(), typeApply);
		}
		return set(node, typeApply);
	}
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:19,代码来源:JcTreeBuilder.java

示例12: isThereInMiniTree

import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
/**
 * This function walks into a tree with nodes of type JCBinary to search for 
 * a string as one of the elements of the tree.
 * @param toTest The String searched as Element in the tree.
 * @param expression The bifurcation tree searched.
 * @return True if the string was found, or False.
 */
private boolean isThereInMiniTree(String toTest, JCTree expression) {
	if(expression instanceof JCParens){
		if(isThereInMiniTree(toTest, ((JCParens) expression).expr))
			return true;
	} else if(expression instanceof JCIdent){
		if(((JCIdent) expression).name.toString().equals(toTest))
			return true;
	} else if(expression instanceof JCBinary){
		if(isThereInMiniTree(toTest, ((JCBinary) expression).rhs))
			return true;
		if(isThereInMiniTree(toTest, ((JCBinary) expression).lhs))
			return true;
	}
	return false;
}
 
开发者ID:alyssonfm,项目名称:jmlok,代码行数:23,代码来源:Examinator.java

示例13: receiverSameAsArgument

import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
/**
 * Matches when the receiver of an instance method is the same reference as a particular argument
 * to the method. For example, receiverSameAsArgument(1) would match {@code obj.method("", obj)}
 *
 * @param argNum The number of the argument to compare against (zero-based.
 */
public static Matcher<? super MethodInvocationTree> receiverSameAsArgument(final int argNum) {
  return new Matcher<MethodInvocationTree>() {
    @Override
    public boolean matches(MethodInvocationTree t, VisitorState state) {
      List<? extends ExpressionTree> args = t.getArguments();
      if (args.size() <= argNum) {
        return false;
      }
      ExpressionTree arg = args.get(argNum);

      JCExpression methodSelect = (JCExpression) t.getMethodSelect();
      if (methodSelect instanceof JCFieldAccess) {
        JCFieldAccess fieldAccess = (JCFieldAccess) methodSelect;
        return ASTHelpers.sameVariable(fieldAccess.getExpression(), arg);
      } else if (methodSelect instanceof JCIdent) {
        // A bare method call: "equals(foo)".  Receiver is implicitly "this".
        return "this".equals(arg.toString());
      }

      return false;
    }
  };
}
 
开发者ID:google,项目名称:error-prone,代码行数:30,代码来源:Matchers.java

示例14: getSymbol

import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
/**
 * Gets the symbol for a tree. Returns null if this tree does not have a symbol because it is of
 * the wrong type, if {@code tree} is null, or if the symbol cannot be found due to a compilation
 * error.
 */
// TODO(eaftan): refactor other code that accesses symbols to use this method
public static Symbol getSymbol(Tree tree) {
  if (tree instanceof JCFieldAccess) {
    return ((JCFieldAccess) tree).sym;
  }
  if (tree instanceof JCIdent) {
    return ((JCIdent) tree).sym;
  }
  if (tree instanceof JCMethodInvocation) {
    return ASTHelpers.getSymbol((MethodInvocationTree) tree);
  }
  if (tree instanceof JCNewClass) {
    return ASTHelpers.getSymbol((NewClassTree) tree);
  }
  if (tree instanceof MemberReferenceTree) {
    return ((JCMemberReference) tree).sym;
  }
  if (tree instanceof JCAnnotatedType) {
    return getSymbol(((JCAnnotatedType) tree).underlyingType);
  }

  return getDeclaredSymbol(tree);
}
 
开发者ID:google,项目名称:error-prone,代码行数:29,代码来源:ASTHelpers.java

示例15: getReceiverType

import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
/**
 * Returns the type of a receiver of a method call expression. Precondition: the expressionTree
 * corresponds to a method call.
 *
 * <p>Examples:
 *
 * <pre>{@code
 * a.b.foo() ==> type of a.b
 * a.bar().foo() ==> type of a.bar()
 * this.foo() ==> type of this
 * foo() ==> type of this
 * TheClass.aStaticMethod() ==> TheClass
 * aStaticMethod() ==> type of class in which method is defined
 * }</pre>
 */
public static Type getReceiverType(ExpressionTree expressionTree) {
  if (expressionTree instanceof JCFieldAccess) {
    JCFieldAccess methodSelectFieldAccess = (JCFieldAccess) expressionTree;
    return methodSelectFieldAccess.selected.type;
  } else if (expressionTree instanceof JCIdent) {
    JCIdent methodCall = (JCIdent) expressionTree;
    return methodCall.sym.owner.type;
  } else if (expressionTree instanceof JCMethodInvocation) {
    return getReceiverType(((JCMethodInvocation) expressionTree).getMethodSelect());
  } else if (expressionTree instanceof JCMemberReference) {
    return ((JCMemberReference) expressionTree).getQualifierExpression().type;
  }
  throw new IllegalArgumentException(
      "Expected a JCFieldAccess or JCIdent from expression " + expressionTree);
}
 
开发者ID:google,项目名称:error-prone,代码行数:31,代码来源:ASTHelpers.java


注:本文中的com.sun.tools.javac.tree.JCTree.JCIdent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。