Package org.openide.src

Examples of org.openide.src.MethodElement


       
    this.customized_innerclass.setName(Identifier.create(neuer_Class_Name));
    this.customized_outerclass.setName(Identifier.create(TargetName));
          
    //we have to exchange the source code of all methods of the inner class
    MethodElement MElements[] = this.customized_innerclass.getMethods();
    for(int i = 0;i <= MElements.length-1;i = i+1)
     { 
      String helpstring1 = "";
      MethodElement MElement = (MethodElement) MElements[i].clone();
   
      String helpstring = MElement.getBody().toString();
      int start = 1;
      int ende = helpstring.indexOf(alter_Class_Name);
      if (ende != -1)
         {
          while(ende != -1)
           {
            helpstring1 = helpstring1 + helpstring.substring(start,ende) + neuer_Class_Name ;
            start = ende + alter_Class_Name.length() ;
            ende = helpstring.indexOf(alter_Class_Name,start);
           }
          helpstring1 = helpstring1 + helpstring.substring(start,helpstring.length());
          try {
               MElement.setBody(helpstring1);
               this.customized_innerclass.removeMethod(MElements[i])
               this.customized_innerclass.addMethod(MElement)
              }catch (Exception e){e.printStackTrace(System.out);}
                    
         }
    }
    // now we change the name in the outer class
   MethodElement MElements1[] = this.customized_outerclass.getMethods();
   for(int i = 0;i <= MElements1.length-1;i = i+1)
    { 
      String helpstring11 = "";
      MethodElement MElement1 = (MethodElement) MElements1[i].clone();
      String helpstring2 = MElement1.getBody().toString();
      int start1 = 1;
      int ende1 = helpstring2.indexOf(alter_Class_Name);
      if (ende1 != -1)
         {
           while(ende1 != -1)
             {
               helpstring11 = helpstring11 + helpstring2.substring(start1,ende1) + neuer_Class_Name;
               start1 = ende1 + alter_Class_Name.length() ;
               ende1 = helpstring2.indexOf(alter_Class_Name,start1);
             }
           helpstring11 = helpstring11 + helpstring2.substring(start1,helpstring2.length());
           try {
                MElement1.setBody(helpstring11);
                this.customized_outerclass.removeMethod(MElements1[i])
                this.customized_outerclass.addMethod(MElement1)
               }catch (Exception e){e.printStackTrace(System.out);}
         }
     }
View Full Code Here


     // I have to take the detour over the Identifier.create, because we want to
     // insert the interfaces into the class without the package names.  
     this.customized_innerclass.addInterface(Identifier.create(newInterface.getIDLName().getName()));
     // The new interface is in the declaration now we habe to put the interface into the
     // methode getType   
     MethodElement aMethodeSrc = this.customized_innerclass.getMethod(Identifier.create("getTypes"), new Type [0]);
     MethodElement aMethodeDes = (MethodElement) aMethodeSrc.clone();
     String MethodString = aMethodeDes.getBody();
     int start = MethodString.indexOf("new Type(");
     String MethodString1 = MethodString.substring(1,start) + "new Type( " + newInterface.getIDLName().getName() + ".class),\n" + MethodString.substring(start,MethodString.length());
     this.customized_innerclass.removeMethod(aMethodeSrc);
     aMethodeDes.setBody(MethodString1);
     this.customized_innerclass.addMethod(aMethodeDes);
     // interfaces are done - now we have to add the methodes

     
   }catch(Exception e){}
View Full Code Here

     // I have to take the detour over the Identifier.create, because we want to
     // insert the interfaces into the class without the package names.  
     this.customized_innerclass.removeInterface(Identifier.create(newInterface.getIDLName().getName()));
     // The new interface is in the declaration now we habe to put the interface into the
     // methode getType   
     MethodElement aMethodeSrc = this.customized_innerclass.getMethod(Identifier.create("getTypes"), new Type [0]);
     MethodElement aMethodeDes = (MethodElement) aMethodeSrc.clone();
     String MethodString = aMethodeDes.getBody();
     int ende = MethodString.indexOf("new Type( " + newInterface.getIDLName().getName() + ".class),\n" );
     int start = MethodString.indexOf("new Type( ",ende + 1 );
     String MethodString1 = MethodString.substring(1,ende)+ MethodString.substring(start,MethodString.length());
     this.customized_innerclass.removeMethod(aMethodeSrc);
     aMethodeDes.setBody(MethodString1);
     this.customized_innerclass.addMethod(aMethodeDes);
            
   }catch(Exception e){}
  }
View Full Code Here

               
                // Set the default category.
                idlmethod.setCategory( "Add-in" );
               
                // Get the method element.
                MethodElement methodelement = idlmethod.getMethodElement();
               
                // Get the parameters from the method.
                MethodParameter[] methodparameter =
                methodelement.getParameters();
               
                // Create an array for the parameter description.
                IDLParameter[] idlparameter =
                new IDLParameter[ methodparameter.length ];
               
View Full Code Here

       
        // Get method element for display argument names.
        Type[] typeParameterArgumentName = new Type[ 2 ];
        typeParameterArgumentName[ 0 ] = Type.parse( "java.lang.String" );
        typeParameterArgumentName[ 1 ] = Type.parse( "int" );
        MethodElement methodelementDisplayArgumentName =
        //oocalcaddinsdata.customized_innerclass.getMethod(
        oocalcaddinsdata.getInnerClass().getMethod(
        Identifier.create( "getDisplayArgumentName" ),
        typeParameterArgumentName );
       
        // Get method element for argument description.
        Type[] typeParameterArgumentDescription = new Type[ 2 ];
        typeParameterArgumentDescription[ 0 ] = Type.parse( "java.lang.String" );
        typeParameterArgumentDescription[ 1 ] = Type.parse( "int" );
        MethodElement methodelementArgumentDescription =
        //oocalcaddinsdata.customized_innerclass.getMethod(
        oocalcaddinsdata.getInnerClass().getMethod(
        Identifier.create( "getArgumentDescription" ),
        typeParameterArgumentDescription );
       
        // Get method element for display function names.
        Type[] typeParameterFunctionName = new Type[ 1 ];
        typeParameterFunctionName[ 0 ] = Type.parse( "java.lang.String" );
        MethodElement methodelementDisplayFunctionName =
        //oocalcaddinsdata.customized_innerclass.getMethod(
        oocalcaddinsdata.getInnerClass().getMethod(
        Identifier.create( "getDisplayFunctionName" ),
        typeParameterFunctionName );
       
        // Get method element for function description.
        Type[] typeParameterFunctionDescription = new Type[ 1 ];
        typeParameterFunctionDescription[ 0 ] = Type.parse( "java.lang.String" );
        MethodElement methodelementFunctionDescription =
        //oocalcaddinsdata.customized_innerclass.getMethod(
        oocalcaddinsdata.getInnerClass().getMethod(
        Identifier.create( "getFunctionDescription" ),
        typeParameterFunctionDescription );
       
        // Get method element for programmatic category name.
        Type[] typeParameterCategoryName = new Type[ 1 ];
        typeParameterCategoryName[ 0 ] = Type.parse( "java.lang.String" );
        MethodElement methodelementCategoryName =
        //oocalcaddinsdata.customized_innerclass.getMethod(
        oocalcaddinsdata.getInnerClass().getMethod(
        Identifier.create( "getProgrammaticCategoryName" ),
        typeParameterCategoryName );
       
        for ( int intInterfaceCounter = 0;
        intInterfaceCounter < vectorInterfaces.size();
        intInterfaceCounter++ ) {
            IDLInterface interfacedescription = ( IDLInterface )
            vectorInterfaces.elementAt( intInterfaceCounter );
            for ( int intMethodCounter = 0;
            intMethodCounter < interfacedescription.getVectorMethods().size();
            intMethodCounter++ ) {
                try {
                    IDLMethod methoddescription = ( IDLMethod )
                    interfacedescription.getVectorMethods().elementAt( intMethodCounter );
                   
                    FieldElement fieldelement = new FieldElement();
                   
                    fieldelement.setName( Identifier.create( "short" +
                    methoddescription.getMethodElement().getName().getName().toUpperCase() ) );
                   
                    fieldelement.setInitValue( String.valueOf( intMethod++ ) );
                   
                    fieldelement.setType( Type.parse( "short" ) );
                   
                    fieldelement.setModifiers( Modifier.PRIVATE
                    + Modifier.FINAL + Modifier.STATIC );
                   
                    //oocalcaddinsdata.customized_innerclass.addField(
                    //fieldelement );
                    oocalcaddinsdata.getInnerClass().addField(
                    fieldelement );
                   
                    fieldelementFunctionNames.setInitValue(
                    fieldelementFunctionNames.getInitValue().substring( 0,
                    fieldelementFunctionNames.getInitValue().length() - 1 )
                    + ( ( intMethod == 1 ) ? "" : ",\n            " ) + "\""
                    + methoddescription.getMethodElement().getName().getName()
                    + "\"}" );
                   
                    // Insert display argument name.
                    MethodParameter[] methodparameter =
                    methoddescription.getMethodElement().getParameters();
                   
                    String stringCaseParameter =
                    /*
                    "                        case 0:\n"
                    + "                            stringReturn = \"(internal)\";\n"
                    + "                            break;\n";
                     */
                    "";
                   
                    for ( int intParameterCounter = 0;
                    intParameterCounter < methoddescription.getArgumentDescription().length;
                    intParameterCounter++ ) {
                        stringCaseParameter +=
                        "                        case "
                        //+ ( intParameterCounter + 1 ) + ":\n"
                        + intParameterCounter + ":\n"
                        + "                            stringReturn = \""
                        + methoddescription.getArgumentDescription()[ intParameterCounter ].getDisplayArgumentName()
                        + "\";\n"
                        + "                            break;\n";
                       
                    }
                   
                    String stringDisplayArgumentNameBody =
                    methodelementDisplayArgumentName.getBody();
                   
                    int intIndexCurlyBraceOpen =
                    stringDisplayArgumentNameBody.indexOf( "{" );
                   
                    stringDisplayArgumentNameBody =
                    stringDisplayArgumentNameBody.substring( 0,
                    intIndexCurlyBraceOpen + 1 )
                    + "\n                case short"
                    + methoddescription.getMethodElement().getName().getName().toUpperCase()
                    + ":\n"
                    + "                    switch( intArgument ) {\n"
                    + stringCaseParameter
                    + "                    }\n"
                    + "                    break;"
                    + stringDisplayArgumentNameBody.substring(
                    intIndexCurlyBraceOpen + 1 );
                   
                    methodelementDisplayArgumentName.setBody(
                    stringDisplayArgumentNameBody );
                   
                    // Insert argument description.
                    String stringCaseParameterDescription =
                    /*
                    "                        case 0:\n"
                    + "                            stringReturn = \"(internal)\";\n"
                    + "                            break;\n";
                     */
                    "";
                   
                    for ( int intParameterCounter = 0;
                    intParameterCounter < methoddescription.getArgumentDescription().length;
                    intParameterCounter++ ) {
                        stringCaseParameterDescription +=
                        "                        case "
                        //+ ( intParameterCounter + 1 ) + ":\n"
                        + intParameterCounter + ":\n"
                        + "                            stringReturn = \""
                        + methoddescription.getArgumentDescription()[ intParameterCounter ].getArgumentDescription()
                        + "\";\n"
                        + "                            break;\n";
                       
                    }
                   
                    String stringArgumentDescriptionBody =
                    methodelementArgumentDescription.getBody();
                   
                    intIndexCurlyBraceOpen =
                    stringArgumentDescriptionBody.indexOf( "{" );
                   
                    stringArgumentDescriptionBody =
                    stringArgumentDescriptionBody.substring( 0,
                    intIndexCurlyBraceOpen + 1 )
                    + "\n                case short"
                    + methoddescription.getMethodElement().getName().getName().toUpperCase()
                    + ":\n"
                    + "                    switch( intArgument ) {\n"
                    + stringCaseParameterDescription
                    + "                    }\n"
                    + "                    break;"
                    + stringArgumentDescriptionBody.substring(
                    intIndexCurlyBraceOpen + 1 );
                   
                    methodelementArgumentDescription.setBody(
                    stringArgumentDescriptionBody );
                   
                    // Insert display function names.
                    String stringDisplayFunctionNameBody =
                    methodelementDisplayFunctionName.getBody();
                   
                    intIndexCurlyBraceOpen =
                    stringDisplayFunctionNameBody.indexOf( "{" );
                   
                    stringDisplayFunctionNameBody =
                    stringDisplayFunctionNameBody.substring( 0,
                    intIndexCurlyBraceOpen + 1 )
                    + "\n                case short"
                    + methoddescription.getMethodElement().getName().getName().toUpperCase()
                    + ":\n"
                    + "                    stringReturn = \""
                    + methoddescription.getDisplayFunctionName()
                    + "\";\n"
                    + "                    break;"
                    + stringDisplayFunctionNameBody.substring(
                    intIndexCurlyBraceOpen + 1 );
                   
                    methodelementDisplayFunctionName.setBody(
                    stringDisplayFunctionNameBody );
                   
                    // Insert function description.
                    String stringFunctionDescriptionBody =
                    methodelementFunctionDescription.getBody();
                   
                    intIndexCurlyBraceOpen =
                    stringFunctionDescriptionBody.indexOf( "{" );
                   
                    stringFunctionDescriptionBody =
                    stringFunctionDescriptionBody.substring( 0,
                    intIndexCurlyBraceOpen + 1 )
                    + "\n                case short"
                    + methoddescription.getMethodElement().getName().getName().toUpperCase()
                    + ":\n"
                    + "                    stringReturn = \""
                    + methoddescription.getFunctionDescription()
                    + "\";\n"
                    + "                    break;"
                    + stringFunctionDescriptionBody.substring(
                    intIndexCurlyBraceOpen + 1 );
                   
                    methodelementFunctionDescription.setBody(
                    stringFunctionDescriptionBody );
                   
                    // Insert programmatic category name.
                    String stringCategoryNameBody =
                    methodelementCategoryName.getBody();
                   
                    intIndexCurlyBraceOpen =
                    stringCategoryNameBody.indexOf( "{" );
                   
                    stringCategoryNameBody =
                    stringCategoryNameBody.substring( 0,
                    intIndexCurlyBraceOpen + 1 )
                    + "\n                case short"
                    + methoddescription.getMethodElement().getName().getName().toUpperCase()
                    + ":\n"
                    + "                    stringReturn = \""
                    + methoddescription.getCategory()
                    + "\";\n"
                    + "                    break;"
                    + stringCategoryNameBody.substring(
                    intIndexCurlyBraceOpen + 1 );
                   
                    methodelementCategoryName.setBody(
                    stringCategoryNameBody );
                }
                catch( SourceException sourceexception ) {
                    // Show message.
                    TopManager.getDefault().notify(
View Full Code Here

           
            //we will parse methods only
            if  (aTokens[j].endsWith(")")) {
                String s5;
               
                MethodElement aMethodeElement = new MethodElement();
               
                // at first we have to take care of the exception
                if  (aTokens[j].indexOf("raises") != -1) {
                    s5 = aTokens[j].substring(0,aTokens[j].indexOf("raises")-2);
                    String s5b = aTokens[j].substring(aTokens[j].indexOf("raises") + 6);
                   
                    //if s5b not 0 - then we have to deal with the exceptions
                    if (s5b.length() != 0 ) {
                        String s6 = s5b.trim().substring(1);
                        s6 = s6.substring(0,s6.length()-1);
                        StringTokenizer stt6 = new StringTokenizer(s6,",");
                        int btokens =  stt6.countTokens();
                        Identifier[] aExceptions = new Identifier[btokens];
                        for(int a=0; a <  btokens;a++) {
                            aExceptions[a] = Identifier.create(OOTools.replaceSubStrings(stt6.nextToken().trim(),"::", "."));
                        }
                        try {
                            aMethodeElement.setExceptions(aExceptions);
                        }catch (Exception e){
                            System.out.println( e );
                        }
                    }
                } else  s5 = aTokens[j].substring(0,aTokens[j].length()-1);
               
                // s5 contains only the methode without an exception
                // it is possible the the line starts with a comment
                // which was inserted at the end of the line before
               
                StringTokenizer st5 = new StringTokenizer(s5,"(");
               
                // if we have a methode with has no parameter - st5 will contain only one token
                // it does no matter if the method raises a eception or not.
                // that means we have to test the token count
                // we have to care about the parameters only if the count is 2
               
                StringTokenizer st6 = new StringTokenizer(st5.nextToken().trim()," ");
               
               
                // after we have created st6 - n tokens
                // n should be the name of the function
                // n - 1 is definitely the return type of the function
                // n - 2 could be a modifier or the keyword oneway or simply a
                // word of a comment
                // n-3 to 0 all stuff we do not need
               
               
                int ctokens = st6.countTokens();
               
                String returnType = null;
               
                try {
                    if (ctokens > 3)
                    { for(int b=0; b < ctokens-3;b++) {
                          st6.nextToken();
                      }
                    }
                    if (ctokens>=3) {
                        // this could be the modifier
                        String ModifierString = st6.nextToken();
                        if ((ModifierString=="public") || (ModifierString=="protected") || (ModifierString=="private")) {
                            if (ModifierString=="public") aMethodeElement.setModifiers(java.lang.reflect.Modifier.PUBLIC);
                            if (ModifierString=="protected") aMethodeElement.setModifiers(java.lang.reflect.Modifier.PROTECTED);
                            if (ModifierString=="private") aMethodeElement.setModifiers(java.lang.reflect.Modifier.PRIVATE);
                        }else{aMethodeElement.setModifiers(java.lang.reflect.Modifier.PUBLIC); }
                       
                    }
                    if (ctokens==2) aMethodeElement.setModifiers(java.lang.reflect.Modifier.PUBLIC);
                    returnType = st6.nextToken();
                    aMethodeElement.setName(Identifier.create(st6.nextToken()));
                    String sss = this.mapParameterTypes(returnType);
                    aMethodeElement.setReturn(Type.parse(this.mapParameterTypes(returnType)));
                   
                   
                }catch (Exception e){
                    System.out.println( e );
                };
               
                // test how many tokens are left over in st5
                if (st5.countTokens()== 1) {
                    // due to the fact that st5 still contains one token, we have to take care of the parameters
                    st6 = new StringTokenizer(st5.nextToken(),",");
                    tokens = st6.countTokens();
                   
                    org.openide.src.MethodParameter[] aMethodeParameters = new org.openide.src.MethodParameter[tokens];
                    for(int k=0; k < tokens;k++)
                    {  String aTypeString;
                       StringTokenizer st7 = new StringTokenizer(st6.nextToken().trim()," ");
                       // now we have the certain parameter
                       String Direction = st7.nextToken();
                      
                       if (Direction.indexOf("out")!= -1) aTypeString = "sequence<" + st7.nextToken()+">";
                       else   aTypeString = st7.nextToken();
                       String bString = st7.nextToken();
                       aMethodeParameters[k] = new org.openide.src.MethodParameter(bString, Type.parse(this.mapParameterTypes(aTypeString)), false);
                    }
                    try {
                        aMethodeElement.setParameters(aMethodeParameters);
                    } catch (Exception e){
                        System.out.println( e );
                    }
                }
                try {
                    // Define an empty return command.
                    String stringReturnCommand = "";
                   
                    // Test if return type is not void.
                    if ( !returnType.equals( "void" ) ) {
                        // Get the Java type of the method.
                        String stringJavaType = this.mapParameterTypes(
                        returnType );
                       
                        if ( ( stringJavaType.equals( "short" )
                        || ( stringJavaType.equals( "int" ) )
                        || ( stringJavaType.equals( "long" ) )
                        || ( stringJavaType.equals( "float" ) )
                        || ( stringJavaType.equals( "double" ) )
                        || ( stringJavaType.equals( "char" ) )
                        || ( stringJavaType.equals( "byte" ) ) ) ) {
                            stringReturnCommand = "\nreturn 0;\n";
                        }
                        else if ( stringJavaType.equals( "boolean" ) ) {
                            stringReturnCommand = "\nreturn false;\n";
                        }
                        else {
                            stringReturnCommand = "\nreturn null;\n";
                        }
                    }
                   
                    aMethodeElement.setBody(
                    "\n\n\n// ToDo: Please insert your implementation code "
                    + "here.\n\n" + stringReturnCommand );
                    IDLMethod aIDLMethod = new IDLMethod();
                    aIDLMethod.setMethod(aMethodeElement);
                    bIDLInterface.addIDLMethod(aIDLMethod);
View Full Code Here

TOP

Related Classes of org.openide.src.MethodElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.