Tabnine Logo
org.eclipse.jdt.core.dom
Code IndexAdd Tabnine to your IDE (free)

How to use org.eclipse.jdt.core.dom

Best Java code snippets using org.eclipse.jdt.core.dom (Showing top 20 results out of 585)

origin: stackoverflow.com

CompilationUnit cu = ast.newCompilationUnit();
PackageDeclaration p1 = ast.newPackageDeclaration();
p1.setName(ast.newSimpleName("foo"));
cu.setPackage(p1);
ImportDeclaration id = ast.newImportDeclaration();
id.setName(ast.newName(new String[] { "java", "util", "Set" }));
cu.imports().add(id);
TypeDeclaration td = ast.newTypeDeclaration();
td.setName(ast.newSimpleName("Foo"));
TypeParameter tp = ast.newTypeParameter();
tp.setName(ast.newSimpleName("X"));
td.typeParameters().add(tp);
cu.types().add(td);
MethodDeclaration md = ast.newMethodDeclaration();
td.bodyDeclarations().add(md);
Block block = ast.newBlock();
md.setBody(block);
MethodInvocation mi = ast.newMethodInvocation();
mi.setName(ast.newSimpleName("x"));
ExpressionStatement e = ast.newExpressionStatement(mi);
block.statements().add(e);
origin: org.projectlombok/lombok

public static org.eclipse.jdt.core.dom.AbstractTypeDeclaration findTypeDeclaration(IType searchType, List<?> nodes) {
  for (Object object : nodes) {
    if (object instanceof org.eclipse.jdt.core.dom.AbstractTypeDeclaration) {
      org.eclipse.jdt.core.dom.AbstractTypeDeclaration typeDeclaration = (org.eclipse.jdt.core.dom.AbstractTypeDeclaration) object;
      if (typeDeclaration.getName().toString().equals(searchType.getElementName()))
        return typeDeclaration;
    }
  }
  return null;
}

origin: org.projectlombok/lombok

if (annotation.isSingleMemberAnnotation()) {
  org.eclipse.jdt.core.dom.SingleMemberAnnotation smAnn = (org.eclipse.jdt.core.dom.SingleMemberAnnotation) annotation;
  values.add(smAnn.getValue().toString());
} else if (annotation.isNormalAnnotation()) {
  org.eclipse.jdt.core.dom.NormalAnnotation normalAnn = (org.eclipse.jdt.core.dom.NormalAnnotation) annotation;
  for (Object value : normalAnn.values()) values.add(value.toString());
signature.append("@").append(annotation.resolveTypeBinding().getQualifiedName());
if (!values.isEmpty()) {
  signature.append("(");
origin: org.projectlombok/lombok

for (Object modifier : declaration.modifiers()) {
  if (modifier instanceof org.eclipse.jdt.core.dom.Annotation) {
    org.eclipse.jdt.core.dom.Annotation annotation = (org.eclipse.jdt.core.dom.Annotation)modifier;
    String qualifiedAnnotationName = annotation.resolveTypeBinding().getQualifiedName();
    if (!"java.lang.Override".equals(qualifiedAnnotationName) && !"java.lang.SuppressWarnings".equals(qualifiedAnnotationName)) annotations.add(annotation);
  .append(declaration.getReturnType2().toString())
  .append(" ").append(declaration.getName().getFullyQualifiedName())
  .append("(");
for (Object parameter : declaration.parameters()) {
  if (!first) signature.append(", ");
  first = false;
origin: stackoverflow.com

Document document = new Document(source);
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setSource(document.get().toCharArray());
CompilationUnit unit = (CompilationUnit)parser.createAST(null);
unit.recordModifications();
  System.out.println(i.getName().getFullyQualifiedName());
ImportDeclaration id = ast.newImportDeclaration();
String classToImport = "path.to.some.class";
id.setName(ast.newName(classToImport.split("\\.")));
  if (type.getNodeType() == ASTNode.TYPE_DECLARATION) {
    List<BodyDeclaration> bodies = type.bodyDeclarations();
    for (BodyDeclaration body : bodies) {
      if (body.getNodeType() == ASTNode.METHOD_DECLARATION) {
        MethodDeclaration method = (MethodDeclaration)body;
        System.out.println("name: " + method.getName().getFullyQualifiedName());
origin: opensourceBIM/BIMserver

private void extractJavaDoc(Class<?> clazz) {
  ASTParser parser = ASTParser.newParser(AST.JLS4);
  parser.setSource(sourceCodeFetcher.get(clazz).toCharArray());
  parser.setKind(ASTParser.K_COMPILATION_UNIT);
  final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
  cu.accept(new ASTVisitor() {
    MethodDeclaration currentMethod = null;
origin: opensourceBIM/BIMserver

public boolean visit(Javadoc javaDoc) {
  if (currentMethod != null) {
    SMethod method = getSMethod(currentMethod.getName().getIdentifier());
    if (method == null) {
      LOGGER.error("Method " + currentMethod.getName().getIdentifier() + " not found in class");
    } else {
      for (Object tag : javaDoc.tags()) {
        if (tag instanceof TagElement) {
          TagElement tagElement = (TagElement) tag;
          String tagName = tagElement.getTagName() == null ? null : tagElement.getTagName().trim();
          if ("@param".equals(tagName)) {
            SParameter parameter = null;
            for (int i = 0; i < tagElement.fragments().size(); i++) {
              Object fragment = tagElement.fragments().get(i);
              if (i == 0 && fragment instanceof SimpleName) {
                parameter = method.getParameter(((SimpleName) fragment).getIdentifier());
              } else if (i == 1 && parameter != null && fragment instanceof TextElement) {
                parameter.setDoc(((TextElement) fragment).getText());
  return super.visit(javaDoc);
origin: org.eclipse.jdt/org.eclipse.jdt.core

@Override
ASTNode clone0(AST target) {
  IfStatement result = new IfStatement(target);
  result.setSourceRange(getStartPosition(), getLength());
  result.copyLeadingComment(this);
  result.setExpression((Expression) getExpression().clone(target));
  result.setThenStatement(
    (Statement) getThenStatement().clone(target));
  result.setElseStatement(
    (Statement) ASTNode.copySubtree(target, getElseStatement()));
  return result;
}
origin: org.projectlombok/lombok

org.eclipse.jdt.core.dom.AbstractTypeDeclaration typeDeclaration = findTypeDeclaration(rootType, cuUnit.types());
while (!typeStack.isEmpty() && typeDeclaration != null) {
  typeDeclaration = findTypeDeclaration(typeStack.pop(), typeDeclaration.bodyDeclarations());
  for (Object declaration : typeDeclaration.bodyDeclarations()) {
    if (declaration instanceof org.eclipse.jdt.core.dom.MethodDeclaration) {
      org.eclipse.jdt.core.dom.MethodDeclaration methodDeclaration = (org.eclipse.jdt.core.dom.MethodDeclaration) declaration;
      if (methodDeclaration.getName().toString().equals(methodName)) {
        return methodDeclaration;
origin: org.eclipse.jdt/org.eclipse.jdt.core

@Override
ASTNode clone0(AST target) {
  EnhancedForStatement result = new EnhancedForStatement(target);
  result.setSourceRange(getStartPosition(), getLength());
  result.copyLeadingComment(this);
  result.setParameter((SingleVariableDeclaration) getParameter().clone(target));
  result.setExpression((Expression) getExpression().clone(target));
  result.setBody(
    (Statement) ASTNode.copySubtree(target, getBody()));
  return result;
}
origin: com.google.code.maven-play-plugin.org.eclipse.jdt/org.eclipse.jdt.core

  int treeSize() {
    return
      memSize()
      + (this.optionalDocComment == null ? 0 : getJavadoc().treeSize())
      + this.modifiers.listSize()
      + (this.memberName == null ? 0 : getName().treeSize())
      + (this.memberType == null ? 0 : getType().treeSize())
      + (this.optionalDefaultValue == null ? 0 : getDefault().treeSize());
  }
}
origin: eclipse/eclipse.jdt.ls

private boolean isEnhancedForStatementVariable(Statement statement, SimpleName name) {
  if (statement instanceof EnhancedForStatement) {
    EnhancedForStatement forStatement= (EnhancedForStatement) statement;
    SingleVariableDeclaration param= forStatement.getParameter();
    return param.getType() == name.getParent(); // strange recovery, see https://bugs.eclipse.org/180456
  }
  return false;
}
origin: eclipse/eclipse.jdt.ls

  private static int getReturnFlag(ReturnStatement node) {
    Expression expression = node.getExpression();
    if (expression == null || expression.resolveTypeBinding() == node.getAST().resolveWellKnownType("void")) {
      return VOID_RETURN;
    }
    return VALUE_RETURN;
  }
}
origin: org.eclipse.jdt/org.eclipse.jdt.core

RecoveredTypeBinding(BindingResolver resolver, VariableDeclaration variableDeclaration) {
  this.variableDeclaration = variableDeclaration;
  this.resolver = resolver;
  this.currentType = getType();
  this.dimensions = variableDeclaration.getExtraDimensions();
  if (this.currentType.isArrayType()) {
    this.dimensions += ((ArrayType) this.currentType).getDimensions();
  }
}
origin: org.eclipse.jdt/org.eclipse.jdt.core

  @Override
  int treeSize() {
    return
      memSize()
      + (this.qualifier == null ? 0 : getQualifier().treeSize())
      + (this.annotations == null ? 0 : this.annotations.listSize())
      + (this.name == null ? 0 : getName().treeSize());
  }
}
origin: opensourceBIM/BIMserver

private String extractFullText(TagElement tagElement) {
  StringBuilder builder = new StringBuilder();
  for (Object fragment : tagElement.fragments()) {
    if (fragment instanceof TextElement) {
      TextElement textElement = (TextElement) fragment;
      builder.append(textElement.getText() + " ");
    }
  }
  return builder.toString().trim();
}
origin: org.projectlombok/lombok

public static boolean isGenerated(org.eclipse.jdt.core.dom.ASTNode node) {
  boolean result = false;
  try {
    result = ((Boolean)node.getClass().getField("$isGenerated").get(node)).booleanValue();
    if (!result && node.getParent() != null && node.getParent() instanceof org.eclipse.jdt.core.dom.QualifiedName) {
      result = isGenerated(node.getParent());
    }
  } catch (Exception e) {
    // better to assume it isn't generated
  }
  return result;
}

origin: opensourceBIM/BIMserver

@Override
public boolean visit(MethodDeclaration node) {
  currentMethod = node;
  return super.visit(node);
}
origin: opensourceBIM/BIMserver

  @Override
  public void endVisit(MethodDeclaration node) {
    currentMethod = null;
    super.endVisit(node);
  }
});
origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.jdt.core

  int treeSize() {
    return
      memSize()
      + (this.optionalDocComment == null ? 0 : getJavadoc().treeSize())
      + this.modifiers.listSize()
      + (this.memberName == null ? 0 : getName().treeSize())
      + (this.memberType == null ? 0 : getType().treeSize())
      + (this.optionalDefaultValue == null ? 0 : getDefault().treeSize());
  }
}
org.eclipse.jdt.core.dom

Most used classes

  • CompilationUnit
    Java compilation unit AST node type. This is the type of the root of an AST. In JLS9 and later, this
  • MethodDeclaration
    Method declaration AST node type. A method declaration is the union of a method declaration and a co
  • ASTParser
    A Java language parser for creating abstract syntax trees (ASTs). Example: Create basic AST from sou
  • TypeDeclaration
    Type declaration AST node type. A type declaration is the union of a class declaration and an interf
  • ASTNode
  • Name,
  • Type,
  • FieldDeclaration,
  • SingleVariableDeclaration,
  • VariableDeclarationFragment,
  • PackageDeclaration,
  • ImportDeclaration,
  • AST,
  • Expression,
  • ParameterizedType,
  • ITypeBinding,
  • MethodInvocation,
  • ASTVisitor,
  • AbstractTypeDeclaration
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now