use of org.eclipse.jdt.ui.text.java.correction.ICommandAccess in project che by eclipse.
the class LocalCorrectionsSubProcessor method addTypePrametersToRawTypeReference.
public static void addTypePrametersToRawTypeReference(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
IProposableFix fix = Java50Fix.createRawTypeReferenceFix(context.getASTRoot(), problem);
if (fix != null) {
for (Iterator<ICommandAccess> iter = proposals.iterator(); iter.hasNext(); ) {
Object element = iter.next();
if (element instanceof FixCorrectionProposal) {
FixCorrectionProposal fixProp = (FixCorrectionProposal) element;
if (RAW_TYPE_REFERENCE_ID.equals(fixProp.getCommandId())) {
return;
}
}
}
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
Map<String, String> options = new Hashtable<String, String>();
options.put(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES, CleanUpOptions.TRUE);
FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new Java50CleanUp(options), IProposalRelevance.RAW_TYPE_REFERENCE, image, context);
proposal.setCommandId(RAW_TYPE_REFERENCE_ID);
proposals.add(proposal);
}
//Infer Generic Type Arguments... proposal
boolean hasInferTypeArgumentsProposal = false;
for (Iterator<ICommandAccess> iterator = proposals.iterator(); iterator.hasNext(); ) {
Object completionProposal = iterator.next();
if (completionProposal instanceof ChangeCorrectionProposal) {
if (IJavaEditorActionDefinitionIds.INFER_TYPE_ARGUMENTS_ACTION.equals(((ChangeCorrectionProposal) completionProposal).getCommandId())) {
hasInferTypeArgumentsProposal = true;
break;
}
}
}
if (!hasInferTypeArgumentsProposal) {
final ICompilationUnit cu = context.getCompilationUnit();
ChangeCorrectionProposal proposal = new ChangeCorrectionProposal(CorrectionMessages.LocalCorrectionsSubProcessor_InferGenericTypeArguments, null, IProposalRelevance.INFER_GENERIC_TYPE_ARGUMENTS, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)) {
@Override
public void apply(IDocument document) {
// action.run(new StructuredSelection(cu));
throw new UnsupportedOperationException();
}
@Override
public String getActionId() {
return "javaInferTypeArguments";
}
/**
* {@inheritDoc}
*/
@Override
public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
return CorrectionMessages.LocalCorrectionsSubProcessor_InferGenericTypeArguments_description;
}
};
proposal.setCommandId(IJavaEditorActionDefinitionIds.INFER_TYPE_ARGUMENTS_ACTION);
proposals.add(proposal);
}
addTypeArgumentsFromContext(context, problem, proposals);
}
use of org.eclipse.jdt.ui.text.java.correction.ICommandAccess in project flux by eclipse.
the class QuickFixProcessor method getCorrections.
/* (non-Javadoc)
* @see IAssistProcessor#getCorrections(org.eclipse.jdt.internal.ui.text.correction.IAssistContext, org.eclipse.jdt.internal.ui.text.correction.IProblemLocation[])
*/
public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
if (locations == null || locations.length == 0) {
return null;
}
HashSet<Integer> handledProblems = new HashSet<Integer>(locations.length);
ArrayList<ICommandAccess> resultingCollections = new ArrayList<ICommandAccess>();
for (int i = 0; i < locations.length; i++) {
IProblemLocation curr = locations[i];
Integer id = new Integer(curr.getProblemId());
if (handledProblems.add(id)) {
process(context, curr, resultingCollections);
}
}
return resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]);
}
use of org.eclipse.jdt.ui.text.java.correction.ICommandAccess in project flux by eclipse.
the class AdvancedQuickAssistProcessor method getAssists.
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.text.correction.IAssistProcessor#getAssists(org.eclipse.jdt.internal.ui.text.correction.IAssistContext, org.eclipse.jdt.internal.ui.text.correction.IProblemLocation[])
*/
public IJavaCompletionProposal[] getAssists(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
ASTNode coveringNode = context.getCoveringNode();
if (coveringNode != null) {
ArrayList<ASTNode> coveredNodes = getFullyCoveredNodes(context, coveringNode);
ArrayList<ICommandAccess> resultingCollections = new ArrayList<ICommandAccess>();
//quick assists that show up also if there is an error/warning
getReplaceConditionalWithIfElseProposals(context, coveringNode, resultingCollections);
if (QuickAssistProcessor.noErrorsAtLocation(locations)) {
getConvertToIfReturnProposals(context, coveringNode, resultingCollections);
getInverseIfProposals(context, coveringNode, resultingCollections);
getIfReturnIntoIfElseAtEndOfVoidMethodProposals(context, coveringNode, resultingCollections);
getInverseIfContinueIntoIfThenInLoopsProposals(context, coveringNode, resultingCollections);
getInverseIfIntoContinueInLoopsProposals(context, coveringNode, resultingCollections);
getInverseConditionProposals(context, coveringNode, coveredNodes, resultingCollections);
getRemoveExtraParenthesesProposals(context, coveringNode, coveredNodes, resultingCollections);
getAddParanoidalParenthesesProposals(context, coveredNodes, resultingCollections);
getAddParenthesesForExpressionProposals(context, coveringNode, resultingCollections);
getJoinAndIfStatementsProposals(context, coveringNode, resultingCollections);
getSplitAndConditionProposals(context, coveringNode, resultingCollections);
getJoinOrIfStatementsProposals(context, coveringNode, coveredNodes, resultingCollections);
getSplitOrConditionProposals(context, coveringNode, resultingCollections);
getInverseConditionalExpressionProposals(context, coveringNode, resultingCollections);
getExchangeInnerAndOuterIfConditionsProposals(context, coveringNode, resultingCollections);
getExchangeOperandsProposals(context, coveringNode, resultingCollections);
getCastAndAssignIfStatementProposals(context, coveringNode, resultingCollections);
getCombineStringProposals(context, coveringNode, resultingCollections);
getPickOutStringProposals(context, coveringNode, resultingCollections);
getReplaceIfElseWithConditionalProposals(context, coveringNode, resultingCollections);
getInverseLocalVariableProposals(context, coveringNode, resultingCollections);
getPushNegationDownProposals(context, coveringNode, resultingCollections);
getPullNegationUpProposals(context, coveredNodes, resultingCollections);
getJoinIfListInIfElseIfProposals(context, coveringNode, coveredNodes, resultingCollections);
getConvertSwitchToIfProposals(context, coveringNode, resultingCollections);
getConvertIfElseToSwitchProposals(context, coveringNode, resultingCollections);
// GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, coveringNode, locations, resultingCollections);
}
return resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]);
}
return null;
}
use of org.eclipse.jdt.ui.text.java.correction.ICommandAccess in project flux by eclipse.
the class QuickAssistProcessor method getSplitVariableProposals.
private static boolean getSplitVariableProposals(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) {
VariableDeclarationFragment fragment;
if (node instanceof VariableDeclarationFragment) {
fragment = (VariableDeclarationFragment) node;
} else if (node.getLocationInParent() == VariableDeclarationFragment.NAME_PROPERTY) {
fragment = (VariableDeclarationFragment) node.getParent();
} else {
return false;
}
if (fragment.getInitializer() == null) {
return false;
}
Statement statement;
ASTNode fragParent = fragment.getParent();
if (fragParent instanceof VariableDeclarationStatement) {
statement = (VariableDeclarationStatement) fragParent;
} else if (fragParent instanceof VariableDeclarationExpression) {
if (fragParent.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) {
return false;
}
statement = (Statement) fragParent.getParent();
} else {
return false;
}
// statement is ForStatement or VariableDeclarationStatement
ASTNode statementParent = statement.getParent();
StructuralPropertyDescriptor property = statement.getLocationInParent();
if (!property.isChildListProperty()) {
return false;
}
List<? extends ASTNode> list = ASTNodes.getChildListProperty(statementParent, (ChildListPropertyDescriptor) property);
if (resultingCollections == null) {
return true;
}
AST ast = statement.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
String label = CorrectionMessages.QuickAssistProcessor_splitdeclaration_description;
// Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_LOCAL);
ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.SPLIT_VARIABLE_DECLARATION);
boolean commandConflict = false;
for (Iterator<ICommandAccess> iterator = resultingCollections.iterator(); iterator.hasNext(); ) {
Object completionProposal = iterator.next();
if (completionProposal instanceof ChangeCorrectionProposal) {
if (SPLIT_JOIN_VARIABLE_DECLARATION_ID.equals(((ChangeCorrectionProposal) completionProposal).getCommandId())) {
commandConflict = true;
}
}
}
if (!commandConflict) {
proposal.setCommandId(SPLIT_JOIN_VARIABLE_DECLARATION_ID);
}
Statement newStatement;
int insertIndex = list.indexOf(statement);
Expression placeholder = (Expression) rewrite.createMoveTarget(fragment.getInitializer());
ITypeBinding binding = fragment.getInitializer().resolveTypeBinding();
if (placeholder instanceof ArrayInitializer && binding != null && binding.isArray()) {
ArrayCreation creation = ast.newArrayCreation();
creation.setInitializer((ArrayInitializer) placeholder);
final ITypeBinding componentType = binding.getElementType();
Type type = null;
if (componentType.isPrimitive())
type = ast.newPrimitiveType(PrimitiveType.toCode(componentType.getName()));
else
type = ast.newSimpleType(ast.newSimpleName(componentType.getName()));
creation.setType(ast.newArrayType(type, binding.getDimensions()));
placeholder = creation;
}
Assignment assignment = ast.newAssignment();
assignment.setRightHandSide(placeholder);
assignment.setLeftHandSide(ast.newSimpleName(fragment.getName().getIdentifier()));
if (statement instanceof VariableDeclarationStatement) {
newStatement = ast.newExpressionStatement(assignment);
// add after declaration
insertIndex += 1;
} else {
rewrite.replace(fragment.getParent(), assignment, null);
VariableDeclarationFragment newFrag = ast.newVariableDeclarationFragment();
newFrag.setName(ast.newSimpleName(fragment.getName().getIdentifier()));
newFrag.extraDimensions().addAll(DimensionRewrite.copyDimensions(fragment.extraDimensions(), rewrite));
VariableDeclarationExpression oldVarDecl = (VariableDeclarationExpression) fragParent;
VariableDeclarationStatement newVarDec = ast.newVariableDeclarationStatement(newFrag);
newVarDec.setType((Type) rewrite.createCopyTarget(oldVarDecl.getType()));
newVarDec.modifiers().addAll(ASTNodeFactory.newModifiers(ast, oldVarDecl.getModifiers()));
newStatement = newVarDec;
}
ListRewrite listRewriter = rewrite.getListRewrite(statementParent, (ChildListPropertyDescriptor) property);
listRewriter.insertAt(newStatement, insertIndex, null);
resultingCollections.add(proposal);
return true;
}
Aggregations