TplIndenter compatible against release70 & release701 branches release70
authorMartin Fousek <marfous@netbeans.org>
Wed, 03 Aug 2011 10:34:50 +0200
branchrelease70
changeset 17553653310285805
parent 17552 4f9e2be2a410
child 17563 38c4336fa8e0
TplIndenter compatible against release70 & release701 branches
php.smarty/manifest.mf
php.smarty/src/org/netbeans/modules/php/smarty/editor/indent/TplIndenter.java
     1.1 --- a/php.smarty/manifest.mf	Tue Aug 02 09:32:05 2011 -0400
     1.2 +++ b/php.smarty/manifest.mf	Wed Aug 03 10:34:50 2011 +0200
     1.3 @@ -1,4 +1,3 @@
     1.4  OpenIDE-Module: org.netbeans.modules.php.smarty
     1.5  OpenIDE-Module-Layer: org/netbeans/modules/php/smarty/resources/layer.xml
     1.6  OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/php/smarty/resources/Bundle.properties
     1.7 -OpenIDE-Module-Module-Dependencies: org.netbeans.modules.php.editor = 2
     2.1 --- a/php.smarty/src/org/netbeans/modules/php/smarty/editor/indent/TplIndenter.java	Tue Aug 02 09:32:05 2011 -0400
     2.2 +++ b/php.smarty/src/org/netbeans/modules/php/smarty/editor/indent/TplIndenter.java	Wed Aug 03 10:34:50 2011 +0200
     2.3 @@ -41,11 +41,16 @@
     2.4   */
     2.5  package org.netbeans.modules.php.smarty.editor.indent;
     2.6  
     2.7 +import java.lang.reflect.Array;
     2.8 +import java.lang.reflect.InvocationTargetException;
     2.9 +import java.lang.reflect.Method;
    2.10  import java.util.ArrayList;
    2.11  import java.util.Arrays;
    2.12  import java.util.HashMap;
    2.13  import java.util.List;
    2.14  import java.util.Stack;
    2.15 +import java.util.logging.Level;
    2.16 +import java.util.logging.Logger;
    2.17  import javax.swing.text.BadLocationException;
    2.18  import org.netbeans.api.lexer.Token;
    2.19  import org.netbeans.api.lexer.TokenHierarchy;
    2.20 @@ -66,6 +71,8 @@
    2.21   **/
    2.22  public class TplIndenter extends AbstractIndenter<TplTopTokenId> {
    2.23  
    2.24 +    private static final Logger LOGGER = Logger.getLogger(TplIndenter.class.getName());
    2.25 +    
    2.26      private Stack<TplStackItem> stack = null;
    2.27      private int preservedLineIndentation = -1;
    2.28      private static final List<String> bodyCommands = new ArrayList<String>(Arrays.asList("capture", "foreach", "foreachelse", "if", "elseif", "else", //NOI18N
    2.29 @@ -134,20 +141,42 @@
    2.30              TokenId id = token.id();
    2.31  
    2.32              if (id == TplTopTokenId.T_SMARTY && ts.offset() < startOffset && balance == 0) {
    2.33 -                int index = ts.index();
    2.34 -                ts.moveNext();
    2.35 -                Token tk = LexUtilities.findNext(ts, Arrays.asList(TplTopTokenId.T_SMARTY));
    2.36 -                ts.moveIndex(index);
    2.37 -                ts.moveNext();
    2.38 -                if (tk != null && tk.id() == TplTopTokenId.T_SMARTY_OPEN_DELIMITER) {
    2.39 -                    if (ts.movePrevious()) {
    2.40 -                        tk = LexUtilities.findPrevious(ts, Arrays.asList(TplTopTokenId.T_SMARTY));
    2.41 -                        if (tk != null) {
    2.42 -                            ts.moveNext();
    2.43 -                            tk = LexUtilities.findNext(ts, Arrays.asList(TplTopTokenId.T_SMARTY));
    2.44 +                // compatibility hack for release70 vs. release701 branches via reflection
    2.45 +                Method method = null; Token tk = null;
    2.46 +                try {
    2.47 +                    method = ts.getClass().getMethod("index");
    2.48 +                    if (method.getReturnType() == int.class) {
    2.49 +                        int index = ((Integer)method.invoke(ts)).intValue();
    2.50 +                        ts.moveNext();
    2.51 +                        tk = LexUtilities.findNext(ts, Arrays.asList(TplTopTokenId.T_SMARTY));
    2.52 +                        ts.getClass().getMethod("moveIndex", int.class).invoke(ts, index);
    2.53 +                    } else {
    2.54 +                        int[] indexes = (int[])method.invoke(ts);
    2.55 +                        ts.moveNext();
    2.56 +                        tk = LexUtilities.findNext(ts, Arrays.asList(TplTopTokenId.T_SMARTY));
    2.57 +                        ts.getClass().getMethod("moveIndex", Array.newInstance(int.class, 2).getClass()).invoke(ts, indexes);
    2.58 +                    }
    2.59 +                    ts.moveNext();
    2.60 +                    if (tk != null && tk.id() == TplTopTokenId.T_SMARTY_OPEN_DELIMITER) {
    2.61 +                        if (ts.movePrevious()) {
    2.62 +                            tk = LexUtilities.findPrevious(ts, Arrays.asList(TplTopTokenId.T_SMARTY));
    2.63 +                            if (tk != null) {
    2.64 +                                ts.moveNext();
    2.65 +                                tk = LexUtilities.findNext(ts, Arrays.asList(TplTopTokenId.T_SMARTY));
    2.66 +                            }
    2.67                          }
    2.68 +                        return ts.offset();
    2.69                      }
    2.70 -                    return ts.offset();
    2.71 +                } catch (NoSuchMethodException ex) {
    2.72 +                    LOGGER.log(Level.INFO, null, ex);
    2.73 +                } catch (SecurityException ex) {
    2.74 +                    LOGGER.log(Level.INFO, null, ex);
    2.75 +                } catch (IllegalAccessException ex) {
    2.76 +                    LOGGER.log(Level.INFO, null, ex);
    2.77 +                } catch (IllegalArgumentException ex) {
    2.78 +                    LOGGER.log(Level.INFO, null, ex);
    2.79 +                } catch (InvocationTargetException ex) {
    2.80 +                    LOGGER.log(Level.INFO, null, ex);
    2.81                  }
    2.82              } else if (id == TplTopTokenId.T_SMARTY_CLOSE_DELIMITER) {
    2.83                  balance++;