use of org.eclipse.jdt.internal.corext.dom.SelectionAnalyzer in project che by eclipse.
the class JavaTextSelection method resolveSelectedNodes.
public ASTNode[] resolveSelectedNodes() {
if (fNodesRequested)
return fSelectedNodes;
fNodesRequested = true;
CompilationUnit root = resolvePartialAstAtOffset();
if (root == null)
return null;
Selection ds = Selection.createFromStartLength(getOffset(), getLength());
SelectionAnalyzer analyzer = new SelectionAnalyzer(ds, false);
root.accept(analyzer);
fSelectedNodes = analyzer.getSelectedNodes();
fCoveringNode = analyzer.getLastCoveringNode();
return fSelectedNodes;
}
use of org.eclipse.jdt.internal.corext.dom.SelectionAnalyzer in project che by eclipse.
the class TypeContextChecker method parseType.
private static Type parseType(String typeString, IJavaProject javaProject, List<String> problemsCollector) {
if (//speed up for a common case //$NON-NLS-1$
"".equals(typeString.trim()))
return null;
if (!typeString.trim().equals(typeString))
return null;
StringBuffer cuBuff = new StringBuffer();
//$NON-NLS-1$
cuBuff.append("interface A{");
int offset = cuBuff.length();
//$NON-NLS-1$
cuBuff.append(typeString).append(" m();}");
ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
p.setSource(cuBuff.toString().toCharArray());
p.setProject(javaProject);
CompilationUnit cu = (CompilationUnit) p.createAST(null);
Selection selection = Selection.createFromStartLength(offset, typeString.length());
SelectionAnalyzer analyzer = new SelectionAnalyzer(selection, false);
cu.accept(analyzer);
ASTNode selected = analyzer.getFirstSelectedNode();
if (!(selected instanceof Type))
return null;
Type type = (Type) selected;
if (MethodTypesSyntaxChecker.isVoidArrayType(type))
return null;
IProblem[] problems = ASTNodes.getProblems(type, ASTNodes.NODE_ONLY, ASTNodes.PROBLEMS);
if (problems.length > 0) {
for (int i = 0; i < problems.length; i++) problemsCollector.add(problems[i].getMessage());
}
String typeNodeRange = cuBuff.substring(type.getStartPosition(), ASTNodes.getExclusiveEnd(type));
if (typeString.equals(typeNodeRange))
return type;
else
return null;
}
use of org.eclipse.jdt.internal.corext.dom.SelectionAnalyzer in project che by eclipse.
the class QuickAssistProcessor method getMakeVariableDeclarationFinalProposals.
private static boolean getMakeVariableDeclarationFinalProposals(IInvocationContext context, Collection<ICommandAccess> resultingCollections) {
SelectionAnalyzer analyzer = new SelectionAnalyzer(Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength()), false);
context.getASTRoot().accept(analyzer);
ASTNode[] selectedNodes = analyzer.getSelectedNodes();
if (selectedNodes.length == 0)
return false;
IProposableFix fix = VariableDeclarationFix.createChangeModifierToFinalFix(context.getASTRoot(), selectedNodes);
if (fix == null)
return false;
if (resultingCollections == null)
return true;
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
Map<String, String> options = new Hashtable<String, String>();
options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL, CleanUpOptions.TRUE);
options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_LOCAL_VARIABLES, CleanUpOptions.TRUE);
options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PARAMETERS, CleanUpOptions.TRUE);
options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PRIVATE_FIELDS, CleanUpOptions.TRUE);
VariableDeclarationCleanUp cleanUp = new VariableDeclarationCleanUp(options);
FixCorrectionProposal proposal = new FixCorrectionProposal(fix, cleanUp, IProposalRelevance.MAKE_VARIABLE_DECLARATION_FINAL, image, context);
resultingCollections.add(proposal);
return true;
}
Aggregations