/**
  * Collect Variable Declarations.
  *
  * @param ast variable token
  * @param frame current frame
  */
 private static void collectVariableDeclarations(DetailAST ast, LexicalFrame frame) {
   final String name = ast.findFirstToken(TokenTypes.IDENT).getText();
   if (frame instanceof ClassFrame) {
     final DetailAST mods = ast.findFirstToken(TokenTypes.MODIFIERS);
     if (ScopeUtils.isInInterfaceBlock(ast) || mods.branchContains(TokenTypes.LITERAL_STATIC)) {
       ((ClassFrame) frame).addStaticMember(name);
     } else {
       ((ClassFrame) frame).addInstanceMember(name);
     }
   } else {
     frame.addName(name);
   }
 }
예제 #2
0
 /**
  * Collects variable declarations.
  *
  * @param ast variable token.
  * @param frame current frame.
  */
 private static void collectVariableDeclarations(DetailAST ast, AbstractFrame frame) {
   final DetailAST ident = ast.findFirstToken(TokenTypes.IDENT);
   if (frame.getType() == FrameType.CLASS_FRAME) {
     final DetailAST mods = ast.findFirstToken(TokenTypes.MODIFIERS);
     if (ScopeUtils.isInInterfaceBlock(ast) || mods.branchContains(TokenTypes.LITERAL_STATIC)) {
       ((ClassFrame) frame).addStaticMember(ident);
     } else {
       ((ClassFrame) frame).addInstanceMember(ident);
     }
   } else {
     frame.addIdent(ident);
   }
 }
예제 #3
0
 /**
  * Checks whether an overlapping by local variable takes place.
  *
  * @param ast an identifier.
  * @return true if an overlapping by local variable takes place.
  */
 private boolean isOverlappingByLocalVariable(DetailAST ast) {
   boolean overlapping = false;
   final DetailAST parent = ast.getParent();
   final DetailAST sibling = ast.getNextSibling();
   if (sibling != null && isAssignToken(parent.getType())) {
     final ClassFrame classFrame = (ClassFrame) findFrame(ast, true);
     if (classFrame != null) {
       final Set<DetailAST> exprIdents = getAllTokensOfType(sibling, TokenTypes.IDENT);
       if (classFrame.hasInstanceMember(ast)) {
         overlapping = classFrame.containsFieldOrVariableDef(exprIdents, ast);
       }
     }
   }
   return overlapping;
 }
 /**
  * Parse the next AST for declarations.
  *
  * @param frameStack Stack containing the FrameTree being built
  * @param ast AST to parse
  */
 private static void collectDeclarations(Deque<LexicalFrame> frameStack, DetailAST ast) {
   final LexicalFrame frame = frameStack.peek();
   switch (ast.getType()) {
     case TokenTypes.VARIABLE_DEF:
       collectVariableDeclarations(ast, frame);
       break;
     case TokenTypes.PARAMETER_DEF:
       final DetailAST parameterAST = ast.findFirstToken(TokenTypes.IDENT);
       frame.addName(parameterAST.getText());
       break;
     case TokenTypes.CLASS_DEF:
     case TokenTypes.INTERFACE_DEF:
     case TokenTypes.ENUM_DEF:
     case TokenTypes.ANNOTATION_DEF:
       final DetailAST classAST = ast.findFirstToken(TokenTypes.IDENT);
       frame.addName(classAST.getText());
       frameStack.addFirst(new ClassFrame(frame));
       break;
     case TokenTypes.SLIST:
       frameStack.addFirst(new BlockFrame(frame));
       break;
     case TokenTypes.METHOD_DEF:
       final String name = ast.findFirstToken(TokenTypes.IDENT).getText();
       if (frame instanceof ClassFrame) {
         final DetailAST mods = ast.findFirstToken(TokenTypes.MODIFIERS);
         if (mods.branchContains(TokenTypes.LITERAL_STATIC)) {
           ((ClassFrame) frame).addStaticMethod(name);
         } else {
           ((ClassFrame) frame).addInstanceMethod(name);
         }
       }
       frameStack.addFirst(new MethodFrame(frame));
       break;
     case TokenTypes.CTOR_DEF:
       frameStack.addFirst(new MethodFrame(frame));
       break;
     default:
       // do nothing
   }
 }
예제 #5
0
 /**
  * Parses the next AST for declarations.
  *
  * @param frameStack stack containing the FrameTree being built.
  * @param ast AST to parse.
  */
 private static void collectDeclarations(Deque<AbstractFrame> frameStack, DetailAST ast) {
   final AbstractFrame frame = frameStack.peek();
   switch (ast.getType()) {
     case TokenTypes.VARIABLE_DEF:
       collectVariableDeclarations(ast, frame);
       break;
     case TokenTypes.PARAMETER_DEF:
       final DetailAST parameterIdent = ast.findFirstToken(TokenTypes.IDENT);
       frame.addIdent(parameterIdent);
       break;
     case TokenTypes.CLASS_DEF:
     case TokenTypes.INTERFACE_DEF:
     case TokenTypes.ENUM_DEF:
     case TokenTypes.ANNOTATION_DEF:
       final DetailAST classFrameNameIdent = ast.findFirstToken(TokenTypes.IDENT);
       frameStack.addFirst(new ClassFrame(frame, classFrameNameIdent));
       break;
     case TokenTypes.SLIST:
       frameStack.addFirst(new BlockFrame(frame, ast));
       break;
     case TokenTypes.METHOD_DEF:
       final DetailAST methodFrameNameIdent = ast.findFirstToken(TokenTypes.IDENT);
       if (frame.getType() == FrameType.CLASS_FRAME) {
         final DetailAST mods = ast.findFirstToken(TokenTypes.MODIFIERS);
         if (mods.branchContains(TokenTypes.LITERAL_STATIC)) {
           ((ClassFrame) frame).addStaticMethod(methodFrameNameIdent);
         } else {
           ((ClassFrame) frame).addInstanceMethod(methodFrameNameIdent);
         }
       }
       frameStack.addFirst(new MethodFrame(frame, methodFrameNameIdent));
       break;
     case TokenTypes.CTOR_DEF:
       final DetailAST ctorFrameNameIdent = ast.findFirstToken(TokenTypes.IDENT);
       frameStack.addFirst(new ConstructorFrame(frame, ctorFrameNameIdent));
       break;
     default:
       // do nothing
   }
 }