Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.Type


                            continue;
                        }

                        if (org.eclipse.jdt.core.dom.Modifier.isPublic(method.getModifiers()) && !method.isConstructor()) {
                            String sType = "void";
                            Type type = method.getReturnType2();
                            if (type != null) {
                                sType = buildFullQualifiedClassname(type, _imports, classname);
                            }
                           
                            TMLScriptMethod tmlScriptMethod = new TMLScriptMethod(method.getName().toString(), sType, classname);
                            tmlScriptMethod.setBeanMode(modeVisitor.getBeanMode());
                            tmlScriptMethod.setDeprecated(isDeprecated(method));
                            if (org.eclipse.jdt.core.dom.Modifier.isStatic(method.getModifiers())) {
                                tmlScriptMethod.setStatic(true);
                            }                           
                           
                            for (Object param : method.parameters()) {
                                SingleVariableDeclaration varDec = (SingleVariableDeclaration) param;
                                String varType = varDec.getType().toString();
                                if (_imports.containsKey(varType)) {
                                    varType = _imports.get(varType);
                                }
                                de.innovationgate.eclipse.editors.tmlscript.parsing.TMLScriptMethodParameter tmlscriptParam = new de.innovationgate.eclipse.editors.tmlscript.parsing.TMLScriptMethodParameter(varDec.getName().toString(), varType);
                                tmlscriptParam.setVararg(varDec.isVarargs());
                                tmlScriptMethod.getParameters().add(tmlscriptParam);
                            }
                            methods.add(tmlScriptMethod);
                        }
                    }
                   
                    Type superClass = node.getSuperclassType();
                    if (superClass != null) {
                        methods.addAll(getPublicMethods(buildFullQualifiedClassname(superClass, _imports, classname), envFlags));
                    }
                }
                super.endVisit(node);
View Full Code Here


    public String[] getInterfaces() {
        if (m_class instanceof TypeDeclaration) {
            List types = ((TypeDeclaration)m_class).superInterfaceTypes();
            ArrayList names = new ArrayList();
            for (Iterator iter = types.iterator(); iter.hasNext();) {
                Type type = (Type)iter.next();
                names.add(type.toString());
            }
            return (String[])names.toArray(new String[names.size()]);
        } else if (m_class instanceof EnumDeclaration) {
            return Utility.EMPTY_STRING_ARRAY;
        } else {
View Full Code Here

            typeparms = type.substring(split+1, type.length()-1);
            type = type.substring(0, split);
        }
       
        // handle the basic type creation
        Type tdef;
        Code code = (Code)s_primitiveTypeCodes.get(type);
        if (code == null) {
            tdef = getAST().newSimpleType(createTypeName(type));
        } else {
            tdef = getAST().newPrimitiveType(code);
View Full Code Here

                + propname);
        }
       
        // find the types to be used for field and actual instance
        String type;
        Type fieldtype;
        Type insttype;
        int reptype = getSchemaCustom().getRepeatType();
        if (reptype == SchemaRootBase.REPEAT_TYPED) {
            fieldtype = builder.createParameterizedType(COLLECTION_VARIABLE_TYPE, basetype);
            insttype = builder.createType(basetype);
            while (--collcount > 0) {
                fieldtype = builder.createParameterizedType(COLLECTION_VARIABLE_TYPE, fieldtype);
                insttype = builder.createParameterizedType(COLLECTION_VARIABLE_TYPE, insttype);
            }
            type = basetype;
            insttype = builder.createParameterizedType(m_listImplClass, insttype);
        } else if (reptype == SchemaRootBase.REPEAT_LIST || node.isAny()) {
            fieldtype = builder.createType(COLLECTION_VARIABLE_TYPE);
            insttype = builder.createType(m_listImplClass);
            if (collcount > 1) {
                type = COLLECTION_VARIABLE_TYPE;
            } else {
                type = basetype;
            }
        } else {
            type = basetype;
            while (--collcount > 0) {
                type += "[]";
            }
            fieldtype = builder.createType(type + "[]");
            insttype = null;
        }
       
        // get documentation and description text
        String document = findDocumentation(true, node);
        String descript = describe(node);
        String term = getSchemaCustom().getRepeatType() == SchemaRootBase.REPEAT_ARRAY ? "array" : "list";
       
        // generate the field as a collection
        String fname = node.getFieldName();
        FieldBuilder field = builder.addField(fname, fieldtype);
        if (insttype != null) {
            field.setInitializer(builder.newInstance(insttype));
        }
        field.setPrivate();
       
        // add get method definition (unchecked, but result meaningless if not the selected group item)
        MethodBuilder getmeth = builder.addMethod(node.getGetMethodName(), (Type)builder.clone(fieldtype));
        getmeth.setPublic();
        StringBuffer buff = new StringBuffer();
        buff.append("Get the ");
        buff.append(term);
        buff.append(" of ");
        buff.append(descript);
        buff.append(" items.");
        if (document != null) {
            buff.append(' ');
            buff.append(document);
        }
        getmeth.addSourceComment(buff.toString());
        getmeth.addSourceComment("");
        getmeth.addSourceComment("@return", " " + term);
        getmeth.createBlock().addReturnNamed(fname);
       
        // add the set method definition
        MethodBuilder setmeth = builder.addMethod(node.getSetMethodName(), "void");
        setmeth.setPublic();
        buff.replace(0, 3, "Set");
        setmeth.addSourceComment(buff.toString());
        setmeth.addSourceComment("");
        setmeth.addSourceComment("@param", " " + COLLECTION_VARIABLE_NAME);
        setmeth.addParameter(COLLECTION_VARIABLE_NAME, (Type)builder.clone(fieldtype));
        BlockBuilder block = setmeth.createBlock();
        generateSelectorSet(node, block, builder);
        block.addAssignVariableToField(COLLECTION_VARIABLE_NAME, fname);
       
        // process list and collection differently for binding
        Item item = node.getItem();
        if (!node.isCollection()) {
           
            // determine format conversion handling for type
            String valsername = null;
            String valdesername = null;
            String valuename = null;
            FormatElement format = (FormatElement)s_formatMap.get(type);
            boolean passctx = false;
            if (format != null) {
                valsername = format.getSerializerName();
                valdesername = format.getDeserializerName();
                if (valsername == null && !"java.lang.String".equals(type)) {
                    valuename = "toString";
                }
                passctx = "org.jibx.runtime.QName".equals(type);
            } else if (item instanceof ReferenceItem) {
                DefinitionItem def = ((ReferenceItem)item).getDefinition();
                if (def.isEnumeration()) {
                    EnumerationClassHolder genclas = (EnumerationClassHolder)def.getGenerateClass();
                    valsername = EnumerationClassHolder.CONVERTFORCE_METHOD;
                    valuename = genclas.getName() + ".toString";
                }
            } else {
                throw new IllegalStateException("Internal error - invalid list type");
            }
           
            // add list serializer method to class
            String sername = LIST_SERIALIZE_PREFIX + propname;
            MethodBuilder sermeth = builder.addMethod(sername, "java.lang.String");
            sermeth.addParameter("values", (Type)builder.clone(fieldtype));
            if (passctx) {
                SingleVariableDeclaration decl = sermeth.addParameter("ictx", "org.jibx.runtime.IMarshallingContext");
                decl.modifiers().add(decl.getAST().newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));
                sermeth.addThrows("org.jibx.runtime.JiBXException");
            }
            sermeth.setPublicStatic();
            sermeth.addSourceComment("Serializer for " + descript + ' ' + term + '.');
            sermeth.addSourceComment("");
            sermeth.addSourceComment("@param", " values");
            sermeth.addSourceComment("@return", " text");
           
            // create a simple null return for null parameter string
            BlockBuilder nullblock = builder.newBlock();
            nullblock.addReturnNull();
           
            // create block for actual serialization when parameter non-null
            BlockBuilder serblock = builder.newBlock();
            NewInstanceBuilder newbuff = builder.newInstance("java.lang.StringBuffer");
            serblock.addLocalVariableDeclaration("java.lang.StringBuffer", "buff", newbuff);
           
            // create body of loop to handle the conversion
            BlockBuilder forblock = builder.newBlock();
           
            // append space to buffer unless empty
            InfixExpressionBuilder lengthexpr = builder.buildInfix(Operator.GREATER);
            lengthexpr.addOperand(builder.createNormalMethodCall("buff", "length"));
            lengthexpr.addNumberLiteralOperand("0");
            InvocationBuilder appendcall = builder.createNormalMethodCall("buff", "append");
            appendcall.addCharacterLiteralOperand(' ');
            BlockBuilder spaceblock = builder.newBlock();
            spaceblock.addExpressionStatement(appendcall);
            forblock.addIfStatement(lengthexpr, spaceblock);
           
            // load the current value from array
            if (reptype == SchemaRootBase.REPEAT_TYPED) {
                forblock.addLocalVariableDeclaration(type, "value", builder.createNormalMethodCall("iter", "next"));
            } else if (reptype == SchemaRootBase.REPEAT_LIST) {
                CastBuilder castexpr = builder.buildCast(type);
                castexpr.addOperand(builder.createNormalMethodCall("iter", "next"));
                forblock.addLocalVariableDeclaration(type, "value", castexpr);
            } else {
                forblock.addLocalVariableDeclaration(type, "value", builder.buildArrayIndexAccess("values", "index"));
            }
           
            // append the current value to the buffer
            appendcall = builder.createNormalMethodCall("buff", "append");
            if (valuename != null) {
                appendcall.addOperand(builder.createNormalMethodCall("value", valuename));
            } else if (valdesername != null) {
                InvocationBuilder sercall = builder.createStaticMethodCall(valsername);
                sercall.addVariableOperand("value");
                if (passctx) {
                    sercall.addVariableOperand("ictx");
                }
                appendcall.addOperand(sercall);
            } else {
                appendcall.addVariableOperand("value");
            }
            forblock.addExpressionStatement(appendcall);
           
            // build the for loop around the conversion
            if (reptype == SchemaRootBase.REPEAT_TYPED) {
                Type itertype = builder.createParameterizedType("java.util.Iterator", type);
                serblock.addIteratedForStatement("iter", itertype,
                    builder.createNormalMethodCall("values", "iterator"), forblock);
            } else if (reptype == SchemaRootBase.REPEAT_LIST) {
                serblock.addIteratedForStatement("iter", builder.createType("java.util.Iterator"),
                    builder.createNormalMethodCall("values", "iterator"), forblock);
View Full Code Here

    MethodDeclaration[] met = object.getMethods();
    for (int i = 0; i < met.length; i++) {
      MethodDeclaration dec = met[i];
      JMethod method = new JMethod();
      method.setMethodName(dec.getName().toString());
      Type returnType = dec.getReturnType2();
      if (returnType != null) {
        method.setReturnType(returnType.toString());
      }
      Block d = dec.getBody();
      if (d == null) {
        continue;
      }
View Full Code Here

            // accept the empty field (stands for java.lang.Object)
            return status;
        }

        if (root != null) {
            Type type = TypeContextChecker.parseSuperClass(sclassName);
            if (type == null) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_InvalidSuperClassName);
                return status;
            }
            if (type instanceof ParameterizedType && !JavaModelUtil.is50OrHigher(root.getJavaProject())) {
View Full Code Here

        if (root != null) {
            List<InterfaceWrapper> elements = fSuperInterfacesDialogField.getElements();
            int nElements = elements.size();
            for (int i = 0; i < nElements; i++) {
                String intfname = elements.get(i).interfaceName;
                Type type = TypeContextChecker.parseSuperInterface(intfname);
                if (type == null) {
                    status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidSuperInterfaceName, BasicElementLabels.getJavaElementName(intfname)));
                    return status;
                }
                if (type instanceof ParameterizedType && !JavaModelUtil.is50OrHigher(root.getJavaProject())) {
View Full Code Here

  public void visitMockUpCreation(final ClassInstanceCreation creation)
  {
    ASTNode gparent = creation.getParent();

    Type typeNode = creation.getType();
    boolean invokesGetInst = false;

    if (gparent instanceof MethodInvocation) // method invocation follows
    {
      MethodInvocation inv = (MethodInvocation) gparent;
View Full Code Here

    ITypeBinding declaringType = null;

    if( node.getParent() instanceof ClassInstanceCreation ) // for anonymous
    {
      ClassInstanceCreation creation = (ClassInstanceCreation) node.getParent();
      Type ctype = creation.getType();

      declaringType = getFirstTypeParam(ctype);
    }
    else if( node instanceof TypeDeclaration )
    {
      Type ctype = ((TypeDeclaration) node).getSuperclassType();
      declaringType = getFirstTypeParam(ctype);
    }

    return declaringType;
  }
View Full Code Here

      ParameterizedType paramType = (ParameterizedType) ctype;
      List<Type> typeArgs = paramType.typeArguments();

      if( !typeArgs.isEmpty() )
      {
        Type arg1 = typeArgs.get(0);
        declaringType = arg1.resolveBinding();
      }
    }
    return declaringType;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.Type

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.