@CopyMethod static Block upToBlock(EmptyDeclaration self) { return null; } }
@CopyMethod static String getDescription(EmptyDeclaration self) { try { return ";"; } catch (Exception e) { return null; } }
@CopyMethod static boolean isStatementExpressionsBased(For self) { return self.rawVariableDeclaration() == null; } }
@CopyMethod static boolean needsParentheses(Expression self) { try { return BinaryExpressionTemplate.needsParentheses(self, 1); } catch (Throwable ignore) { return true; } } }
@CopyMethod static boolean needsParentheses(Expression self) { try { return BinaryExpressionTemplate.needsParentheses(self, 1); } catch (Throwable ignore) { return true; } } }
@CopyMethod static boolean hasLabel(Break self) { return self.astLabel() != null; } }
@CopyMethod static boolean hasLabel(Continue self) { return self.astLabel() != null; } }
@CopyMethod static String getDescription(AnnotationElement self) { try { return self.astName().astValue(); } catch (NullPointerException e) { return null; } }
@CopyMethod static String getDescription(ConstructorInvocation self) { try { return self.astTypeReference().getDescription(); } catch (NullPointerException e) { return null; } } }
@CopyMethod static String getDescription(MethodDeclaration self) { return self.astMethodName().astValue(); } }
/** * Returns the keyword-based modifiers the way {@link java.lang.reflect.Modifiers} works. * Only those keywords that are explicitly in the AST are reported; to also include implicit flags, such * as for example the idea that methods in interfaces are always public and abstract even if not marked as such, * use {@link #getEffectiveModifierFlags()}. */ @CopyMethod static int getExplicitModifierFlags(Modifiers m) { int out = 0; for (KeywordModifier n : m.astKeywords()) out |= n.asReflectModifiers(); return out; }
@CopyMethod static TypeDeclaration upUpIfFieldToTypeDeclaration(VariableDefinitionEntry self) { VariableDefinition def = self.upToVariableDefinition(); if (def == null) return null; VariableDeclaration decl = def.upToVariableDeclaration(); return decl == null ? null : decl.upUpToTypeDeclaration(); }
@CopyMethod static Block upUpIfLocalVariableToBlock(VariableDefinitionEntry self) { VariableDefinition def = self.upToVariableDefinition(); if (def == null) return null; VariableDeclaration decl = def.upToVariableDeclaration(); return decl == null ? null : decl.upToBlock(); } }
@CopyMethod static List<Node> getValues(Annotation self, String key) { for (AnnotationElement elem : self.astElements()) { if (key == null && elem.astName() == null) return elem.getValues(); if (key != null && elem.astName() != null && elem.astName().astValue().equals(key)) return elem.getValues(); } return ImmutableList.of(); } }
@CopyMethod static StrictListAccessor<VariableDefinitionEntry,VariableDeclaration> getVariableDefinitionEntries(VariableDeclaration self) { VariableDefinition def = self.astDefinition(); if (def != null) { return def.variables.wrap(self).asStrict(); } return ListAccessor.emptyStrict("variableDefinitionEntries", self); } }
@CopyMethod static boolean isPrimitive(TypeReference self) { if (self.astArrayDimensions() > 0 || self.rawParts().size() != 1) return false; try { String name = self.astParts().first().astIdentifier().astValue(); return name.indexOf(' ') == -1 && PRIMITIVE_NAMES.contains(" " + name + " "); } catch (NullPointerException e) { return false; } }
@CopyMethod(isStatic = true) static TypeReference fromName(String name) { TypeReference ref = new TypeReference(); for (String part : name.split("\\.")) { ref.astParts().addToEnd(new TypeReferencePart().astIdentifier(Identifier.of(part))); } return ref; }
@CopyMethod static boolean isVoid(TypeReference self) { if (self.rawParts().size() != 1) return false; try { String name = self.astParts().first().astIdentifier().astValue(); return name.equals("void"); } catch (NullPointerException e) { return false; } }
@CopyMethod static StrictListAccessor<TypeReference, TypeReference> getTypeArguments(TypeReference self) { try { return self.astParts().last().typeArguments.wrap(self).asStrict(); } catch (Exception e) { return ListAccessor.emptyStrict("typeArguments", self); } } }
@CopyMethod static TypeReference getEffectiveTypeReference(VariableDefinitionEntry self) { VariableDefinition parent = self.upToVariableDefinition(); if (parent == null) throw new AstException( self, "Cannot calculate type reference of a VariableDefinitionEntry without a VariableDefinition as parent"); TypeReference typeRef = parent.astTypeReference().copy(); return typeRef.astArrayDimensions(typeRef.astArrayDimensions() + self.astArrayDimensions() + (parent.astVarargs() ? 1 : 0)); }