Search in sources :

Example 31 with SimpleName

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

the class SourceProvider method makeNamesUnique.

private void makeNamesUnique(ASTRewrite rewriter, CodeScopeBuilder.Scope scope) {
    Collection<NameData> usedCalleeNames = fAnalyzer.getUsedNames();
    for (Iterator<NameData> iter = usedCalleeNames.iterator(); iter.hasNext(); ) {
        SourceAnalyzer.NameData nd = iter.next();
        if (scope.isInUse(nd.getName())) {
            String newName = scope.createName(nd.getName(), true);
            List<SimpleName> references = nd.references();
            for (Iterator<SimpleName> refs = references.iterator(); refs.hasNext(); ) {
                SimpleName element = refs.next();
                ASTNode newNode = rewriter.createStringPlaceholder(newName, ASTNode.SIMPLE_NAME);
                rewriter.replace(element, newNode, null);
            }
        }
    }
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) ASTNode(org.eclipse.jdt.core.dom.ASTNode) NameData(org.eclipse.jdt.internal.corext.refactoring.code.SourceAnalyzer.NameData) NameData(org.eclipse.jdt.internal.corext.refactoring.code.SourceAnalyzer.NameData)

Example 32 with SimpleName

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

the class TempAssignmentFinder method visit.

@Override
public boolean visit(PostfixExpression postfixExpression) {
    if (postfixExpression.getOperand() == null)
        return true;
    if (!(postfixExpression.getOperand() instanceof SimpleName))
        return true;
    SimpleName simpleName = (SimpleName) postfixExpression.getOperand();
    if (!isNameReferenceToTemp(simpleName))
        return true;
    fFirstAssignment = postfixExpression;
    return false;
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName)

Example 33 with SimpleName

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

the class TempAssignmentFinder method visit.

@Override
public boolean visit(PrefixExpression prefixExpression) {
    if (prefixExpression.getOperand() == null)
        return true;
    if (!(prefixExpression.getOperand() instanceof SimpleName))
        return true;
    if (!prefixExpression.getOperator().equals(Operator.DECREMENT) && !prefixExpression.getOperator().equals(Operator.INCREMENT))
        return true;
    SimpleName simpleName = (SimpleName) prefixExpression.getOperand();
    if (!isNameReferenceToTemp(simpleName))
        return true;
    fFirstAssignment = prefixExpression;
    return false;
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName)

Example 34 with SimpleName

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

the class PromoteTempToFieldRefactoring method addTempRenames.

private void addTempRenames(ASTRewrite rewrite) {
    boolean noNameChange = fFieldName.equals(fTempDeclarationNode.getName().getIdentifier());
    if (fLinkedProposalModel == null && noNameChange) {
        // no changes needed
        return;
    }
    TempOccurrenceAnalyzer analyzer = new TempOccurrenceAnalyzer(fTempDeclarationNode, false);
    analyzer.perform();
    // no javadocs (refactoring not for parameters)
    SimpleName[] tempRefs = analyzer.getReferenceNodes();
    for (int j = 0; j < tempRefs.length; j++) {
        SimpleName occurence = tempRefs[j];
        if (noNameChange) {
            addLinkedName(rewrite, occurence, false);
        } else {
            SimpleName newName = getAST().newSimpleName(fFieldName);
            addLinkedName(rewrite, newName, false);
            rewrite.replace(occurence, newName, null);
        }
    }
}
Also used : TempOccurrenceAnalyzer(org.eclipse.jdt.internal.corext.refactoring.rename.TempOccurrenceAnalyzer) SimpleName(org.eclipse.jdt.core.dom.SimpleName)

Example 35 with SimpleName

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

the class ReorgCorrectionsSubProcessor method getWrongTypeNameProposals.

public static void getWrongTypeNameProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    ICompilationUnit cu = context.getCompilationUnit();
    boolean isLinked = cu.getResource().isLinked();
    IJavaProject javaProject = cu.getJavaProject();
    String sourceLevel = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
    String compliance = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
    CompilationUnit root = context.getASTRoot();
    ASTNode coveredNode = problem.getCoveredNode(root);
    if (!(coveredNode instanceof SimpleName))
        return;
    ASTNode parentType = coveredNode.getParent();
    if (!(parentType instanceof AbstractTypeDeclaration))
        return;
    String currTypeName = ((SimpleName) coveredNode).getIdentifier();
    String newTypeName = JavaCore.removeJavaLikeExtension(cu.getElementName());
    boolean hasOtherPublicTypeBefore = false;
    boolean found = false;
    List<AbstractTypeDeclaration> types = root.types();
    for (int i = 0; i < types.size(); i++) {
        AbstractTypeDeclaration curr = types.get(i);
        if (parentType != curr) {
            if (newTypeName.equals(curr.getName().getIdentifier())) {
                return;
            }
            if (!found && Modifier.isPublic(curr.getModifiers())) {
                hasOtherPublicTypeBefore = true;
            }
        } else {
            found = true;
        }
    }
    if (!JavaConventions.validateJavaTypeName(newTypeName, sourceLevel, compliance).matches(IStatus.ERROR)) {
        proposals.add(new CorrectMainTypeNameProposal(cu, context, currTypeName, newTypeName, IProposalRelevance.RENAME_TYPE));
    }
    if (!hasOtherPublicTypeBefore) {
        String newCUName = JavaModelUtil.getRenamedCUName(cu, currTypeName);
        ICompilationUnit newCU = ((IPackageFragment) (cu.getParent())).getCompilationUnit(newCUName);
        if (!newCU.exists() && !isLinked && !JavaConventions.validateCompilationUnitName(newCUName, sourceLevel, compliance).matches(IStatus.ERROR)) {
            RenameCompilationUnitChange change = new RenameCompilationUnitChange(cu, newCUName);
            // rename CU
            String label = Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_renamecu_description, BasicElementLabels.getResourceName(newCUName));
            proposals.add(new ChangeCorrectionProposal(label, change, IProposalRelevance.RENAME_CU, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_RENAME)));
        }
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) SimpleName(org.eclipse.jdt.core.dom.SimpleName) CorrectMainTypeNameProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.CorrectMainTypeNameProposal) ChangeCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal) RenameCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange) IJavaProject(org.eclipse.jdt.core.IJavaProject) ASTNode(org.eclipse.jdt.core.dom.ASTNode) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

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