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

Java Tree类代码示例

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

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



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

示例1: buildGraph

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
private void buildGraph(Tree tree) {
  String label = tree.kind() + (tree.firstToken() != null ? (" L#" + tree.firstToken().line()) : "");
  addNode(new ASTDotNode(index, label, tree.kind()));
  if (tree.is(Tree.Kind.TOKEN)) {
    // add an extra node for tokens
    addNode(new ASTDotNode(index, escapeSpecialChars(((SyntaxToken) tree).text())));
  }
  int currentNodeIndex = index;
  if (!((JavaTree) tree).isLeaf()) {
    for (Tree child : ((JavaTree) tree).getChildren()) {
      index++;
      int childIndex = index;
      buildGraph(child);
      addEdge(new ASTDotEdge(currentNodeIndex, childIndex));
    }
  }
}
 
开发者ID:SonarSource,项目名称:source-graph-viewer,代码行数:18,代码来源:ASTDotGraph.java


示例2: visitMethod

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
@Override
public void visitMethod(MethodTree tree) {
  if (implementsSpecificInterface) {
    List<AnnotationTree> annotations = tree.modifiers().annotations();

    boolean isHavingMandatoryAnnotation = Boolean.FALSE;

    for (AnnotationTree annotationTree : annotations) {
      if (annotationTree.annotationType().is(Tree.Kind.IDENTIFIER)) {
        IdentifierTree idf = (IdentifierTree) annotationTree.annotationType();
        LOGGER.info("Method Name {}", idf.name());

        if (idf.name().equals(name)) {
          isHavingMandatoryAnnotation = Boolean.TRUE;
        }
      }
    }
    if (!isHavingMandatoryAnnotation) {
      context.reportIssue(this, tree, String.format("Mandatory Annotation not set @%s", name));
    }

  }
  // The call to the super implementation allows to continue the visit of the AST.
  // Be careful to always call this method to visit every node of the tree.
  super.visitMethod(tree);
}
 
开发者ID:SonarSource,项目名称:sonar-custom-rules-examples,代码行数:27,代码来源:SecurityAnnotationMandatoryRule.java


示例3: visitNode

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
@Override
public void visitNode(Tree tree) {
  // Cast the node to the correct type :
  // in this case we registered only to one kind so we will only receive MethodTree see Tree.Kind enum to know about which type you can
  // cast depending on Kind.
  MethodTree methodTree = (MethodTree) tree;
  // Retrieve symbol of method.
  MethodSymbol methodSymbol = methodTree.symbol();
  Type returnType = methodSymbol.returnType().type();
  // Check method has only one argument.
  if (methodSymbol.parameterTypes().size() == 1) {
    Type argType = methodSymbol.parameterTypes().get(0);
    // Verify argument type is same as return type.
    if (argType.is(returnType.fullyQualifiedName())) {
      // raise an issue on this node of the SyntaxTree
      reportIssue(tree, "message");
    }
  }
}
 
开发者ID:SonarSource,项目名称:sonar-custom-rules-examples,代码行数:20,代码来源:MyCustomSubscriptionRule.java


示例4: visitNode

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
@Override
public void visitNode(Tree tree) {
  // Visit CLASS node only => cast could be done
  ClassTree treeClazz = (ClassTree) tree;

  // No extends => stop to visit class
  if (treeClazz.superClass() == null) {
    return;
  }

  // For 'symbolType' usage, jar in dependencies must be on classpath, !unknownSymbol! result otherwise
  String superClassName = treeClazz.superClass().symbolType().fullyQualifiedName();

  // Check if superClass avoid
  if (SUPER_CLASS_AVOID.contains(superClassName)) {
    reportIssue(tree, String.format("The usage of super class %s is forbidden", superClassName));
  }
}
 
开发者ID:SonarSource,项目名称:sonar-custom-rules-examples,代码行数:19,代码来源:AvoidSuperClassRule.java


示例5: visitMethod

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
@Override
public void visitMethod(MethodTree tree) {
  List<AnnotationTree> annotations = tree.modifiers().annotations();
  for (AnnotationTree annotationTree : annotations) {
    if (annotationTree.annotationType().is(Tree.Kind.IDENTIFIER)) {
      IdentifierTree idf = (IdentifierTree) annotationTree.annotationType();
      System.out.println(idf.name());

      if (idf.name().equals(name)) {
        context.reportIssue(this, idf, String.format("Avoid using annotation @%s", name));
      }
    }
  }

  // The call to the super implementation allows to continue the visit of the AST.
  // Be careful to always call this method to visit every node of the tree.
  super.visitMethod(tree);
}
 
开发者ID:SonarSource,项目名称:sonar-custom-rules-examples,代码行数:19,代码来源:AvoidAnnotationRule.java


示例6: checkIfLongSession

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
protected boolean checkIfLongSession(MethodTree method) {
	List<AnnotationTree> annotations = method.modifiers().annotations();
	for (AnnotationTree annotationTree : annotations) {
		if (annotationTree.annotationType().is(Tree.Kind.IDENTIFIER)) {
			IdentifierTree idf = (IdentifierTree) annotationTree.annotationType();
			if (idf.name().equals(ACTIVATE)) {
				collectLongSessionOpened(method);
				return true;
			}
			else if (idf.name().equals(DEACTIVATE)) {
				collectLongSessionClosed(method);
				return true;
			}
		}
	}
	return false;
}
 
开发者ID:Cognifide,项目名称:AEM-Rules-for-SonarQube,代码行数:18,代码来源:SessionShouldBeLoggedOut.java


示例7: checkIfLongResourceResolver

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
protected boolean checkIfLongResourceResolver(MethodTree method) {
	List<AnnotationTree> annotations = method.modifiers().annotations();
	for (AnnotationTree annotationTree : annotations) {
		if (annotationTree.annotationType().is(Tree.Kind.IDENTIFIER)) {
			IdentifierTree idf = (IdentifierTree) annotationTree.annotationType();
			if (idf.name().equals(ACTIVATE)) {
				collectLongResourceResolverOpened(method);
				return true;
			}
			else if (idf.name().equals(DEACTIVATE)) {
				collectLongResourceResolverClosed(method);
				return true;
			}
		}
	}
	return false;
}
 
开发者ID:Cognifide,项目名称:AEM-Rules-for-SonarQube,代码行数:18,代码来源:ResourceResolverShouldBeClosed.java


示例8: appendElements

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
private static void appendElements(StringBuilder buffer, CFG.Block block) {
  int i = 0;
  for (Tree tree : block.elements()) {
    buffer.append('\n');
    buffer.append(i);
    buffer.append(":\t");
    appendKind(buffer, tree.kind());
    buffer.append(toString(tree));
    i++;
  }
}
 
开发者ID:SonarSource,项目名称:source-graph-viewer,代码行数:12,代码来源:CFGPrinter.java


示例9: appendTerminator

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
private static void appendTerminator(StringBuilder buffer, CFG.Block block) {
  Tree terminator = block.terminator();
  if (terminator != null) {
    buffer.append("\nT:\t");
    appendKind(buffer, terminator.kind());
    buffer.append(toString(terminator));
  }
}
 
开发者ID:SonarSource,项目名称:source-graph-viewer,代码行数:9,代码来源:CFGPrinter.java


示例10: toString

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
private static String toString(Tree tree) {
  Stream.Builder<String> sb = Stream.builder();
  switch (tree.kind()) {
    case TOKEN:
      sb.add(((SyntaxToken) tree).text());
      break;
    case VARIABLE:
      VariableTree vt = (VariableTree) tree;
      // skip initializer
      addTrees(sb, vt.type(), vt.simpleName());
      break;
    case NEW_CLASS:
      NewClassTree nct = (NewClassTree) tree;
      // skip body for anonymous classes
      addTrees(sb, nct.newKeyword(), nct.identifier(), nct.arguments());
      break;
    case MEMBER_SELECT:
      MemberSelectExpressionTree mset = (MemberSelectExpressionTree) tree;
      if (mset.expression().is(Tree.Kind.METHOD_INVOCATION)) {
        // skip method invocation
        addTrees(sb, mset.identifier());
      } else {
        addChildren(sb, tree);
      }
      break;
    case IF_STATEMENT:
      IfStatementTree ist = (IfStatementTree) tree;
      // skip thenClause and elseClause
      addTrees(sb, ist.ifKeyword(), ist.openParenToken(), ist.condition(), ist.closeParenToken());
      break;
    default:
      addChildren(sb, tree);
      break;
  }
  return sb.build().filter(text -> !text.isEmpty()).collect(Collectors.joining(" "));
}
 
开发者ID:SonarSource,项目名称:source-graph-viewer,代码行数:37,代码来源:CFGPrinter.java


示例11: addChildren

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
private static void addChildren(Stream.Builder<String> sb, Tree tree) {
  if (tree.is(Tree.Kind.INFERED_TYPE)) {
    // do nothing, infered types does not have children
    return;
  }
  addTrees(sb, ((JavaTree) tree).getChildren());
}
 
开发者ID:SonarSource,项目名称:source-graph-viewer,代码行数:8,代码来源:CFGPrinter.java


示例12: programPoint

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
private String programPoint() {
  String tree = "";
  if (pp.i < pp.block.elements().size()) {
    Tree syntaxNode = ((CFG.Block) pp.block).elements().get(pp.i);
    tree = "" + syntaxNode.kind() + " L#" + syntaxNode.firstToken().line();
  }
  return programPointKey() + "  " + tree;
}
 
开发者ID:SonarSource,项目名称:source-graph-viewer,代码行数:9,代码来源:EGDotNode.java


示例13: getMethodBehavior

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
@CheckForNull
private static MethodBehavior getMethodBehavior(BehaviorCache bc, @Nullable Tree syntaxTree) {
  if (syntaxTree == null || !syntaxTree.is(Tree.Kind.METHOD_INVOCATION)) {
    return null;
  }
  Symbol symbol = ((MethodInvocationTree) syntaxTree).symbol();
  if (!symbol.isMethodSymbol()) {
    return null;
  }
  return bc.get((Symbol.MethodSymbol) symbol);
}
 
开发者ID:SonarSource,项目名称:source-graph-viewer,代码行数:12,代码来源:EGDotNode.java


示例14: getFirstMethodOrConstructor

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
@CheckForNull
private static MethodTree getFirstMethodOrConstructor(CompilationUnitTree cut) {
  return (MethodTree) cut.types().stream()
    .findFirst()
    .map(ClassTree.class::cast)
    .map(ClassTree::members)
    .map(List::stream)
    .flatMap(members -> members.filter(m -> m.is(Tree.Kind.METHOD, Tree.Kind.CONSTRUCTOR)).findFirst())
    .orElse(null);
}
 
开发者ID:SonarSource,项目名称:source-graph-viewer,代码行数:11,代码来源:Viewer.java


示例15: visitNode

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
@Override
public void visitNode(Tree tree) {

  if (((NewClassTree) tree).symbolType().isSubtypeOf("org.apache.commons.collections4.list.UnmodifiableList")) {
    reportIssue(tree, "Avoid using UnmodifiableList");
  }
}
 
开发者ID:SonarSource,项目名称:sonar-custom-rules-examples,代码行数:8,代码来源:AvoidUnmodifiableListRule.java


示例16: scan

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
@Override
protected void scan(List<? extends Tree> trees) {
  if (!trees.isEmpty()) {
    sb.deleteCharAt(sb.length() - 1);
    sb.append(" : [\n");
    super.scan(trees);
    indent().append("]\n");
  }
}
 
开发者ID:SonarSource,项目名称:sonar-custom-rules-examples,代码行数:10,代码来源:PrinterVisitor.java


示例17: visitReturnStatement

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
@Override
public void visitReturnStatement(ReturnStatementTree tree) {
	if (tree.expression() != null && tree.expression().is(Kind.IDENTIFIER)) {
		IdentifierTree identifier = (IdentifierTree) tree.expression();
		Tree declaration = getDeclaration(identifier);
		if (sessions.contains(declaration)) {
			sessions.remove(declaration);
		}
	}
	super.visitReturnStatement(tree);
}
 
开发者ID:Cognifide,项目名称:AEM-Rules-for-SonarQube,代码行数:12,代码来源:FindSessionDeclarationVisitor.java


示例18: visitMethodInvocation

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
@Override
public void visitMethodInvocation(MethodInvocationTree tree) {
	Tree declaration = tree.symbol().declaration();
	if (null != declaration) {
		declaration.accept(new MethodInvocationVisitor(javaFileScanner, context));
	}
	super.visitMethodInvocation(tree);
}
 
开发者ID:Cognifide,项目名称:AEM-Rules-for-SonarQube,代码行数:9,代码来源:MethodInvocationVisitor.java


示例19: visitParameterizedType

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
@Override
public void visitParameterizedType(ParameterizedTypeTree parameterizedTypeTree) {
	for (Iterator<Tree> iterator = parameterizedTypeTree.typeArguments().iterator(); iterator.hasNext() && !withResourceTypeVariable;) {
		TypeTreeVisitor treeVisitor = new TypeTreeVisitor();
		iterator.next().accept(treeVisitor);
		withResourceTypeVariable = treeVisitor.isResourceTypeInstance();
	}
	super.visitParameterizedType(parameterizedTypeTree);
}
 
开发者ID:Cognifide,项目名称:AEM-Rules-for-SonarQube,代码行数:10,代码来源:ParameterizedTypeTreeVisitor.java


示例20: checkModelProviderCall

import org.sonar.plugins.java.api.tree.Tree; //导入依赖的package包/类
private void checkModelProviderCall(Tree tree, StatementTree statement) {
	MethodInvocationTreeVisitor methodInvocationTreeVisitor = new MethodInvocationTreeVisitor();
	statement.accept(methodInvocationTreeVisitor);
	if (methodInvocationTreeVisitor.isModelProviderGetCalled()) {
		context.reportIssue(this, tree, RULE_MESSAGE);
	}
}
 
开发者ID:Cognifide,项目名称:AEM-Rules-for-SonarQube,代码行数:8,代码来源:IteratingResourcesCheck.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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