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);
}
}
}
}
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;
}
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;
}
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);
}
}
}
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)));
}
}
}
Aggregations