/** * Determine whether SLIST begins a block, determined by braces. * @param ast SLIST ast. */ private void leaveSlist(DetailAST ast) { if (LEFT_CURLY.equals(ast.getText())) { currentFrame = currentFrame.getParent(); } }
/** * Whether the field or the variable from the specified class is of String type. * @param objCalledOn the field or the variable from the specified class to check. * @param className the name of the class to check in. * @return true if the field or the variable from the specified class is of String type. */ private boolean isStringFieldOrVariableFromClass(DetailAST objCalledOn, final String className) { boolean result = false; final String name = objCalledOn.getText(); FieldFrame frame = getObjectFrame(currentFrame); while (frame != null) { if (className.equals(frame.getFrameName())) { final DetailAST field = frame.findField(name); if (field != null) { result = STRING.equals(getFieldType(field)); } break; } frame = getObjectFrame(frame.getParent()); } return result; }
/** * Whether the field or the variable is of String type. * @param objCalledOn the field or the variable to check. * @return true if the field or the variable is of String type. */ private boolean isStringFieldOrVariable(DetailAST objCalledOn) { boolean result = false; final String name = objCalledOn.getText(); FieldFrame frame = currentFrame; while (frame != null) { final DetailAST field = frame.findField(name); if (field != null && (frame.isClassOrEnumOrEnumConstDef() || checkLineNo(field, objCalledOn))) { result = STRING.equals(getFieldType(field)); break; } frame = frame.getParent(); } return result; }
/** * Whether the field or the variable from the specified class is of String type. * @param objCalledOn the field or the variable from the specified class to check. * @param className the name of the class to check in. * @return true if the field or the variable from the specified class is of String type. */ private boolean isStringFieldOrVariableFromClass(DetailAST objCalledOn, final String className) { boolean result = false; final String name = objCalledOn.getText(); FieldFrame frame = getObjectFrame(currentFrame); while (frame != null) { if (className.equals(frame.getFrameName())) { final DetailAST field = frame.findField(name); if (field != null) { result = STRING.equals(getFieldType(field)); } break; } frame = getObjectFrame(frame.getParent()); } return result; }
/** * Whether the field or the variable is of String type. * @param objCalledOn the field or the variable to check. * @return true if the field or the variable is of String type. */ private boolean isStringFieldOrVariable(DetailAST objCalledOn) { boolean result = false; final String name = objCalledOn.getText(); FieldFrame frame = currentFrame; while (frame != null) { final DetailAST field = frame.findField(name); if (field != null && (frame.isClassOrEnumOrEnumConstDef() || checkLineNo(field, objCalledOn))) { result = STRING.equals(getFieldType(field)); break; } frame = frame.getParent(); } return result; }
@Override public void leaveToken(DetailAST ast) { final int astType = ast.getType(); if (astType == TokenTypes.SLIST) { leaveSlist(ast); } else if (astType == TokenTypes.LITERAL_NEW) { leaveLiteralNew(ast); } else if (astType == TokenTypes.OBJBLOCK) { final int parentType = ast.getParent().getType(); if (parentType != TokenTypes.CLASS_DEF && parentType != TokenTypes.ENUM_DEF) { currentFrame = currentFrame.getParent(); } } else if (astType != TokenTypes.VARIABLE_DEF && astType != TokenTypes.PARAMETER_DEF && astType != TokenTypes.METHOD_CALL) { currentFrame = currentFrame.getParent(); } }
/** * Get the nearest parent frame which is CLASS_DEF, ENUM_DEF or ENUM_CONST_DEF. * @param frame to start the search from. * @return the nearest parent frame which is CLASS_DEF, ENUM_DEF or ENUM_CONST_DEF. */ private static FieldFrame getObjectFrame(FieldFrame frame) { FieldFrame objectFrame = frame; while (objectFrame != null && !objectFrame.isClassOrEnumOrEnumConstDef()) { objectFrame = objectFrame.getParent(); } return objectFrame; }
/** * Determine whether SLIST begins a block, determined by braces. * @param ast SLIST ast. */ private void leaveSlist(DetailAST ast) { if (LEFT_CURLY.equals(ast.getText())) { currentFrame = currentFrame.getParent(); } }
/** * Determine whether LITERAL_NEW is an anonymous class definition and leave * the frame it is in. * * @param ast LITERAL_NEW ast. */ private void leaveLiteralNew(DetailAST ast) { if (ast.findFirstToken(TokenTypes.OBJBLOCK) != null) { currentFrame = currentFrame.getParent(); } }
@Override public void leaveToken(DetailAST ast) { final int astType = ast.getType(); if (astType == TokenTypes.SLIST) { leaveSlist(ast); } else if (astType == TokenTypes.LITERAL_NEW) { leaveLiteralNew(ast); } else if (astType == TokenTypes.OBJBLOCK) { final int parentType = ast.getParent().getType(); if (parentType != TokenTypes.CLASS_DEF && parentType != TokenTypes.ENUM_DEF) { currentFrame = currentFrame.getParent(); } } else if (astType != TokenTypes.VARIABLE_DEF && astType != TokenTypes.PARAMETER_DEF && astType != TokenTypes.METHOD_CALL) { currentFrame = currentFrame.getParent(); } }
/** * Determine whether LITERAL_NEW is an anonymous class definition and leave * the frame it is in. * * @param ast LITERAL_NEW ast. */ private void leaveLiteralNew(DetailAST ast) { if (ast.findFirstToken(TokenTypes.OBJBLOCK) != null) { currentFrame = currentFrame.getParent(); } }
/** * Get the nearest parent frame which is CLASS_DEF, ENUM_DEF or ENUM_CONST_DEF. * @param frame to start the search from. * @return the nearest parent frame which is CLASS_DEF, ENUM_DEF or ENUM_CONST_DEF. */ private static FieldFrame getObjectFrame(FieldFrame frame) { FieldFrame objectFrame = frame; while (objectFrame != null && !objectFrame.isClassOrEnumOrEnumConstDef()) { objectFrame = objectFrame.getParent(); } return objectFrame; }