• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JCLiteral类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
void test(Object value, TypeTag tag, Type type, Object constValue) {
    JCLiteral l = maker.Literal(value);
    if (!l.type.hasTag(tag))
        error("unexpected tag: " + l.getTag() + ": expected: " + tag);
    if (!types.isSameType(l.type, type))
        error("unexpected type: " + l.type + ": expected: " + type);
    if (l.type.constValue().getClass() != constValue.getClass()
            || !constValue.equals(l.type.constValue()))  {
        error("unexpected const value: "
                + l.type.constValue().getClass() + " " + l.type.constValue()
                + ": expected:" + constValue.getClass() + " " + constValue);
    }
    if (l.getValue().getClass() != value.getClass()
            || !value.equals(l.getValue()))  {
        error("unexpected const value: "
                + l.getValue().getClass() + " " + l.type.constValue()
                + ": expected:" + value.getClass() + " " + value);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:MakeLiteralTest.java


示例2: calculateGuess

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的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


示例3: visitLiteral

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
public void visitLiteral(JCLiteral tree) {
	TypeTag typeTag = typeTag(tree);
	try {
		if (CTC_INT.equals(typeTag)) print(tree.value.toString());
		else if (CTC_LONG.equals(typeTag)) print(tree.value + "L");
		else if (CTC_FLOAT.equals(typeTag)) print(tree.value + "F");
		else if (CTC_DOUBLE.equals(typeTag)) print(tree.value.toString());
		else if (CTC_CHAR.equals(typeTag)) {
			print("\'" + quoteChar((char)((Number)tree.value).intValue()) + "\'");
		}
		else if (CTC_BOOLEAN.equals(typeTag)) print(((Number)tree.value).intValue() == 1 ? "true" : "false");
		else if (CTC_BOT.equals(typeTag)) print("null");
		else print("\"" + quoteChars(tree.value.toString()) + "\"");
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
开发者ID:mobmead,项目名称:EasyMPermission,代码行数:18,代码来源:PrettyCommentsPrinter.java


示例4: inline

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
@Override
public JCLiteral inline(Inliner inliner) {
  Object value = this.getValue();
  switch (getKind()) {
    case CHAR_LITERAL:
      // Why do they do it like this?  I wish I knew.
      value = (int) ((Character) value).charValue();
      break;
    case BOOLEAN_LITERAL:
      value = ((Boolean) value) ? 1 : 0;
      break;
    default:
      // do nothing
  }
  return inliner.maker().Literal(LIT_KIND_TAG.get(getKind()), value);
}
 
开发者ID:sivakumar-kailasam,项目名称:refactor-faster,代码行数:17,代码来源:ULiteral.java


示例5: hasTrueValue

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
/**
 * Verify if the boolean expression have a true value despite of any variable values. 
 * @param expression The boolean expression examined.
 * @return 1 When the expression is always true.
 */
private int hasTrueValue(JCTree expression) {
	if(expression instanceof JCParens){
		if(hasTrueValue(((JCParens)expression).expr) != 0)
			return 1;
	}else if(expression instanceof JCLiteral){
		if(((JCLiteral) expression).value == null)
			return VAR_FALSE_VALUE;
		return (int) ((JCLiteral) expression).value;
	}else if(expression instanceof JmlSingleton){
		return 1;
	}else if(expression instanceof JCBinary){
		return resolveBooleanOperations(expression);
	}
	return VAR_FALSE_VALUE;
}
 
开发者ID:alyssonfm,项目名称:jmlok,代码行数:21,代码来源:Examinator.java


示例6: constValue

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
/** Returns the compile-time constant value of a tree if it has one, or {@code null}. */
@Nullable
public static Object constValue(Tree tree) {
  if (tree == null) {
    return null;
  }
  tree = stripParentheses(tree);
  Type type = ASTHelpers.getType(tree);
  Object value;
  if (tree instanceof JCLiteral) {
    value = ((JCLiteral) tree).value;
  } else if (type != null) {
    value = type.constValue();
  } else {
    return null;
  }
  if (type.hasTag(TypeTag.BOOLEAN) && value instanceof Integer) {
    return ((Integer) value) == 1;
  }
  return value;
}
 
开发者ID:google,项目名称:error-prone,代码行数:22,代码来源:ASTHelpers.java


示例7: matchBinary

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
  if (!(tree.getLeftOperand() instanceof JCLiteral)) {
    return Description.NO_MATCH;
  }
  if (!(tree.getRightOperand() instanceof JCLiteral)) {
    return Description.NO_MATCH;
  }
  Boolean constValue = ASTHelpers.constValue(tree, Boolean.class);
  if (constValue == null) {
    return Description.NO_MATCH;
  }
  return buildDescription(tree)
      .addFix(SuggestedFix.replace(tree, constValue.toString()))
      .setMessage(
          String.format(
              "This expression always evalutes to `%s`, prefer a boolean literal for clarity.",
              constValue))
      .build();
}
 
开发者ID:google,项目名称:error-prone,代码行数:21,代码来源:ComplexBooleanConstant.java


示例8: verifyPrintf

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
private void verifyPrintf(MethodInvocationTree tree, FormatParameters parameters)
    throws FormatFlagsConversionMismatchException, IllegalFormatException, FormatterException {
   List<? extends ExpressionTree> args = tree.getArguments();

  JCLiteral format = (JCLiteral) args.get(parameters.getFormatIndex());
  String formatString = (String) format.getValue();

  List<String> argTypes = new ArrayList<String>();
  for (int i = parameters.getFormatIndex() + 1; i < args.size(); ++i) {
    Type type = ((JCExpression) args.get(i)).type;
    argTypes.add(getFormatterType(type));
  }

  try {
    Formatter.check(formatString, argTypes.toArray(new String[0]));
  } catch (ExtraFormatArgumentsException e) {
    return; // We can handle this.
  }
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:20,代码来源:MisusedFormattingLogger.java


示例9: hashCode

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
/**
 * Note: Do not include node.toString() as part of the hash or the equals.  We generate
 * the WrappedTreeMap after the parse phase, but we compare after the flow phase.  The
 * attribute phase may alter the structure of the AST nodes such that their string
 * representations no longer match.  For example, annotation nodes after the parse phase look
 * like:
 * @SuppressWarnings("foo")
 * But after the flow phase, they look like:
 * @SuppressWarnings(value = "foo")
 */
@Override
public int hashCode() {
  int result = 17;
  result = 31 * result + node.getStartPosition();
  result = 31 * result + node.getPreferredPosition();
  try {
    result = 31 * result + node.getKind().ordinal();
  } catch (AssertionError e) {
    // getKind() throws an AssertionError for LetExpr and TypeBoundKind. Ignore it for 
    // calculating the hash code.
  }
  result = 31 * result + JDKCompatible.getJCTreeTag(node);
  if (node instanceof JCLiteral) {
    Object value = ((JCLiteral) node).getValue();
    if (value != null) {
      result = 31 * result + value.hashCode();
    }
  }
  return result;
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:31,代码来源:WrappedTreeMap.java


示例10: calculateGuess

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的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:redundent,项目名称:lombok,代码行数:23,代码来源:Javac.java


示例11: diffLiteral

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
protected int diffLiteral(JCLiteral oldT, JCLiteral newT, int[] bounds) {
    if (oldT.typetag != newT.typetag ||
       (oldT.value != null && !oldT.value.equals(newT.value)))
    {
        int localPointer = bounds[0];
        // literal
        int[] literalBounds = getBounds(oldT);
        copyTo(localPointer, literalBounds[0]);
        printer.print(newT);
        copyTo(literalBounds[1], bounds[1]);
    } else {
        copyTo(bounds[0], bounds[1]);
    }
    return bounds[1];
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:CasualDiff.java


示例12: visitVarDef

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
/**
 * field definitions: replace initializers with 0, 0.0, false etc
 * when possible -- i.e. leave public, protected initializers alone
 */
@Override
public void visitVarDef(JCVariableDecl tree) {
    tree.mods = translate(tree.mods);
    tree.vartype = translate(tree.vartype);
    if (tree.init != null) {
        if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
            tree.init = translate(tree.init);
        else {
            String t = tree.vartype.toString();
            if (t.equals("boolean"))
                tree.init = new JCLiteral(TypeTag.BOOLEAN, 0) { };
            else if (t.equals("byte"))
                tree.init = new JCLiteral(TypeTag.BYTE, 0) { };
            else if (t.equals("char"))
                tree.init = new JCLiteral(TypeTag.CHAR, 0) { };
            else if (t.equals("double"))
                tree.init = new JCLiteral(TypeTag.DOUBLE, 0.d) { };
            else if (t.equals("float"))
                tree.init = new JCLiteral(TypeTag.FLOAT, 0.f) { };
            else if (t.equals("int"))
                tree.init = new JCLiteral(TypeTag.INT, 0) { };
            else if (t.equals("long"))
                tree.init = new JCLiteral(TypeTag.LONG, 0) { };
            else if (t.equals("short"))
                tree.init = new JCLiteral(TypeTag.SHORT, 0) { };
            else
                tree.init = new JCLiteral(TypeTag.BOT, null) { };
        }
    }
    result = tree;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:GenStubs.java


示例13: visitLiteral

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
@Override public void visitLiteral(JCLiteral tree) {
	TypeTag typeTag = typeTag(tree);
	if (CTC_INT.equals(typeTag)) print("" + tree.value);
	else if (CTC_LONG.equals(typeTag)) print(tree.value + "L");
	else if (CTC_FLOAT.equals(typeTag)) print(tree.value + "F");
	else if (CTC_DOUBLE.equals(typeTag)) print("" + tree.value);
	else if (CTC_CHAR.equals(typeTag)) {
		print("\'" + quoteChar((char)((Number)tree.value).intValue()) + "\'");
	}
	else if (CTC_BOOLEAN.equals(typeTag)) print(((Number)tree.value).intValue() == 1 ? "true" : "false");
	else if (CTC_BOT.equals(typeTag)) print("null");
	else print("\"" + quoteChars(tree.value.toString()) + "\"");
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:14,代码来源:PrettyPrinter.java


示例14: returnVarNameIfNullCheck

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
/**
 * Checks if the statement is of the form 'if (x == null) {throw WHATEVER;},
 * where the block braces are optional. If it is of this form, returns "x".
 * If it is not of this form, returns null.
 */
public String returnVarNameIfNullCheck(JCStatement stat) {
	if (!(stat instanceof JCIf)) return null;
	
	/* Check that the if's statement is a throw statement, possibly in a block. */ {
		JCStatement then = ((JCIf) stat).thenpart;
		if (then instanceof JCBlock) {
			List<JCStatement> stats = ((JCBlock) then).stats;
			if (stats.length() == 0) return null;
			then = stats.get(0);
		}
		if (!(then instanceof JCThrow)) return null;
	}
	
	/* Check that the if's conditional is like 'x == null'. Return from this method (don't generate
	   a nullcheck) if 'x' is equal to our own variable's name: There's already a nullcheck here. */ {
		JCExpression cond = ((JCIf) stat).cond;
		while (cond instanceof JCParens) cond = ((JCParens) cond).expr;
		if (!(cond instanceof JCBinary)) return null;
		JCBinary bin = (JCBinary) cond;
		if (!CTC_EQUAL.equals(treeTag(bin))) return null;
		if (!(bin.lhs instanceof JCIdent)) return null;
		if (!(bin.rhs instanceof JCLiteral)) return null;
		if (!CTC_BOT.equals(typeTag(bin.rhs))) return null;
		return ((JCIdent) bin.lhs).name.toString();
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:32,代码来源:HandleNonNull.java


示例15: test

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
void test(Object value, TypeTag tag, Type type, Object constValue) {
    JCLiteral l = maker.Literal(value);
    if (!l.type.hasTag(tag))
        error("unexpected tag: " + l.getTag() + ": expected: " + tag);
    if (!types.isSameType(l.type, type))
        error("unexpected type: " + l.type + ": expected: " + type);
    if (l.type.constValue().getClass() != constValue.getClass()
            || !constValue.equals(l.type.constValue()))  {
        error("unexpected const value: "
                + l.type.constValue().getClass() + " " + l.type.constValue()
                + ": expected:" + constValue.getClass() + " " + constValue);
    }
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:14,代码来源:MakeLiteralTest.java


示例16: visitLiteral

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
public void visitLiteral(JCLiteral that) {
    try {
        print("JCLiteral:");
    } catch (Exception e) {
    }
    super.visitLiteral(that);
}
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:8,代码来源:PrintAstVisitor.java


示例17: visitUnaryExpression

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
@Override
public boolean visitUnaryExpression(UnaryExpression node) {
	Expression operand = node.astOperand();
	UnaryOperator operator = node.astOperator();
	if (operator == UnaryOperator.UNARY_MINUS && operand instanceof IntegralLiteral) {
		JCLiteral result = (JCLiteral) toTree(operand);
		result.value = negative(result.value);
		return set(node, setPos(operand, result));
	}
	
	int start = node.getPosition().getStart();
	int end = node.getPosition().getEnd();
	
	/*
	 * The pos of "++x" is the entire thing, but the pos of "x++" is only the symbol.
	 * I guess the javac guys think consistency is overrated :(
	 */
	if (hasSourceStructures()) {
		switch (operator) {
		case POSTFIX_DECREMENT:
		case POSTFIX_INCREMENT:
			start = posOfStructure(node, node.astOperator().getSymbol(), true);
			end = posOfStructure(node, node.astOperator().getSymbol(), false);
		}
	}
	
	return set(node, setPos(start, end, treeMaker.Unary(UNARY_OPERATORS.get(operator), toExpression(operand))));
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:29,代码来源:JcTreeBuilder.java


示例18: getLongLiteral

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
/**
 * Extracts the long literal corresponding to a given {@link LiteralTree} node from the source
 * code as a string. Returns null if the source code is not available.
 */
private static String getLongLiteral(LiteralTree literalTree, VisitorState state) {
  JCLiteral longLiteral = (JCLiteral) literalTree;
  CharSequence sourceFile = state.getSourceCode();
  if (sourceFile == null) {
    return null;
  }
  int start = longLiteral.getStartPosition();
  java.util.regex.Matcher matcher =
      LONG_LITERAL_PATTERN.matcher(sourceFile.subSequence(start, sourceFile.length()));
  if (matcher.lookingAt()) {
    return matcher.group();
  }
  return null;
}
 
开发者ID:google,项目名称:error-prone,代码行数:19,代码来源:LongLiteralLowerCaseSuffix.java


示例19: literalHasStartPosition

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
private Matcher<LiteralTree> literalHasStartPosition(final int startPosition) {
  return new Matcher<LiteralTree>() {
    @Override
    public boolean matches(LiteralTree tree, VisitorState state) {
      JCLiteral literal = (JCLiteral) tree;
      return literal.getStartPosition() == startPosition;
    }
  };
}
 
开发者ID:google,项目名称:error-prone,代码行数:10,代码来源:ASTHelpersTest.java


示例20: visitVarDef

import com.sun.tools.javac.tree.JCTree.JCLiteral; //导入依赖的package包/类
/**
 * field definitions: replace initializers with 0, 0.0, false etc
 * when possible -- i.e. leave public, protected initializers alone
 */
@Override
public void visitVarDef(JCVariableDecl tree) {
    tree.mods = translate(tree.mods);
    tree.vartype = translate(tree.vartype);
    if (tree.init != null) {
        if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
            tree.init = translate(tree.init);
        else {
            String t = tree.vartype.toString();
            if (t.equals("boolean"))
                tree.init = new JCLiteral(TypeTags.BOOLEAN, 0) { };
            else if (t.equals("byte"))
                tree.init = new JCLiteral(TypeTags.BYTE, 0) { };
            else if (t.equals("char"))
                tree.init = new JCLiteral(TypeTags.CHAR, 0) { };
            else if (t.equals("double"))
                tree.init = new JCLiteral(TypeTags.DOUBLE, 0.d) { };
            else if (t.equals("float"))
                tree.init = new JCLiteral(TypeTags.FLOAT, 0.f) { };
            else if (t.equals("int"))
                tree.init = new JCLiteral(TypeTags.INT, 0) { };
            else if (t.equals("long"))
                tree.init = new JCLiteral(TypeTags.LONG, 0) { };
            else if (t.equals("short"))
                tree.init = new JCLiteral(TypeTags.SHORT, 0) { };
            else
                tree.init = new JCLiteral(TypeTags.BOT, null) { };
        }
    }
    result = tree;
}
 
开发者ID:aducode,项目名称:openjdk-source-code-learn,代码行数:36,代码来源:GenStubs.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java UnsupportedFileSystemException类代码示例发布时间:2022-05-21
下一篇:
Java IQTypeFilter类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap