PLSQL Formatting issue - Indentation with IS and BEGIN release701
authorSubhashini Sooriarachchi <subslk@netbeans.org>
Tue, 14 Feb 2012 10:31:27 +0530
branchrelease701
changeset 1653a2a9a082157
parent 164 1adaff0cc2f4
child 166 0ba2732fc2c0
child 168 10da59e1b5ab
PLSQL Formatting issue - Indentation with IS and BEGIN
PLSQL/Formatter/src/org/netbeans/modules/plsql/format/PlsqlFormatter.java
     1.1 --- a/PLSQL/Formatter/src/org/netbeans/modules/plsql/format/PlsqlFormatter.java	Mon Feb 13 21:41:10 2012 +0100
     1.2 +++ b/PLSQL/Formatter/src/org/netbeans/modules/plsql/format/PlsqlFormatter.java	Tue Feb 14 10:31:27 2012 +0530
     1.3 @@ -638,7 +638,7 @@
     1.4                      tokenParent = tokenTemp;
     1.5                      break;
     1.6                  } else if (imageTmp.equalsIgnoreCase("IS")) {
     1.7 -                    //Check whether this is CURSOR
     1.8 +	 //Check whether this is CURSOR
     1.9                      TokenItem tmp = getIsParent(tokenTemp.getPrevious());
    1.10                      if ((tmp.getImage().trim().equalsIgnoreCase("CURSOR"))
    1.11                              || (tmp.getImage().trim().equalsIgnoreCase("TYPE"))) {
    1.12 @@ -652,8 +652,11 @@
    1.13                                      || (tmpCursorItem.getImage().trim().equalsIgnoreCase("TYPE"))) {
    1.14                                  tokenTemp = getPreviousToken(tokenTemp);
    1.15                              } else { // still it's not the 'CURSOR', and it's 'IS' or "PROCEDURE" or "FUNCTION", it's the parent
    1.16 -                                if (tmp.getImage().trim().equalsIgnoreCase("IS") || tmp.getImage().trim().equalsIgnoreCase("PROCEDURE") || tmp.getImage().trim().equalsIgnoreCase("FUNCTION")) {
    1.17 -                                    tokenParent = tokenTemp;
    1.18 +                                if (tmp.getImage().trim().equalsIgnoreCase("IS")) {
    1.19 +	                tokenParent = tokenTemp;
    1.20 +                                    break;
    1.21 +	            }else if(tmp.getImage().trim().equalsIgnoreCase("PROCEDURE") || tmp.getImage().trim().equalsIgnoreCase("FUNCTION")) {
    1.22 +                                    tokenParent = tmp;
    1.23                                      break;
    1.24                                  } else {
    1.25                                      tokenTemp = getPreviousToken(tokenTemp);
    1.26 @@ -661,7 +664,7 @@
    1.27                              }
    1.28                          } else { // if the token is 'IS' or "PROCEDURE" or "FUNCTION", it should be the parent line
    1.29                              if (tmp.getImage().trim().equalsIgnoreCase("IS") || tmp.getImage().trim().equalsIgnoreCase("PROCEDURE") || tmp.getImage().trim().equalsIgnoreCase("FUNCTION")) {
    1.30 -                                tokenParent = tokenTemp;
    1.31 +                                tokenParent = tmp;
    1.32                                  break;
    1.33                              } else {
    1.34                                  tokenTemp = getPreviousToken(tokenTemp);
    1.35 @@ -987,8 +990,16 @@
    1.36                      return getTabSize();
    1.37                  } else {
    1.38                      if (tokenImage.equalsIgnoreCase("IS")) {
    1.39 +	    /*for select statements in side cursors*/
    1.40 +	    if(token.getImage().equalsIgnoreCase("SELECT")){
    1.41 +	             return getTabSize();	    
    1.42 +	    }
    1.43                          TokenItem preKey = getPreviousKeyword(previousNWS.getPrevious());
    1.44                          if (preKey != null) {
    1.45 +	         TokenItem firstToken = findLineFirstNonWhitespace(getPosition(previousNWS, 0)).getToken();
    1.46 +	         if(token.getTokenID() != PlsqlTokenContext.KEYWORD && firstToken != previousNWS){
    1.47 +	             return 0;
    1.48 +	         }
    1.49                              String image = preKey.getImage().trim();
    1.50                              if ((!token.getImage().trim().equalsIgnoreCase("BEGIN"))
    1.51                                      && (!((image.equalsIgnoreCase("PACKAGE")) || (image.equalsIgnoreCase("BODY"))))) {
    1.52 @@ -1088,7 +1099,9 @@
    1.53  	}
    1.54  
    1.55  	if ((previousKeyword.equalsIgnoreCase("INTO"))
    1.56 -	        || (previousKeyword.equalsIgnoreCase("SET"))) {
    1.57 +	        || (previousKeyword.equalsIgnoreCase("SET"))
    1.58 +	        || (previousKeyword.equalsIgnoreCase("CURSOR"))
    1.59 +	        || (previousKeyword.equalsIgnoreCase("IS"))) {
    1.60  	    return getTabSize();
    1.61  	}
    1.62                  } else if (previousNWS.getImage().trim().equalsIgnoreCase("*")) {
    1.63 @@ -1440,7 +1453,7 @@
    1.64              int indent = getTabSize();
    1.65              TokenItem first = findLineFirstNonWhitespace(getPosition(previousNWS, 0)).getToken();
    1.66             
    1.67 -            int parent = getVisualColumnOffset(getPosition(first, 0));
    1.68 +            int parent = getLineIndent(getPosition(previousNWS, 0), true);
    1.69              TokenItem findStatementStart = findStatementStart(first);
    1.70  
    1.71              if (findStatementStart != null) {
    1.72 @@ -1449,12 +1462,9 @@
    1.73              
    1.74              do {
    1.75                  first = first.getNext();
    1.76 -                if ((first != null) && (first.getTokenID() != PlsqlTokenContext.WHITESPACE) && (first.getTokenID() != PlsqlTokenContext.BLOCK_COMMENT) && (first.getTokenID() != PlsqlTokenContext.LINE_COMMENT)) {
    1.77 -	if (parent != 0 && parent < getVisualColumnOffset(getPosition(first, 0))) {
    1.78 -	    return 0;
    1.79 -	} else {
    1.80 -	    return getVisualColumnOffset(getPosition(first, 0)) - parent;
    1.81 -	}
    1.82 +                if ((first != null) && (first.getTokenID() != PlsqlTokenContext.WHITESPACE) && (first.getTokenID() != PlsqlTokenContext.BLOCK_COMMENT)
    1.83 +	    && (first.getTokenID() != PlsqlTokenContext.LINE_COMMENT)) {
    1.84 +	return getVisualColumnOffset(getPosition(first, 0)) - parent;
    1.85                  }
    1.86              } while (first != null);
    1.87              return indent;