Example usage for org.eclipse.jdt.core.dom SingleVariableDeclaration TYPE_PROPERTY

List of usage examples for org.eclipse.jdt.core.dom SingleVariableDeclaration TYPE_PROPERTY

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom SingleVariableDeclaration TYPE_PROPERTY.

Prototype

ChildPropertyDescriptor TYPE_PROPERTY

To view the source code for org.eclipse.jdt.core.dom SingleVariableDeclaration TYPE_PROPERTY.

Click Source Link

Document

The "type" structural property of this node type (child type: Type ).

Usage

From source file:org.autorefactor.refactoring.rules.UseMultiCatchRefactoring.java

License:Open Source License

@Override
public boolean visit(TryStatement node) {
    List<CatchClause> catchClauses = catchClauses(node);
    Binding[] typeBindings = resolveTypeBindings(catchClauses);
    for (int i = 0; i < catchClauses.size(); i++) {
        CatchClause catchClause1 = catchClauses.get(i);
        for (int j = i + 1; j < catchClauses.size(); j++) {
            CatchClause catchClause2 = catchClauses.get(j);
            MergeDirection direction = mergeDirection(typeBindings, i, j);
            if (!MergeDirection.NONE.equals(direction) && matchMultiCatch(catchClause1, catchClause2)) {
                Refactorings r = this.ctx.getRefactorings();
                UnionType ut = unionTypes(catchClause1.getException().getType(),
                        catchClause2.getException().getType());
                if (MergeDirection.UP.equals(direction)) {
                    r.set(catchClause1.getException(), SingleVariableDeclaration.TYPE_PROPERTY, ut);
                    r.remove(catchClause2);
                } else if (MergeDirection.DOWN.equals(direction)) {
                    r.remove(catchClause1);
                    r.set(catchClause2.getException(), SingleVariableDeclaration.TYPE_PROPERTY, ut);
                }// ww  w  .  j av  a2s. c  om
                return DO_NOT_VISIT_SUBTREE;
            }
        }
    }
    return VISIT_SUBTREE;
}

From source file:org.fastcode.util.SourceUtil.java

License:Open Source License

/**
 * @param compilationUnit/*w  ww  .  ja  va  2 s.  com*/
 * @return
 * @throws Exception
 */
public static List<FastCodeReturn> getLocalVarFromCompUnit(final ICompilationUnit compilationUnit,
        final IEditorPart editorPart) throws Exception {
    final ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setSource(compilationUnit);
    parser.setResolveBindings(true);
    final IJavaElement currentMethod = findSelectedJavaElement(compilationUnit, editorPart);
    if (currentMethod == null) {
        return new ArrayList<FastCodeReturn>();
    }
    final CompilationUnit parse = (CompilationUnit) parser.createAST(null);
    final FastCodeVisitor methodVisitor = new FastCodeVisitor(currentMethod.getElementName(), compilationUnit);
    parse.accept(methodVisitor);
    final Shell parentShell = MessageUtil.getParentShell();
    final List<FastCodeReturn> variablesList = methodVisitor.getFastCodeReturns();
    for (final Object obj : methodVisitor.getMethodDecln().parameters()) {
        final VariableDeclaration variableDeclaration = (VariableDeclaration) obj;
        final String type = variableDeclaration.getStructuralProperty(SingleVariableDeclaration.TYPE_PROPERTY)
                .toString();
        final FastCodeReturn fastCodeReturn = new FastCodeReturn(variableDeclaration.getName().toString(),
                new FastCodeType(getFQNameFromFieldTypeName(type.toString(), compilationUnit)));
        variablesList.add(fastCodeReturn);
    }
    return variablesList;
}

From source file:org.moe.natjgen.MethodEditor.java

License:Apache License

@SuppressWarnings("unchecked")
public void setArgument(int idx, String arg_name, Type type, TypeResolver resolver) throws GeneratorException {
    editLock();//from w  w w .ja  v a  2s.  c om

    ListRewrite mlrw = getRewrite().getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY);
    List<SingleVariableDeclaration> list = (List<SingleVariableDeclaration>) mlrw.getRewrittenList();
    SingleVariableDeclaration svd = list.get(idx);

    SimpleName property = (SimpleName) getRewrite().get(svd, SingleVariableDeclaration.NAME_PROPERTY);
    if (property == null || !property.getFullyQualifiedName().equals(arg_name)) {
        getRewrite().set(svd, SingleVariableDeclaration.NAME_PROPERTY, getAST().newName(arg_name),
                getEditGroup());
    }

    ModifierEditor argmod = new ModifierEditor(getManager(), svd, SingleVariableDeclaration.MODIFIERS2_PROPERTY,
            true);
    resolver.resolve(getManager(), svd, SingleVariableDeclaration.TYPE_PROPERTY, argmod, type, true);
    argmod.close();

    // Add uncertain descriptor
    UncertainDescriptor udesc = argmod.getUncertainDescriptor();
    if (udesc != null) {
        uncertains.add(new UncertainElem(Integer.toString(idx), udesc));
    }
}

From source file:org.moe.natjgen.MethodEditor.java

License:Apache License

@SuppressWarnings("unchecked")
public void setVariadicArgument(int idx, String arg_name) throws GeneratorException {
    editLock();//ww  w .j  a  v  a  2s.c o m

    ListRewrite mlrw = getRewrite().getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY);
    List<SingleVariableDeclaration> list = (List<SingleVariableDeclaration>) mlrw.getRewrittenList();
    SingleVariableDeclaration svd = list.get(idx);

    SimpleName property = (SimpleName) getRewrite().get(svd, SingleVariableDeclaration.NAME_PROPERTY);
    if (property == null || !property.getFullyQualifiedName().equals(arg_name)) {
        getRewrite().set(svd, SingleVariableDeclaration.NAME_PROPERTY, getAST().newName(arg_name),
                getEditGroup());
    }

    SimpleType type = getAST().newSimpleType(getAST().newName("Object"));
    getRewrite().set(svd, SingleVariableDeclaration.TYPE_PROPERTY, type, getEditGroup());
    getRewrite().set(svd, SingleVariableDeclaration.VARARGS_PROPERTY, Boolean.TRUE, getEditGroup());
}

From source file:org.moe.natjgen.MethodEditor.java

License:Apache License

@SuppressWarnings("unchecked")
public boolean hasArgumentTypeMatch(Type[] args) {
    ListRewrite a_lrw = getRewrite().getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY);
    List<SingleVariableDeclaration> svds = a_lrw.getRewrittenList();
    if (svds.size() != args.length) {
        return false;
    }//from  w  ww  .  j ava 2  s  . c  o m

    for (int i = 0; i < args.length; ++i) {
        SingleVariableDeclaration vdec = (SingleVariableDeclaration) svds.get(0);
        org.eclipse.jdt.core.dom.Type type = (org.eclipse.jdt.core.dom.Type) getRewrite().get(vdec,
                SingleVariableDeclaration.TYPE_PROPERTY);
        if (!isSimilarTo(args[i], type)) {
            return false;
        }
    }

    return true;
}