本文整理匯總了Java中com.sun.source.tree.ExpressionTree.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java ExpressionTree.toString方法的具體用法?Java ExpressionTree.toString怎麽用?Java ExpressionTree.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.source.tree.ExpressionTree
的用法示例。
在下文中一共展示了ExpressionTree.toString方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: className
import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
private static String className(TreePath path) {
ClassTree ct = (ClassTree) path.getLeaf();
if (path.getParentPath().getLeaf().getKind() == Kind.NEW_CLASS) {
NewClassTree nct = (NewClassTree) path.getParentPath().getLeaf();
if (nct.getClassBody() == ct) {
return simpleName(nct.getIdentifier());
}
} else if (path.getParentPath().getLeaf() == path.getCompilationUnit()) {
ExpressionTree pkg = path.getCompilationUnit().getPackageName();
String pkgName = pkg != null ? pkg.toString() : null;
if (pkgName != null && !pkgName.contentEquals(ERR_NAME)) {
return pkgName + '.' + ct.getSimpleName().toString();
}
}
return ct.getSimpleName().toString();
}
示例2: isFirstStatementThisOrSuperCall
import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
private static boolean isFirstStatementThisOrSuperCall(@NotNull JCTree.JCBlock body) {
List<JCTree.JCStatement> statements = body.getStatements();
if (statements.isEmpty()) {
return false;
}
JCTree.JCStatement expressionCandidate = statements.get(0);
if (expressionCandidate instanceof ExpressionStatementTree) {
ExpressionStatementTree expression = (ExpressionStatementTree) expressionCandidate;
ExpressionTree methodInvocationCandidate = expression.getExpression();
if (methodInvocationCandidate instanceof MethodInvocationTree) {
MethodInvocationTree methodInvocation = (MethodInvocationTree) methodInvocationCandidate;
ExpressionTree methodSelect = methodInvocation.getMethodSelect();
if (methodSelect != null) {
String select = methodSelect.toString();
return "this".equals(select) || "super".equals(select);
}
}
}
return false;
}
示例3: matchDereference
import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
private Description matchDereference(
ExpressionTree baseExpression, ExpressionTree derefExpression, VisitorState state) {
Symbol dereferenced = ASTHelpers.getSymbol(baseExpression);
if (dereferenced == null
|| dereferenced.type.isPrimitive()
|| !kindMayDeferenceNull(dereferenced.getKind())) {
// we know we don't have a null dereference here
return Description.NO_MATCH;
}
if (mayBeNullExpr(state, baseExpression)) {
String message = "dereferenced expression " + baseExpression.toString() + " is @Nullable";
return createErrorDescriptionForNullAssignment(
MessageTypes.DEREFERENCE_NULLABLE,
derefExpression,
message,
baseExpression,
state.getPath());
}
return Description.NO_MATCH;
}
示例4: addInputFile
import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
private void addInputFile( TaskEvent e )
{
if( !_initialized )
{
CompilationUnitTree compilationUnit = e.getCompilationUnit();
ExpressionTree pkg = compilationUnit.getPackageName();
String packageQualifier = pkg == null ? "" : (pkg.toString() + '.');
for( Tree classDecl : compilationUnit.getTypeDecls() )
{
if( classDecl instanceof JCTree.JCClassDecl )
{
_javaInputFiles.add( new Pair<>( packageQualifier + ((JCTree.JCClassDecl)classDecl).getSimpleName(), compilationUnit.getSourceFile() ) );
}
}
}
}
示例5: resolveThrowsName
import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
/**
* computes name of throws clause to work around
* <a href="http://www.netbeans.org/issues/show_bug.cgi?id=160414">issue 160414</a>.
*/
private static String resolveThrowsName(Element el, String fqn, ExpressionTree throwTree) {
boolean nestedClass = ElementKind.CLASS == el.getKind()
&& NestingKind.TOP_LEVEL != ((TypeElement) el).getNestingKind();
String insertName = nestedClass ? fqn : throwTree.toString();
return insertName;
}
示例6: process
import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
private void process( TaskEvent e )
{
Set<String> typesToProcess = new HashSet<>();
ExpressionTree pkg = e.getCompilationUnit().getPackageName();
String packageQualifier = pkg == null ? "" : (pkg.toString() + '.');
for( Tree classDecl : e.getCompilationUnit().getTypeDecls() )
{
if( classDecl instanceof JCTree.JCClassDecl )
{
typesToProcess.add( packageQualifier + ((JCTree.JCClassDecl)classDecl).getSimpleName() );
insertBootstrap( (JCTree.JCClassDecl)classDecl );
}
}
_typeProcessor.addTypesToProcess( typesToProcess );
}
示例7: ImportVisitor
import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
private ImportVisitor (CompilationInfo info) {
this.info = info;
ExpressionTree pkg = info.getCompilationUnit().getPackageName();
currentPackage = pkg != null ? pkg.toString() : "";
imports = new ArrayList<TreePathHandle>();
}
示例8: visitThrows
import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
@Override
public Void visitThrows(ThrowsTree tree, List<ErrorDescription> errors) {
boolean oldInheritDoc = foundInheritDoc;
ReferenceTree exName = tree.getExceptionName();
DocTreePath refPath = new DocTreePath(getCurrentPath(), tree.getExceptionName());
Element ex = javac.getDocTrees().getElement(refPath);
Types types = javac.getTypes();
Elements elements = javac.getElements();
final TypeElement throwableEl = elements.getTypeElement("java.lang.Throwable");
final TypeElement errorEl = elements.getTypeElement("java.lang.Error");
final TypeElement runtimeEl = elements.getTypeElement("java.lang.RuntimeException");
if(throwableEl == null || errorEl == null || runtimeEl == null) {
LOG.warning("Broken java-platform, cannot resolve " + throwableEl == null? "java.lang.Throwable" : errorEl == null? "java.lang.Error" : "java.lang.RuntimeException"); //NOI18N
return null;
}
TypeMirror throwable = throwableEl.asType();
TypeMirror error = errorEl.asType();
TypeMirror runtime = runtimeEl.asType();
DocTreePath currentDocPath = getCurrentPath();
DocTreePathHandle dtph = DocTreePathHandle.create(currentDocPath, javac);
if(dtph == null) {
return null;
}
DocSourcePositions sp = (DocSourcePositions) javac.getTrees().getSourcePositions();
int start = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), tree);
int end = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), tree);
if (ex == null || (ex.asType().getKind() == TypeKind.DECLARED
&& types.isAssignable(ex.asType(), throwable))) {
switch (currentElement.getKind()) {
case CONSTRUCTOR:
case METHOD:
if (ex == null || !(types.isAssignable(ex.asType(), error)
|| types.isAssignable(ex.asType(), runtime))) {
ExecutableElement ee = (ExecutableElement) currentElement;
String fqn;
if (ex != null) {
fqn = ((TypeElement) ex).getQualifiedName().toString();
} else {
ExpressionTree referenceClass = javac.getTreeUtilities().getReferenceClass(new DocTreePath(currentDocPath, exName));
if(referenceClass == null) break;
fqn = referenceClass.toString();
}
checkThrowsDeclared(tree, ex, fqn, ee.getThrownTypes(), dtph, start, end, errors);
}
break;
default:
// env.messages.error(REFERENCE, tree, "dc.invalid.throws");
}
} else {
// env.messages.error(REFERENCE, tree, "dc.invalid.throws");
}
warnIfEmpty(tree, tree.getDescription());
super.visitThrows(tree, errors);
foundInheritDoc = oldInheritDoc;
return null;
}
示例9: handleInvocation
import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
/**
* handle either a method invocation or a 'new' invocation
*
* @param state visitor state
* @param methodSymbol symbol for invoked method
* @param actualParams parameters passed at call
* @return description of error or NO_MATCH if no error
*/
private Description handleInvocation(
VisitorState state,
Symbol.MethodSymbol methodSymbol,
List<? extends ExpressionTree> actualParams) {
ImmutableSet<Integer> nonNullPositions = null;
if (NullabilityUtil.fromUnannotatedPackage(methodSymbol, config)) {
nonNullPositions =
handler.onUnannotatedInvocationGetNonNullPositions(
this, state, methodSymbol, actualParams, ImmutableSet.of());
}
if (nonNullPositions == null) {
ImmutableSet.Builder<Integer> builder = ImmutableSet.builder();
// compute which arguments are @NonNull
List<VarSymbol> formalParams = methodSymbol.getParameters();
for (int i = 0; i < formalParams.size(); i++) {
if (i == formalParams.size() - 1 && methodSymbol.isVarArgs()) {
// eventually, handle this case properly. I *think* a null
// array could be passed in incorrectly. For now, punt
continue;
}
VarSymbol param = formalParams.get(i);
if (param.type.isPrimitive()) {
Description unboxingCheck = doUnboxingCheck(state, actualParams.get(i));
if (unboxingCheck != Description.NO_MATCH) {
return unboxingCheck;
} else {
continue;
}
}
boolean nullable = Nullness.hasNullableAnnotation(param);
if (!nullable) {
builder.add(i);
}
}
nonNullPositions = builder.build();
}
if (nonNullPositions.isEmpty()) {
return Description.NO_MATCH;
}
// now actually check the arguments
for (int argPos : nonNullPositions) {
// make sure we are passing a non-null value
ExpressionTree actual = actualParams.get(argPos);
if (mayBeNullExpr(state, actual)) {
String message =
"passing @Nullable parameter '" + actual.toString() + "' where @NonNull is required";
return createErrorDescriptionForNullAssignment(
MessageTypes.PASS_NULLABLE, actual, message, actual, state.getPath());
}
}
// NOTE: the case of an invocation on a possibly-null reference
// is handled by matchMemberSelect()
return Description.NO_MATCH;
}
示例10: processExpression
import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
private List<Snippet> processExpression(String userSource, String compileSource) {
String name = null;
ExpressionInfo ei = ExpressionToTypeInfo.expressionInfo(compileSource, state);
ExpressionTree assignVar;
Wrap guts;
Snippet snip;
if (ei != null && ei.isNonVoid) {
String typeName = ei.typeName;
SubKind subkind;
if (ei.tree instanceof IdentifierTree) {
IdentifierTree id = (IdentifierTree) ei.tree;
name = id.getName().toString();
subkind = SubKind.VAR_VALUE_SUBKIND;
} else if (ei.tree instanceof AssignmentTree
&& (assignVar = ((AssignmentTree) ei.tree).getVariable()) instanceof IdentifierTree) {
name = assignVar.toString();
subkind = SubKind.ASSIGNMENT_SUBKIND;
} else {
subkind = SubKind.OTHER_EXPRESSION_SUBKIND;
}
if (shouldGenTempVar(subkind)) {
if (preserveState) {
name = "$$";
} else {
if (state.tempVariableNameGenerator != null) {
name = state.tempVariableNameGenerator.get();
}
while (name == null || state.keyMap.doesVariableNameExist(name)) {
name = "$" + ++varNumber;
}
}
guts = Wrap.tempVarWrap(compileSource, typeName, name);
Collection<String> declareReferences = null; //TODO
snip = new VarSnippet(state.keyMap.keyForVariable(name), userSource, guts,
name, SubKind.TEMP_VAR_EXPRESSION_SUBKIND, typeName, declareReferences, null);
} else {
guts = Wrap.methodReturnWrap(compileSource);
snip = new ExpressionSnippet(state.keyMap.keyForExpression(name, typeName), userSource, guts,
name, subkind);
}
} else {
guts = Wrap.methodWrap(compileSource);
if (ei == null) {
// We got no type info, check for not a statement by trying
AnalyzeTask at = trialCompile(guts);
if (at.getDiagnostics().hasNotStatement()) {
guts = Wrap.methodReturnWrap(compileSource);
at = trialCompile(guts);
}
if (at.hasErrors()) {
return compileFailResult(at, userSource, Kind.EXPRESSION);
}
}
snip = new StatementSnippet(state.keyMap.keyForStatement(), userSource, guts);
}
return singletonList(snip);
}