Search in sources :

Example 61 with SimpleName

use of org.eclipse.jdt.core.dom.SimpleName in project che by eclipse.

the class FullConstraintCreator method create.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.QualifiedName)
	 */
@Override
public ITypeConstraint[] create(QualifiedName qualifiedName) {
    SimpleName name = qualifiedName.getName();
    Name qualifier = qualifiedName.getQualifier();
    IBinding nameBinding = name.resolveBinding();
    if (nameBinding instanceof IVariableBinding) {
        IVariableBinding vb = (IVariableBinding) nameBinding;
        if (vb.isField())
            return createConstraintsForAccessToField(vb, qualifier, qualifiedName);
    }
    //TODO other bindings
    return new ITypeConstraint[0];
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) IBinding(org.eclipse.jdt.core.dom.IBinding) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) SimpleName(org.eclipse.jdt.core.dom.SimpleName) Name(org.eclipse.jdt.core.dom.Name) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName)

Example 62 with SimpleName

use of org.eclipse.jdt.core.dom.SimpleName in project che by eclipse.

the class FullConstraintCreator method getConstraintsFromFragmentList.

private ITypeConstraint[] getConstraintsFromFragmentList(List<VariableDeclarationFragment> list, Type type) {
    int size = list.size();
    ConstraintVariable typeVariable = fConstraintVariableFactory.makeTypeVariable(type);
    List<ITypeConstraint> result = new ArrayList<ITypeConstraint>((size * (size - 1)) / 2);
    for (int i = 0; i < size; i++) {
        VariableDeclarationFragment fragment1 = list.get(i);
        SimpleName fragment1Name = fragment1.getName();
        result.addAll(Arrays.asList(fTypeConstraintFactory.createDefinesConstraint(fConstraintVariableFactory.makeExpressionOrTypeVariable(fragment1Name, getContext()), typeVariable)));
        for (int j = i + 1; j < size; j++) {
            VariableDeclarationFragment fragment2 = list.get(j);
            result.addAll(Arrays.asList(fTypeConstraintFactory.createEqualsConstraint(fConstraintVariableFactory.makeExpressionOrTypeVariable(fragment1Name, getContext()), fConstraintVariableFactory.makeExpressionOrTypeVariable(fragment2.getName(), getContext()))));
        }
    }
    return result.toArray(new ITypeConstraint[result.size()]);
}
Also used : VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) SimpleName(org.eclipse.jdt.core.dom.SimpleName) ArrayList(java.util.ArrayList)

Example 63 with SimpleName

use of org.eclipse.jdt.core.dom.SimpleName in project che by eclipse.

the class FullConstraintCreator method create.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SuperFieldAccess)
	 */
@Override
public ITypeConstraint[] create(SuperFieldAccess access) {
    SimpleName name = access.getName();
    IBinding binding = name.resolveBinding();
    if (!(binding instanceof IVariableBinding))
        return new ITypeConstraint[0];
    IVariableBinding vb = (IVariableBinding) binding;
    return createConstraintsForAccessToField(vb, null, access);
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) IBinding(org.eclipse.jdt.core.dom.IBinding) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding)

Example 64 with SimpleName

use of org.eclipse.jdt.core.dom.SimpleName in project che by eclipse.

the class RenameNodeCorrectionProposal method addEdits.

/*(non-Javadoc)
	 * @see org.eclipse.jdt.internal.ui.text.correction.CUCorrectionProposal#addEdits(org.eclipse.jface.text.IDocument)
	 */
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
    super.addEdits(doc, root);
    // build a full AST
    CompilationUnit unit = SharedASTProvider.getAST(getCompilationUnit(), SharedASTProvider.WAIT_YES, null);
    ASTNode name = NodeFinder.perform(unit, fOffset, fLength);
    if (name instanceof SimpleName) {
        SimpleName[] names = LinkedNodeFinder.findByProblems(unit, (SimpleName) name);
        if (names != null) {
            for (int i = 0; i < names.length; i++) {
                SimpleName curr = names[i];
                root.addChild(new ReplaceEdit(curr.getStartPosition(), curr.getLength(), fNewName));
            }
            return;
        }
    }
    root.addChild(new ReplaceEdit(fOffset, fLength, fNewName));
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) SimpleName(org.eclipse.jdt.core.dom.SimpleName) ASTNode(org.eclipse.jdt.core.dom.ASTNode) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit)

Example 65 with SimpleName

use of org.eclipse.jdt.core.dom.SimpleName in project che by eclipse.

the class InlineTempRefactoring method inlineTemp.

private void inlineTemp(CompilationUnitRewrite cuRewrite) throws JavaModelException {
    SimpleName[] references = getReferences();
    TextEditGroup groupDesc = cuRewrite.createGroupDescription(RefactoringCoreMessages.InlineTempRefactoring_inline_edit_name);
    ASTRewrite rewrite = cuRewrite.getASTRewrite();
    for (int i = 0; i < references.length; i++) {
        SimpleName curr = references[i];
        ASTNode initializerCopy = getInitializerSource(cuRewrite, curr);
        rewrite.replace(curr, initializerCopy, groupDesc);
    }
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) ASTNode(org.eclipse.jdt.core.dom.ASTNode) ASTRewrite(org.eclipse.jdt.core.dom.rewrite.ASTRewrite) TextEditGroup(org.eclipse.text.edits.TextEditGroup)

Aggregations

SimpleName (org.eclipse.jdt.core.dom.SimpleName)291 ASTNode (org.eclipse.jdt.core.dom.ASTNode)122 IBinding (org.eclipse.jdt.core.dom.IBinding)70 Expression (org.eclipse.jdt.core.dom.Expression)67 AST (org.eclipse.jdt.core.dom.AST)63 ArrayList (java.util.ArrayList)60 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)57 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)55 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)53 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)47 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)46 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)44 QualifiedName (org.eclipse.jdt.core.dom.QualifiedName)43 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)41 Name (org.eclipse.jdt.core.dom.Name)40 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)35 Type (org.eclipse.jdt.core.dom.Type)35 Block (org.eclipse.jdt.core.dom.Block)34 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)33 Assignment (org.eclipse.jdt.core.dom.Assignment)32