EADS-2669 : Create test block throws null pointer exception release701
authorShanil Amarasinghe <shanil@netbeans.org>
Thu, 24 May 2012 16:41:01 +0530
branchrelease701
changeset 230b13b428b953d
parent 229 c0a56e4dd133
child 231 444acb912904
EADS-2669 : Create test block throws null pointer exception
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/Bundle.properties
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/CreateTestBlockAction.java
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/SelectMethodDialog.form
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/SelectMethodDialog.java
PLSQL/Utilities/src/org/netbeans/modules/plsql/utilities/PlsqlParserUtil.java
     1.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/Bundle.properties	Thu May 24 10:13:43 2012 +0530
     1.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/Bundle.properties	Thu May 24 16:41:01 2012 +0530
     1.3 @@ -23,3 +23,5 @@
     1.4  PromptDialog.okButton.text=OK
     1.5  PromptDialog.lblPrompt.text=
     1.6  PromptDialog.fieldSubstitutionValue.text=
     1.7 +SelectMethodDialog.jLabel1.text=Available Methods
     1.8 +SelectMethodDialog.btnOk.text=OK
     2.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/CreateTestBlockAction.java	Thu May 24 10:13:43 2012 +0530
     2.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/CreateTestBlockAction.java	Thu May 24 16:41:01 2012 +0530
     2.3 @@ -155,7 +155,15 @@
     2.4                          PlsqlBlock temp = selectedBlock;
     2.5                          selectedBlock = null;
     2.6                          DataObject dataObj = null;
     2.7 -                        PlsqlBlock block = PlsqlParserUtil.findMatchingBlock(PlsqlParserUtil.getBlockHierarchy(dataObject), doc, doc, selectedName, parentName, temp.getStartOffset(), false, false, true);
     2.8 +                        PlsqlBlock block = null;
     2.9 +                        List<PlsqlBlock> blocks = PlsqlParserUtil.findMatchingBlocks(PlsqlParserUtil.getBlockHierarchy(dataObject), doc, doc, selectedName, parentName, temp.getStartOffset(), false, false, true);
    2.10 +                        if (blocks != null) {
    2.11 +                            if (blocks.size() == 1) {
    2.12 +                               block = blocks.get(0); 
    2.13 +                            } else {
    2.14 +                               block = getMethodFromUser(doc, blocks);
    2.15 +                            }
    2.16 +                        }
    2.17                          if (block == null) {
    2.18                              Document specDoc = getSpecDocument(doc);
    2.19                              if (specDoc == null) {
    2.20 @@ -183,7 +191,7 @@
    2.21                      if (selectedBlock.getParent() != null) {
    2.22                          selectedName = selectedBlock.getParent().getName() + "." + selectedBlock.getName();
    2.23                      }
    2.24 -                    tempTemplate = tempTemplate + createMethodTemplate(doc);
    2.25 +                        tempTemplate = tempTemplate + createMethodTemplate(doc);
    2.26                  } catch (NotConnectedToDbException e) {
    2.27                      Exceptions.printStackTrace(e);
    2.28                  }
    2.29 @@ -663,11 +671,25 @@
    2.30  
    2.31      private void selectMatchingBlock(DataObject dataObj, Document specDoc, int offset) {
    2.32          List<PlsqlBlock> newBlockHier = PlsqlParserUtil.getBlockHierarchy(dataObj);
    2.33 -        PlsqlBlock block = PlsqlParserUtil.findMatchingBlock(newBlockHier, doc, specDoc, selectedName, parentName, offset, false, false, true);
    2.34 +        PlsqlBlock block = null;
    2.35 +        List<PlsqlBlock> blocks = PlsqlParserUtil.findMatchingBlocks(newBlockHier, doc, specDoc, selectedName, parentName, offset, false, false, true);
    2.36 +        if (blocks != null) {
    2.37 +            if (blocks.size() == 1) {
    2.38 +                block = blocks.get(0);
    2.39 +            } else {
    2.40 +                block = getMethodFromUser(specDoc, blocks);
    2.41 +            }
    2.42 +        }
    2.43          if (block != null && block.getParent() != null) {
    2.44              selectedBlock = block;
    2.45              doc = specDoc;
    2.46              dataObject = dataObj;
    2.47          }
    2.48      }
    2.49 +    
    2.50 +    private PlsqlBlock getMethodFromUser(Document doc, List<PlsqlBlock> blocks) {
    2.51 +        SelectMethodDialog dialog = new SelectMethodDialog(null, true, doc, blocks);
    2.52 +        dialog.setVisible(true);
    2.53 +        return dialog.getSelectedPlsqlBlock();
    2.54 +    }
    2.55  }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/SelectMethodDialog.form	Thu May 24 16:41:01 2012 +0530
     3.3 @@ -0,0 +1,93 @@
     3.4 +<?xml version="1.1" encoding="UTF-8" ?>
     3.5 +
     3.6 +<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
     3.7 +  <Properties>
     3.8 +    <Property name="defaultCloseOperation" type="int" value="2"/>
     3.9 +  </Properties>
    3.10 +  <SyntheticProperties>
    3.11 +    <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
    3.12 +  </SyntheticProperties>
    3.13 +  <AuxValues>
    3.14 +    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
    3.15 +    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
    3.16 +    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
    3.17 +    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
    3.18 +    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
    3.19 +    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
    3.20 +    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
    3.21 +    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
    3.22 +    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
    3.23 +  </AuxValues>
    3.24 +
    3.25 +  <Layout>
    3.26 +    <DimensionLayout dim="0">
    3.27 +      <Group type="103" groupAlignment="0" attributes="0">
    3.28 +          <Group type="102" attributes="0">
    3.29 +              <EmptySpace max="-2" attributes="0"/>
    3.30 +              <Group type="103" groupAlignment="0" attributes="0">
    3.31 +                  <Component id="jScrollPane1" alignment="0" pref="790" max="32767" attributes="0"/>
    3.32 +                  <Component id="jLabel1" alignment="0" min="-2" max="-2" attributes="0"/>
    3.33 +                  <Component id="btnOk" alignment="1" min="-2" max="-2" attributes="0"/>
    3.34 +              </Group>
    3.35 +              <EmptySpace max="-2" attributes="0"/>
    3.36 +          </Group>
    3.37 +      </Group>
    3.38 +    </DimensionLayout>
    3.39 +    <DimensionLayout dim="1">
    3.40 +      <Group type="103" groupAlignment="0" attributes="0">
    3.41 +          <Group type="102" alignment="0" attributes="0">
    3.42 +              <EmptySpace max="-2" attributes="0"/>
    3.43 +              <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
    3.44 +              <EmptySpace max="-2" attributes="0"/>
    3.45 +              <Component id="jScrollPane1" min="-2" pref="242" max="-2" attributes="0"/>
    3.46 +              <EmptySpace type="unrelated" max="-2" attributes="0"/>
    3.47 +              <Component id="btnOk" min="-2" max="-2" attributes="0"/>
    3.48 +              <EmptySpace max="32767" attributes="0"/>
    3.49 +          </Group>
    3.50 +      </Group>
    3.51 +    </DimensionLayout>
    3.52 +  </Layout>
    3.53 +  <SubComponents>
    3.54 +    <Component class="javax.swing.JLabel" name="jLabel1">
    3.55 +      <Properties>
    3.56 +        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
    3.57 +          <ResourceString bundle="org/netbeans/modules/plsql/execution/Bundle.properties" key="SelectMethodDialog.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
    3.58 +        </Property>
    3.59 +      </Properties>
    3.60 +    </Component>
    3.61 +    <Container class="javax.swing.JScrollPane" name="jScrollPane1">
    3.62 +      <AuxValues>
    3.63 +        <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
    3.64 +      </AuxValues>
    3.65 +
    3.66 +      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
    3.67 +      <SubComponents>
    3.68 +        <Component class="javax.swing.JList" name="lstMethods">
    3.69 +          <Properties>
    3.70 +            <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
    3.71 +              <StringArray count="5">
    3.72 +                <StringItem index="0" value="Item 1"/>
    3.73 +                <StringItem index="1" value="Item 2"/>
    3.74 +                <StringItem index="2" value="Item 3"/>
    3.75 +                <StringItem index="3" value="Item 4"/>
    3.76 +                <StringItem index="4" value="Item 5"/>
    3.77 +              </StringArray>
    3.78 +            </Property>
    3.79 +            <Property name="selectionMode" type="int" value="0"/>
    3.80 +          </Properties>
    3.81 +        </Component>
    3.82 +      </SubComponents>
    3.83 +    </Container>
    3.84 +    <Component class="javax.swing.JButton" name="btnOk">
    3.85 +      <Properties>
    3.86 +        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
    3.87 +          <ResourceString bundle="org/netbeans/modules/plsql/execution/Bundle.properties" key="SelectMethodDialog.btnOk.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
    3.88 +        </Property>
    3.89 +        <Property name="enabled" type="boolean" value="false"/>
    3.90 +      </Properties>
    3.91 +      <Events>
    3.92 +        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnOkActionPerformed"/>
    3.93 +      </Events>
    3.94 +    </Component>
    3.95 +  </SubComponents>
    3.96 +</Form>
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/SelectMethodDialog.java	Thu May 24 16:41:01 2012 +0530
     4.3 @@ -0,0 +1,158 @@
     4.4 +/*
     4.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     4.6 + *
     4.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
     4.8 + *
     4.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    4.10 + * Other names may be trademarks of their respective owners.
    4.11 + *
    4.12 + * The contents of this file are subject to the terms of either the GNU
    4.13 + * General Public License Version 2 only ("GPL") or the Common
    4.14 + * Development and Distribution License("CDDL") (collectively, the
    4.15 + * "License"). You may not use this file except in compliance with the
    4.16 + * License. You can obtain a copy of the License at
    4.17 + * http://www.netbeans.org/cddl-gplv2.html
    4.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    4.19 + * specific language governing permissions and limitations under the
    4.20 + * License.  When distributing the software, include this License Header
    4.21 + * Notice in each file and include the License file at
    4.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    4.23 + * particular file as subject to the "Classpath" exception as provided
    4.24 + * by Oracle in the GPL Version 2 section of the License file that
    4.25 + * accompanied this code. If applicable, add the following below the
    4.26 + * License Header, with the fields enclosed by brackets [] replaced by
    4.27 + * your own identifying information:
    4.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    4.29 + *
    4.30 + * If you wish your version of this file to be governed by only the CDDL
    4.31 + * or only the GPL Version 2, indicate your decision by adding
    4.32 + * "[Contributor] elects to include this software in this distribution
    4.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    4.34 + * single choice of license, a recipient has the option to distribute
    4.35 + * your version of this file under either the CDDL, the GPL Version 2 or
    4.36 + * to extend the choice of license to its licensees as provided above.
    4.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    4.38 + * Version 2 license, then the option applies only if the new code is
    4.39 + * made subject to such option by the copyright holder.
    4.40 + *
    4.41 + * Contributor(s):
    4.42 + *
    4.43 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
    4.44 + */
    4.45 +package org.netbeans.modules.plsql.execution;
    4.46 +
    4.47 +import java.util.ArrayList;
    4.48 +import java.util.List;
    4.49 +import javax.swing.event.ListSelectionEvent;
    4.50 +import javax.swing.event.ListSelectionListener;
    4.51 +import javax.swing.text.Document;
    4.52 +import org.netbeans.modules.plsql.lexer.PlsqlBlock;
    4.53 +import org.netbeans.modules.plsql.utilities.PlsqlParserUtil;
    4.54 +
    4.55 +/**
    4.56 + *
    4.57 + * @author shaalk
    4.58 + */
    4.59 +public class SelectMethodDialog extends javax.swing.JDialog {
    4.60 +
    4.61 +    private List<PlsqlBlock> blocks = null;
    4.62 +    
    4.63 +    /** Creates new form SelectMethodDialog */
    4.64 +    public SelectMethodDialog(java.awt.Frame parent, boolean modal, Document doc, List<PlsqlBlock> blocks) {
    4.65 +        super(parent, modal);
    4.66 +        initComponents();
    4.67 +        this.blocks = blocks;
    4.68 +        lstMethods.removeAll();
    4.69 +        ArrayList<String> items = new ArrayList<String>();
    4.70 +        for (PlsqlBlock block : blocks) {
    4.71 +            items.add(PlsqlParserUtil.fetchMethodHeader(doc, block.getStartOffset()));
    4.72 +        }
    4.73 +        lstMethods.setListData(items.toArray());
    4.74 +        lstMethods.addListSelectionListener(new ListSelectionListener() {
    4.75 +
    4.76 +            @Override
    4.77 +            public void valueChanged(ListSelectionEvent e) {
    4.78 +                if (!lstMethods.isSelectionEmpty()) {
    4.79 +                    btnOk.setEnabled(true);
    4.80 +                }
    4.81 +            }
    4.82 +        });
    4.83 +    }
    4.84 +    
    4.85 +    public PlsqlBlock getSelectedPlsqlBlock() {
    4.86 +        return blocks.get(lstMethods.getSelectedIndex());
    4.87 +    }
    4.88 +
    4.89 +    /** This method is called from within the constructor to
    4.90 +     * initialize the form.
    4.91 +     * WARNING: Do NOT modify this code. The content of this method is
    4.92 +     * always regenerated by the Form Editor.
    4.93 +     */
    4.94 +    @SuppressWarnings("unchecked")
    4.95 +   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    4.96 +   private void initComponents() {
    4.97 +
    4.98 +      jLabel1 = new javax.swing.JLabel();
    4.99 +      jScrollPane1 = new javax.swing.JScrollPane();
   4.100 +      lstMethods = new javax.swing.JList();
   4.101 +      btnOk = new javax.swing.JButton();
   4.102 +
   4.103 +      setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
   4.104 +
   4.105 +      jLabel1.setText(org.openide.util.NbBundle.getMessage(SelectMethodDialog.class, "SelectMethodDialog.jLabel1.text")); // NOI18N
   4.106 +
   4.107 +      lstMethods.setModel(new javax.swing.AbstractListModel() {
   4.108 +         String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
   4.109 +         public int getSize() { return strings.length; }
   4.110 +         public Object getElementAt(int i) { return strings[i]; }
   4.111 +      });
   4.112 +      lstMethods.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
   4.113 +      jScrollPane1.setViewportView(lstMethods);
   4.114 +
   4.115 +      btnOk.setText(org.openide.util.NbBundle.getMessage(SelectMethodDialog.class, "SelectMethodDialog.btnOk.text")); // NOI18N
   4.116 +      btnOk.setEnabled(false);
   4.117 +      btnOk.addActionListener(new java.awt.event.ActionListener() {
   4.118 +         public void actionPerformed(java.awt.event.ActionEvent evt) {
   4.119 +            btnOkActionPerformed(evt);
   4.120 +         }
   4.121 +      });
   4.122 +
   4.123 +      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
   4.124 +      getContentPane().setLayout(layout);
   4.125 +      layout.setHorizontalGroup(
   4.126 +         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   4.127 +         .addGroup(layout.createSequentialGroup()
   4.128 +            .addContainerGap()
   4.129 +            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   4.130 +               .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 790, Short.MAX_VALUE)
   4.131 +               .addComponent(jLabel1)
   4.132 +               .addComponent(btnOk, javax.swing.GroupLayout.Alignment.TRAILING))
   4.133 +            .addContainerGap())
   4.134 +      );
   4.135 +      layout.setVerticalGroup(
   4.136 +         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   4.137 +         .addGroup(layout.createSequentialGroup()
   4.138 +            .addContainerGap()
   4.139 +            .addComponent(jLabel1)
   4.140 +            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
   4.141 +            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)
   4.142 +            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
   4.143 +            .addComponent(btnOk)
   4.144 +            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
   4.145 +      );
   4.146 +
   4.147 +      pack();
   4.148 +   }// </editor-fold>//GEN-END:initComponents
   4.149 +
   4.150 +private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
   4.151 +    this.setVisible(false);
   4.152 +}//GEN-LAST:event_btnOkActionPerformed
   4.153 +
   4.154 +
   4.155 +   // Variables declaration - do not modify//GEN-BEGIN:variables
   4.156 +   private javax.swing.JButton btnOk;
   4.157 +   private javax.swing.JLabel jLabel1;
   4.158 +   private javax.swing.JScrollPane jScrollPane1;
   4.159 +   private javax.swing.JList lstMethods;
   4.160 +   // End of variables declaration//GEN-END:variables
   4.161 +}
     5.1 --- a/PLSQL/Utilities/src/org/netbeans/modules/plsql/utilities/PlsqlParserUtil.java	Thu May 24 10:13:43 2012 +0530
     5.2 +++ b/PLSQL/Utilities/src/org/netbeans/modules/plsql/utilities/PlsqlParserUtil.java	Thu May 24 16:41:01 2012 +0530
     5.3 @@ -88,7 +88,7 @@
     5.4          } else {
     5.5              usageParams = fetchMethodDefParamTypes(source, startOffset);
     5.6          }
     5.7 -
     5.8 +  
     5.9          if (packageName == null || packageName.equals("")) {
    5.10              packageName = getPackageName(getBlockFactory(source), startOffset);
    5.11          }
    5.12 @@ -110,6 +110,87 @@
    5.13  
    5.14          return (match == null && findBestMatch && matchList.size() > 0) ? null : match;
    5.15      }
    5.16 +    
    5.17 +    /**
    5.18 +     * Method that will find & return list of matching FUNCTION/ PROCEDURE of the body file
    5.19 +     * @param blockHier
    5.20 +     * @param source
    5.21 +     * @param dest
    5.22 +     * @param name
    5.23 +     * @param startOffset
    5.24 +     * @param isUsage       whether this is method usage
    5.25 +     * @param isImpl
    5.26 +     * @param findBestMatch   whether best match is OK
    5.27 +     * @return
    5.28 +     */    
    5.29 +    public static List<PlsqlBlock> findMatchingBlocks(final List<PlsqlBlock> blockHier, final Document source,
    5.30 +            final Document dest, final String name, String packageName, final int startOffset, final boolean isUsage, final boolean isImpl, final boolean findBestMatch) {
    5.31 +        PlsqlBlock match = null;
    5.32 +        final List<PlsqlBlock> matchList = new ArrayList<PlsqlBlock>();
    5.33 +        if (isImpl) {
    5.34 +            findMatchingImplBlocks(blockHier, name, matchList);
    5.35 +        } else {
    5.36 +            findMatchingDefBlocks(blockHier, name, matchList);
    5.37 +        }
    5.38 +
    5.39 +        //There are several methods with the same name. Have to check the signature
    5.40 +        List<String> usageParams;
    5.41 +        if (isUsage) {
    5.42 +            usageParams = fetchMethodParamTypes(source, startOffset);
    5.43 +        } else {
    5.44 +            usageParams = fetchMethodDefParamTypes(source, startOffset);
    5.45 +        }
    5.46 +
    5.47 +        if (packageName == null || packageName.equals("")) {
    5.48 +            packageName = getPackageName(getBlockFactory(source), startOffset);
    5.49 +        }
    5.50 +
    5.51 +        //Take PlsqlBlock one by one and compare the parameters
    5.52 +        for (int x = 0; x < matchList.size(); x++) {
    5.53 +            PlsqlBlock block = matchList.get(x);
    5.54 +            if (!(block.getParent() != null ? block.getParent().getName().equalsIgnoreCase(packageName) : true)) {
    5.55 +                continue; //If the parent block name is not the same this is not a match
    5.56 +            }
    5.57 +
    5.58 +            List<String> params = fetchMethodDefParamTypes(dest, block.getStartOffset());
    5.59 +            int defaultNo = fetchDefaultParams(dest, block.getStartOffset());
    5.60 +            if (compareParameters(usageParams, params, defaultNo)) {
    5.61 +                match = block;
    5.62 +                break;
    5.63 +            }
    5.64 +        }
    5.65 +        if (match == null && findBestMatch) {
    5.66 +           List<PlsqlBlock> similarParaCountList = new ArrayList<PlsqlBlock>();
    5.67 +           int usageCount = fetchMethodParamsCount(source, startOffset);
    5.68 +           for (int x = 0; x < matchList.size(); x++) {
    5.69 +               PlsqlBlock block = matchList.get(x);
    5.70 +               if (!(block.getParent() != null ? block.getParent().getName().equalsIgnoreCase(packageName) : true)) {
    5.71 +                   continue; //If the parent block name is not the same this is not a match
    5.72 +               }
    5.73 +
    5.74 +               int count = fetchMethodParamsCount(dest, block.getStartOffset());
    5.75 +               
    5.76 +               if (usageCount == count) {
    5.77 +                   similarParaCountList.add(block);
    5.78 +               }
    5.79 +            }
    5.80 +            if (similarParaCountList.size() > 0) {
    5.81 +                if (similarParaCountList.size() == 1) {
    5.82 +                    match = similarParaCountList.get(0);
    5.83 +                } else {
    5.84 +                    return similarParaCountList;
    5.85 +                }
    5.86 +            }
    5.87 +            if (match == null && matchList.size() > 0) {
    5.88 +                return matchList;
    5.89 +            }            
    5.90 +        }
    5.91 +        List<PlsqlBlock> returnList = new ArrayList<PlsqlBlock>();
    5.92 +        if (match != null) {
    5.93 +            returnList.add(match);
    5.94 +        }
    5.95 +        return (match == null && findBestMatch && matchList.size() > 0) ? null : returnList;
    5.96 +    }        
    5.97  
    5.98      /**
    5.99       * Compare given parameter lists
   5.100 @@ -257,6 +338,50 @@
   5.101          }
   5.102          return params;
   5.103      }
   5.104 +    
   5.105 +    private static int fetchMethodParamsCount(final Document doc, final int start) {
   5.106 +        int noOfParams = 0;
   5.107 +        final TokenHierarchy tokenHierarchy = TokenHierarchy.get(doc);
   5.108 +        @SuppressWarnings("unchecked")
   5.109 +        final TokenSequence<PlsqlTokenId> ts = tokenHierarchy.tokenSequence(PlsqlTokenId.language());
   5.110 +
   5.111 +        if (ts != null) {
   5.112 +            ts.move(start);
   5.113 +            Token<PlsqlTokenId> token = ts.token();
   5.114 +            HashSet<String> keywords = new HashSet<String>();
   5.115 +            while (ts.moveNext()) {
   5.116 +                token = ts.token();
   5.117 +                if ((token.text().toString().equals(",")) || (token.text().toString().equals(")"))) {
   5.118 +                    noOfParams++;
   5.119 +                }
   5.120 +
   5.121 +                if ((token.text().toString().equalsIgnoreCase("IS")) || (token.text().toString().equals(")")) || (token.text().toString().equals(";"))) {
   5.122 +                    break;
   5.123 +                }
   5.124 +            }
   5.125 +        }
   5.126 +        return noOfParams;
   5.127 +    }
   5.128 +    
   5.129 +    public static String fetchMethodHeader(final Document doc, final int start) {
   5.130 +        String header = "";
   5.131 +        final TokenHierarchy tokenHierarchy = TokenHierarchy.get(doc);
   5.132 +        @SuppressWarnings("unchecked")
   5.133 +        final TokenSequence<PlsqlTokenId> ts = tokenHierarchy.tokenSequence(PlsqlTokenId.language());
   5.134 +
   5.135 +        if (ts != null) {
   5.136 +            ts.move(start);
   5.137 +            Token<PlsqlTokenId> token = ts.token();
   5.138 +            while (ts.moveNext()) {
   5.139 +                token = ts.token();
   5.140 +                header += token;
   5.141 +                if ((token.text().toString().equalsIgnoreCase("IS")) || (token.text().toString().equals(")")) || (token.text().toString().equals(";"))) {
   5.142 +                    break;
   5.143 +                }
   5.144 +            }
   5.145 +        }
   5.146 +        return header;
   5.147 +    }        
   5.148  
   5.149      /**
   5.150       * Method that will access the parameter types of the function/procedure definition