Tabnine Logo
org.eclipse.jdt.internal.compiler.ast
Code IndexAdd Tabnine to your IDE (free)

How to use org.eclipse.jdt.internal.compiler.ast

Best Java code snippets using org.eclipse.jdt.internal.compiler.ast (Showing top 20 results out of 315)

origin: eugenp/tutorials

private FieldDeclaration addInstanceVar(ConstructorDeclaration constructor, TypeReference typeReference, TypeDeclaration innerClass) {
  FieldDeclaration field = new FieldDeclaration();
  field.modifiers = AccPrivate | AccStatic | AccFinal;
  field.name = "INSTANCE".toCharArray();
  field.type = typeReference;
  AllocationExpression exp = new AllocationExpression();
  exp.type = typeReference;
  exp.binding = constructor.binding;
  exp.sourceStart = innerClass.sourceStart;
  exp.sourceEnd = innerClass.sourceEnd;
  field.initialization = exp;
  return field;
}
origin: eugenp/tutorials

private void addFactoryMethod(EclipseNode singletonClass, TypeDeclaration astNode, TypeReference typeReference, TypeDeclaration innerClass, FieldDeclaration field) {
  MethodDeclaration factoryMethod = new MethodDeclaration(astNode.compilationResult);
  factoryMethod.modifiers = AccStatic | ClassFileConstants.AccPublic;
  factoryMethod.returnType = typeReference;
  factoryMethod.sourceStart = astNode.sourceStart;
  factoryMethod.sourceEnd = astNode.sourceEnd;
  factoryMethod.selector = "getInstance".toCharArray();
  factoryMethod.bits = ECLIPSE_DO_NOT_TOUCH_FLAG;
  long pS = factoryMethod.sourceStart;
  long pE = factoryMethod.sourceEnd;
  long p = (long) pS << 32 | pE;
  FieldReference ref = new FieldReference(field.name, p);
  ref.receiver = new SingleNameReference(innerClass.name, p);
  ReturnStatement statement = new ReturnStatement(ref, astNode.sourceStart, astNode.sourceEnd);
  factoryMethod.statements = new Statement[]{statement};
  EclipseHandlerUtil.injectMethod(singletonClass, factoryMethod);
}
origin: eugenp/tutorials

  private ConstructorDeclaration addConstructor(EclipseNode singletonClass, TypeDeclaration astNode) {
    ConstructorDeclaration constructor = new ConstructorDeclaration(astNode.compilationResult);
    constructor.modifiers = AccPrivate;
    constructor.selector = astNode.name;
    constructor.sourceStart = astNode.sourceStart;
    constructor.sourceEnd = astNode.sourceEnd;
    constructor.thrownExceptions = null;
    constructor.typeParameters = null;
    constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = astNode.sourceStart;
    constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = astNode.sourceEnd;
    constructor.arguments = null;

    EclipseHandlerUtil.injectMethod(singletonClass, constructor);
    return constructor;
  }
}
origin: INRIA/spoon

  @Override
  public int compare(CompilationUnitDeclaration o1, CompilationUnitDeclaration o2) {
    String s1 = new String(o1.getFileName());
    String s2 = new String(o2.getFileName());
    return s1.compareTo(s2);
  }
}
origin: INRIA/spoon

/**
 * In no classpath, the model of the super interface isn't always correct.
 */
private boolean isCorrectTypeReference(TypeReference ref) {
  if (ref.resolvedType == null) {
    return false;
  }
  if (!(ref.resolvedType instanceof ProblemReferenceBinding)) {
    return true;
  }
  final String[] compoundName = CharOperation.charArrayToStringArray(((ProblemReferenceBinding) ref.resolvedType).compoundName);
  final String[] typeName = CharOperation.charArrayToStringArray(ref.getTypeName());
  if (compoundName.length == 0 || typeName.length == 0) {
    return false;
  }
  return compoundName[compoundName.length - 1].equals(typeName[typeName.length - 1]);
}
origin: INRIA/spoon

@Override
public boolean visit(ThisReference thisReference, BlockScope scope) {
  context.enter(factory.Code().createThisAccess(references.getTypeReference(thisReference.resolvedType), thisReference.isImplicitThis()), thisReference);
  return true;
}
origin: eugenp/tutorials

@Override
public void handle(AnnotationValues<Singleton> annotation, Annotation ast, EclipseNode annotationNode) {
  //remove annotation
  EclipseHandlerUtil.unboxAndRemoveAnnotationParameter(ast, "onType", "@Singleton(onType=", annotationNode);
  //add private constructor
  EclipseNode singletonClass = annotationNode.up();
  TypeDeclaration singletonClassType = (TypeDeclaration) singletonClass.get();
  ConstructorDeclaration constructor = addConstructor(singletonClass, singletonClassType);
  TypeReference singletonTypeRef = EclipseHandlerUtil.cloneSelfType(singletonClass, singletonClassType);
  //add inner class
  //add instance field
  StringBuilder sb = new StringBuilder();
  sb.append(singletonClass.getName());
  sb.append("Holder");
  String innerClassName = sb.toString();
  TypeDeclaration innerClass = new TypeDeclaration(singletonClassType.compilationResult);
  innerClass.modifiers = AccPrivate | AccStatic;
  innerClass.name = innerClassName.toCharArray();
  FieldDeclaration instanceVar = addInstanceVar(constructor, singletonTypeRef, innerClass);
  FieldDeclaration[] declarations = new FieldDeclaration[]{instanceVar};
  innerClass.fields = declarations;
  EclipseHandlerUtil.injectType(singletonClass, innerClass);
  addFactoryMethod(singletonClass, singletonClassType, singletonTypeRef, innerClass, instanceVar);
}
origin: org.projectlombok/lombok

String oName = new String(out[idx].type.getLastToken());
boolean found = false;
for (IAnnotation i : in) {
origin: INRIA/spoon

@Override
public boolean visit(CastExpression castExpression, BlockScope scope) {
  CastInfo ci = new CastInfo();
  //the 8 bits from 21 to 28 represents number of enclosing brackets
  ci.nrOfBrackets = ((castExpression.bits >>> 21) & 0xF);
  ci.typeRef = this.references.buildTypeReference(castExpression.type, scope, true);
  context.casts.add(ci);
  castExpression.expression.traverse(this, scope);
  return false;
}
origin: INRIA/spoon

@Override
public boolean visit(Initializer initializer, MethodScope scope) {
  CtAnonymousExecutable b = factory.Core().createAnonymousExecutable();
  if (initializer.isStatic()) {
    b.addModifier(ModifierKind.STATIC);
  }
  context.enter(b, initializer);
  return true;
}
origin: INRIA/spoon

/**
 * Searches a type declared in imports.
 *
 * @param typeName
 *         Expected type name.
 * @param imports
 *         Search the type in imports.
 * @return qualified name of the expected type.
 */
static String searchType(String typeName, ImportReference[] imports) {
  if (typeName == null || imports == null) {
    return null;
  }
  for (ImportReference anImport : imports) {
    final String importType = CharOperation.charToString(anImport.getImportName()[anImport.getImportName().length - 1]);
    if (typeName.equals(importType)) {
      return CharOperation.toString(anImport.getImportName());
    }
  }
  return null;
}
origin: INRIA/spoon

@Override
public boolean visit(StringLiteral stringLiteral, BlockScope scope) {
  context.enter(factory.Code().createLiteral(CharOperation.charToString(stringLiteral.source())), stringLiteral);
  return true;
}
origin: INRIA/spoon

private <T> void insertGenericTypesInNoClasspathFromJDTInSpoon(TypeReference original, CtTypeReference<T> type) {
  if (original.resolvedType instanceof ProblemReferenceBinding && original.getTypeArguments() != null) {
    for (TypeReference[] typeReferences : original.getTypeArguments()) {
      if (typeReferences != null) {
        for (TypeReference typeReference : typeReferences) {
          type.addActualTypeArgument(this.getTypeReference(typeReference.resolvedType));
        }
      }
    }
  }
}
origin: INRIA/spoon

@Override
public boolean visit(QualifiedThisReference qualifiedThisRef, BlockScope scope) {
  context.enter(factory.Code().createThisAccess(references.getTypeReference(qualifiedThisRef.qualification.resolvedType), qualifiedThisRef.isImplicitThis()), qualifiedThisRef);
  return true;
}
origin: INRIA/spoon

@Override
public boolean visit(IntLiteral intLiteral, BlockScope scope) {
  intLiteral.computeConstant();
  CtLiteral<Integer> l = factory.Code().createLiteral(intLiteral.constant.intValue());
  context.enter(l, intLiteral);
  return true;
}
origin: INRIA/spoon

@Override
public boolean visit(DoubleLiteral doubleLiteral, BlockScope scope) {
  doubleLiteral.computeConstant();
  context.enter(factory.Code().createLiteral(doubleLiteral.constant.doubleValue()), doubleLiteral);
  return true;
}
origin: INRIA/spoon

@Override
public boolean visit(FloatLiteral floatLiteral, BlockScope scope) {
  floatLiteral.computeConstant();
  context.enter(factory.Code().createLiteral(floatLiteral.constant.floatValue()), floatLiteral);
  return true;
}
origin: INRIA/spoon

@Override
public boolean visit(CharLiteral charLiteral, BlockScope scope) {
  charLiteral.computeConstant();
  context.enter(factory.Code().createLiteral(charLiteral.constant.charValue()), charLiteral);
  return true;
}
origin: INRIA/spoon

@Override
public boolean visit(LongLiteral longLiteral, BlockScope scope) {
  longLiteral.computeConstant();
  context.enter(factory.Code().createLiteral(longLiteral.constant.longValue()), longLiteral);
  return true;
}
origin: INRIA/spoon

private int getSourceEndOfTypeReference(char[] contents, TypeReference node, int sourceEnd) {
  TypeReference[][] typeArgs = node.getTypeArguments();
  if (typeArgs != null && typeArgs.length > 0) {
    TypeReference[] trs = typeArgs[typeArgs.length - 1];
org.eclipse.jdt.internal.compiler.ast

Most used classes

  • CompilationUnitDeclaration
  • TypeDeclaration
  • TypeReference
  • Argument
  • StringLiteral
  • ImportReference,
  • ConstructorDeclaration,
  • ExplicitConstructorCall,
  • MethodDeclaration,
  • AbstractMethodDeclaration,
  • AllocationExpression,
  • FieldDeclaration,
  • FieldReference,
  • Javadoc,
  • MessageSend,
  • SingleMemberAnnotation,
  • SingleNameReference,
  • Expression,
  • ExtendedStringLiteral
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