Corrected test for "unreachable statement" when casing of END keyword is in lowercase
authorstlase@netbeans.org
Fri, 26 Apr 2013 08:33:26 +0200
changeset 3861774dada7c53
parent 385 6df018124382
child 387 ffa00130cfc3
Corrected test for "unreachable statement" when casing of END keyword is in lowercase
PLSQL/Annotation/src/org/netbeans/modules/plsql/annotation/PlsqlMethodAnnotationUtil.java
     1.1 --- a/PLSQL/Annotation/src/org/netbeans/modules/plsql/annotation/PlsqlMethodAnnotationUtil.java	Thu Apr 25 17:12:47 2013 +0200
     1.2 +++ b/PLSQL/Annotation/src/org/netbeans/modules/plsql/annotation/PlsqlMethodAnnotationUtil.java	Fri Apr 26 08:33:26 2013 +0200
     1.3 @@ -61,15 +61,15 @@
     1.4  
     1.5  /**
     1.6   * Util class for annotations added for methods
     1.7 + *
     1.8   * @author YADHLK
     1.9   */
    1.10  public class PlsqlMethodAnnotationUtil {
    1.11 -static int hasReturn = 0;
    1.12 -private static final int HAS_RETURNS = 1;
    1.13 -private static final int NO_RETURNS = 2;
    1.14  
    1.15 +   static int hasReturn = 0;
    1.16 +   private static final int HAS_RETURNS = 1;
    1.17 +   private static final int NO_RETURNS = 2;
    1.18     private static Comparator<PlsqlBlock> comparator = new Comparator<PlsqlBlock>() {
    1.19 -
    1.20        @Override
    1.21        public int compare(PlsqlBlock o1, PlsqlBlock o2) {
    1.22           Integer o1pos, o2pos;
    1.23 @@ -153,84 +153,84 @@
    1.24        }
    1.25        return methodSpec.trim();
    1.26     }
    1.27 -        
    1.28 -    public static PlsqlBlock findMethod(final List<PlsqlBlock> specBlockHier, final String packageName, final String methodName) {
    1.29 -        PlsqlBlock match = null;
    1.30 -        if (!packageName.equals("")) {
    1.31 -            PlsqlBlock packageBlock = getPackageBody(specBlockHier, PlsqlBlockType.PACKAGE_BODY, packageName);
    1.32 -            if (packageBlock != null) {
    1.33 -                for (int i = 0; i < packageBlock.getChildCount(); i++) {
    1.34 -                    final PlsqlBlock temp = packageBlock.getChildBlocks().get(i);
    1.35 -                    if (temp.getName().equals(methodName)) {
    1.36 -                        match = temp;
    1.37 -                        break;
    1.38 -                    }
    1.39 -                }
    1.40 +
    1.41 +   public static PlsqlBlock findMethod(final List<PlsqlBlock> specBlockHier, final String packageName, final String methodName) {
    1.42 +      PlsqlBlock match = null;
    1.43 +      if (!packageName.equals("")) {
    1.44 +         PlsqlBlock packageBlock = getPackageBody(specBlockHier, PlsqlBlockType.PACKAGE_BODY, packageName);
    1.45 +         if (packageBlock != null) {
    1.46 +            for (int i = 0; i < packageBlock.getChildCount(); i++) {
    1.47 +               final PlsqlBlock temp = packageBlock.getChildBlocks().get(i);
    1.48 +               if (temp.getName().equals(methodName)) {
    1.49 +                  match = temp;
    1.50 +                  break;
    1.51 +               }
    1.52              }
    1.53 -        }
    1.54 -        return match;
    1.55 -    }
    1.56 -      
    1.57 -    public static PlsqlBlock getPackageBody(final List<PlsqlBlock> specBlockHier, final PlsqlBlockType blockType, final String packageName){
    1.58 -        PlsqlBlock packageBlock = null;
    1.59 -            for (int i = 0; i < specBlockHier.size(); i++) {
    1.60 -                final PlsqlBlock temp = specBlockHier.get(i);
    1.61 -                if (temp.getType() == blockType && temp.getName().equalsIgnoreCase(packageName)) {
    1.62 -                    packageBlock = temp;
    1.63 -                    break;
    1.64 -                }
    1.65 -            }
    1.66 -            return packageBlock;        
    1.67 +         }
    1.68 +      }
    1.69 +      return match;
    1.70     }
    1.71  
    1.72 -    public static int getOffsetToInsert(final Document doc, final List<PlsqlBlock> specBlockHier, final String packageName, final PlsqlBlock searchBlock, final int searchPlace) throws BadLocationException {
    1.73 -        int offset = -1;
    1.74 -        //Get package block
    1.75 -        if (!packageName.equals("")) {
    1.76 -            PlsqlBlock packageBlock = getPackageBody(specBlockHier, PlsqlBlockType.PACKAGE, packageName);
    1.77 +   public static PlsqlBlock getPackageBody(final List<PlsqlBlock> specBlockHier, final PlsqlBlockType blockType, final String packageName) {
    1.78 +      PlsqlBlock packageBlock = null;
    1.79 +      for (int i = 0; i < specBlockHier.size(); i++) {
    1.80 +         final PlsqlBlock temp = specBlockHier.get(i);
    1.81 +         if (temp.getType() == blockType && temp.getName().equalsIgnoreCase(packageName)) {
    1.82 +            packageBlock = temp;
    1.83 +            break;
    1.84 +         }
    1.85 +      }
    1.86 +      return packageBlock;
    1.87 +   }
    1.88  
    1.89 -            if (packageBlock != null) {
    1.90 -                for (int i = 0; i < packageBlock.getChildCount(); i++) {
    1.91 -                    final PlsqlBlock temp = packageBlock.getChildBlocks().get(i);
    1.92 -                    if (!temp.getType().equals(PlsqlBlockType.COMMENT) && (temp.getType().equals(PlsqlBlockType.FUNCTION_DEF) || temp.getType().equals(PlsqlBlockType.PROCEDURE_DEF))) {
    1.93 -                        if (temp.getName().contains(searchBlock.getName())) {
    1.94 -                            if (searchPlace == -1) {
    1.95 -                                offset = temp.getStartOffset();
    1.96 -                            } else {
    1.97 -                                offset = packageBlock.getChildBlocks().get(i + 1).getStartOffset() - 1;
    1.98 -                            }
    1.99 -                            break;
   1.100 +   public static int getOffsetToInsert(final Document doc, final List<PlsqlBlock> specBlockHier, final String packageName, final PlsqlBlock searchBlock, final int searchPlace) throws BadLocationException {
   1.101 +      int offset = -1;
   1.102 +      //Get package block
   1.103 +      if (!packageName.equals("")) {
   1.104 +         PlsqlBlock packageBlock = getPackageBody(specBlockHier, PlsqlBlockType.PACKAGE, packageName);
   1.105 +
   1.106 +         if (packageBlock != null) {
   1.107 +            for (int i = 0; i < packageBlock.getChildCount(); i++) {
   1.108 +               final PlsqlBlock temp = packageBlock.getChildBlocks().get(i);
   1.109 +               if (!temp.getType().equals(PlsqlBlockType.COMMENT) && (temp.getType().equals(PlsqlBlockType.FUNCTION_DEF) || temp.getType().equals(PlsqlBlockType.PROCEDURE_DEF))) {
   1.110 +                  if (temp.getName().contains(searchBlock.getName())) {
   1.111 +                     if (searchPlace == -1) {
   1.112 +                        offset = temp.getStartOffset();
   1.113 +                     } else {
   1.114 +                        offset = packageBlock.getChildBlocks().get(i + 1).getStartOffset() - 1;
   1.115 +                     }
   1.116 +                     break;
   1.117 +                  }
   1.118 +               } else if (temp.getType().equals(PlsqlBlockType.COMMENT) && searchBlock.getType().equals(PlsqlBlockType.COMMENT)) {
   1.119 +
   1.120 +                  //Get block content and check; comments can be merged to one comment block
   1.121 +                  final String text = doc.getText(temp.getStartOffset(), temp.getEndOffset() - temp.getStartOffset());
   1.122 +                  int index = text.indexOf(searchBlock.getName());
   1.123 +                  if (index != -1) {
   1.124 +                     index = text.indexOf("\n", index);
   1.125 +                     if (index != -1) {
   1.126 +                        index = text.indexOf("\n", index + 1);
   1.127 +                        if (index != -1) {
   1.128 +                           offset = temp.getStartOffset() + index;
   1.129 +                        } else {
   1.130 +                           offset = temp.getEndOffset();
   1.131                          }
   1.132 -                    } else if (temp.getType().equals(PlsqlBlockType.COMMENT)&& searchBlock.getType().equals(PlsqlBlockType.COMMENT)) {
   1.133  
   1.134 -                        //Get block content and check; comments can be merged to one comment block
   1.135 -                        final String text = doc.getText(temp.getStartOffset(), temp.getEndOffset() - temp.getStartOffset());
   1.136 -                        int index = text.indexOf(searchBlock.getName());
   1.137 -                        if (index != -1) {
   1.138 -                            index = text.indexOf("\n", index);
   1.139 -                            if (index != -1) {
   1.140 -                                index = text.indexOf("\n", index + 1);
   1.141 -                                if (index != -1) {
   1.142 -                                    offset = temp.getStartOffset() + index;
   1.143 -                                } else {
   1.144 -                                    offset = temp.getEndOffset();
   1.145 -                                }
   1.146 +                        break;
   1.147 +                     }
   1.148 +                  }
   1.149 +               }
   1.150 +            }
   1.151  
   1.152 -                                break;
   1.153 -                            }
   1.154 -                        }
   1.155 -                    }
   1.156 -                }
   1.157 +            //If the comment is not found insert some where
   1.158 +            if (offset == -1) {
   1.159 +               offset = packageBlock.getChildBlocks().get(0).getEndOffset();
   1.160 +            }
   1.161 +         }
   1.162 +      }
   1.163  
   1.164 -                //If the comment is not found insert some where
   1.165 -                if (offset == -1) {
   1.166 -                    offset = packageBlock.getChildBlocks().get(0).getEndOffset();
   1.167 -                }
   1.168 -            }
   1.169 -        }
   1.170 -
   1.171 -        return offset;
   1.172 -    }
   1.173 +      return offset;
   1.174 +   }
   1.175  
   1.176     public static boolean changeParam(final Document doc, final int offset, final String methodName) {
   1.177        if (PlsqlAnnotationUtil.isFileReadOnly(doc)) {
   1.178 @@ -256,21 +256,21 @@
   1.179        }
   1.180        return false;
   1.181     }
   1.182 -  
   1.183 -    public static int isReturnExist(final Document doc, final PlsqlBlock block) {
   1.184 -        hasReturn = 0;
   1.185 -        boolean isMissing = isReturn(doc, block);
   1.186  
   1.187 -        if (!isMissing) {
   1.188 -            if (hasReturn == HAS_RETURNS) {
   1.189 -                return HAS_RETURNS;
   1.190 -            } else {
   1.191 -                return NO_RETURNS;
   1.192 -            }
   1.193 -        } else {
   1.194 -            return 0;
   1.195 -        }
   1.196 -    }
   1.197 +   public static int isReturnExist(final Document doc, final PlsqlBlock block) {
   1.198 +      hasReturn = 0;
   1.199 +      boolean isMissing = isReturn(doc, block);
   1.200 +
   1.201 +      if (!isMissing) {
   1.202 +         if (hasReturn == HAS_RETURNS) {
   1.203 +            return HAS_RETURNS;
   1.204 +         } else {
   1.205 +            return NO_RETURNS;
   1.206 +         }
   1.207 +      } else {
   1.208 +         return 0;
   1.209 +      }
   1.210 +   }
   1.211  
   1.212     public static boolean isReturn(final Document doc, final PlsqlBlock block) {
   1.213        boolean isReturn = false;
   1.214 @@ -283,7 +283,7 @@
   1.215                 && child.getType() != PlsqlBlockType.CUSTOM_FOLD
   1.216                 && startOffset < child.getStartOffset()) {
   1.217              if (!isReturnMissing(startOffset, child.getStartOffset(), doc, true)) {
   1.218 -               isReturn = true;               
   1.219 +               isReturn = true;
   1.220                 break;
   1.221              }
   1.222           }
   1.223 @@ -444,12 +444,12 @@
   1.224        @SuppressWarnings("unchecked")
   1.225        final TokenSequence<PlsqlTokenId> ts = tokenHierarchy.tokenSequence(PlsqlTokenId.language());
   1.226        int endLineCount = 0;
   1.227 -      
   1.228 +
   1.229        if (ts != null) {
   1.230           ts.move(startOffset);
   1.231           Token<PlsqlTokenId> token = ts.token();
   1.232           boolean isException = false;
   1.233 -         boolean isRaised=false;
   1.234 +         boolean isRaised = false;
   1.235  
   1.236           while (ts.moveNext() && ts.offset() < endOffset) {
   1.237              token = ts.token();
   1.238 @@ -458,11 +458,11 @@
   1.239                 if (moveToReturnEnd(ts, endOffset)) {
   1.240                    isReturn = true;
   1.241                 }
   1.242 -            }else if (token.toString().equalsIgnoreCase("RAISE")) {
   1.243 +            } else if (token.toString().equalsIgnoreCase("RAISE")) {
   1.244                 if (moveToReturnEnd(ts, endOffset)) {
   1.245                    isRaised = true;
   1.246                 }
   1.247 -            }else if (token.toString().equalsIgnoreCase("ERROR_SYS")) {
   1.248 +            } else if (token.toString().equalsIgnoreCase("ERROR_SYS")) {
   1.249                 if (ts.moveNext()) {
   1.250                    token = ts.token();
   1.251                    if (token.id() == PlsqlTokenId.DOT) {
   1.252 @@ -479,6 +479,7 @@
   1.253                 }
   1.254              } else if (token.toString().equalsIgnoreCase("EXCEPTION")) {
   1.255                 isException = true;
   1.256 +               return isReturn;
   1.257              } else if (token.toString().equalsIgnoreCase("WHEN") && isException) {
   1.258                 if (PlsqlParserUtil.getNextNonWhitespace(ts, true)) { //Exception name
   1.259                    if (PlsqlParserUtil.getNextNonWhitespace(ts, true)) {
   1.260 @@ -492,7 +493,7 @@
   1.261                 }
   1.262              } else if ((isReturn || isRaised) && token.toString().contains("\n")) {
   1.263                 endLineCount++;
   1.264 -            } else if (endLineCount > 0 && token.toString().contains("END")
   1.265 +            } else if (endLineCount > 0 && token.toString().toUpperCase(Locale.ENGLISH).contains("END")
   1.266                    && (NbEditorUtilities.getLine(doc, ts.offset(), false).getLineNumber()
   1.267                    == NbEditorUtilities.getLine(doc, endOffset, false).getLineNumber() || isRaised)) {
   1.268                 //avoid END of blocks being unreachable statements