use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project lombok by rzwitserloot.
the class PatchExtensionMethodCompletionProposal method getJavaCompletionProposals.
public static IJavaCompletionProposal[] getJavaCompletionProposals(IJavaCompletionProposal[] javaCompletionProposals, CompletionProposalCollector completionProposalCollector) {
List<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>(Arrays.asList(javaCompletionProposals));
if (canExtendCodeAssist()) {
for (Extension extension : getExtensionMethods(completionProposalCollector)) {
for (MethodBinding method : extension.extensionMethods) {
if (!isMatchingProposal(method, completionProposalCollector)) {
continue;
}
ExtensionMethodCompletionProposal newProposal = new ExtensionMethodCompletionProposal(0);
copyNameLookupAndCompletionEngine(completionProposalCollector, newProposal);
ASTNode node = getAssistNode(completionProposalCollector);
newProposal.setMethodBinding(method, node);
createAndAddJavaCompletionProposal(completionProposalCollector, newProposal, proposals);
}
}
}
return proposals.toArray(new IJavaCompletionProposal[0]);
}
use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project jbosstools-base by jbosstools.
the class MarkerAnnotationInfo method getProposals.
private List<ICompletionProposal> getProposals(TemporaryAnnotation annotation, Position position) {
List<ICompletionProposal> allProposals = new ArrayList<ICompletionProposal>();
List<IQuickAssistProcessor> processors = new ArrayList<IQuickAssistProcessor>();
boolean isJBTAnnotation = isJBTAnnotation(annotation);
// get all relevant quick fixes for this annotation
if (QuickFixManager.getInstance().hasProposals(annotation, position)) {
if (annotation.getText().startsWith(UNKNOWN_TAG) || annotation.getText().startsWith(MISSING_ATTRIBUTE)) {
annotation.setAdditionalFixInfo(viewer.getDocument());
}
List<IJavaCompletionProposal> proposals = QuickFixManager.getInstance().getProposals(annotation, position);
allProposals.addAll(proposals);
}
if (!isJBTAnnotation) {
Object o = annotation.getAdditionalFixInfo();
if (o instanceof IQuickAssistProcessor) {
processors.add((IQuickAssistProcessor) o);
}
QuickFixRegistry registry = QuickFixRegistry.getInstance();
processors.addAll(Arrays.asList(registry.getQuickFixProcessors(annotation)));
// set up context
Map attributes = annotation.getAttributes();
StructuredTextInvocationContext sseContext = new StructuredTextInvocationContext(viewer, position.getOffset(), position.getLength(), attributes);
ICompletionProposal[] compoundQuickAssistProcessorProposals = fCompoundQuickAssistProcessor.computeQuickAssistProposals(sseContext);
if (compoundQuickAssistProcessorProposals != null) {
for (ICompletionProposal proposal : compoundQuickAssistProcessorProposals) {
allProposals.add(proposal);
}
}
// call each processor
for (int i = 0; i < processors.size(); ++i) {
List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
collectProposals((IQuickAssistProcessor) processors.get(i), annotation, sseContext, proposals);
allProposals.addAll(proposals);
}
}
return allProposals;
}
use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project gap-eclipse-plugins by gayanper.
the class StringFormatAsistProcessor method createProposalForStringFormat.
private IJavaCompletionProposal[] createProposalForStringFormat(IInvocationContext context, AST ast, InfixExpression oldInfixExpression) {
final ICompilationUnit cu = context.getCompilationUnit();
final ASTRewrite rewrite = ASTRewrite.create(ast);
List<Expression> operands = new ArrayList<>();
collectInfixPlusOperands(oldInfixExpression, operands);
List<Expression> formatArguments = new ArrayList<>();
StringBuilder formatString = new StringBuilder();
for (Iterator<Expression> iterator = operands.iterator(); iterator.hasNext(); ) {
Expression operand = iterator.next();
if (operand instanceof StringLiteral) {
String value = ((StringLiteral) operand).getEscapedValue();
value = value.substring(1, value.length() - 1);
value = value.replaceAll("'", "''");
formatString.append(value);
} else {
formatString.append("%s");
formatArguments.add((Expression) rewrite.createCopyTarget(operand));
}
}
if (formatArguments.size() == 0) {
return null;
}
ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal("Use 'String.format' for string concatenation", cu, rewrite, 0, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE));
proposal.setCommandId(CONVERT_TO_STRING_FORMAT_ID);
MethodInvocation formatInvocation = ast.newMethodInvocation();
formatInvocation.setExpression(ast.newSimpleName("String"));
formatInvocation.setName(ast.newSimpleName("format"));
@SuppressWarnings("unchecked") List<Expression> arguments = formatInvocation.arguments();
StringLiteral formatStringArgument = ast.newStringLiteral();
// $NON-NLS-1$ //$NON-NLS-2$
formatStringArgument.setEscapedValue("\"" + formatString + "\"");
arguments.add(formatStringArgument);
for (Iterator<Expression> iterator = formatArguments.iterator(); iterator.hasNext(); ) {
arguments.add(iterator.next());
}
rewrite.replace(oldInfixExpression, formatInvocation, null);
return new IJavaCompletionProposal[] { proposal };
}
use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project grails-ide by spring-attic.
the class BeansJavaCompletionUtils method addClassValueProposals.
/**
* Add class and package content assist proposals that match the given
* <code>prefix</code>.
*/
public static void addClassValueProposals(IContentAssistContext context, IContentAssistProposalRecorder recorder, int flags) {
String prefix = context.getMatchString();
if (prefix == null || prefix.length() == 0) {
return;
}
try {
ICompilationUnit unit = createSourceCompilationUnit(context.getFile(), prefix);
char enclosingChar = (prefix.lastIndexOf('$') > 0 ? '$' : '.');
prefix = prefix.replace('$', '.');
// we manually add the private inner classes if possible
if (prefix.lastIndexOf('.') > 0) {
String rootClass = prefix.substring(0, prefix.lastIndexOf('.'));
IType type = JdtUtils.getJavaType(context.getFile().getProject(), rootClass);
if (type != null) {
for (IType innerType : type.getTypes()) {
if (Flags.isPrivate(innerType.getFlags()) && innerType.getFullyQualifiedName('.').startsWith(prefix)) {
recorder.recordProposal(JAVA_LABEL_PROVIDER.getImage(innerType), 10, JAVA_LABEL_PROVIDER.getText(innerType), innerType.getFullyQualifiedName(enclosingChar), innerType);
}
}
}
}
String sourceStart = CLASS_SOURCE_START + prefix;
String packageName = null;
int dot = prefix.lastIndexOf('.');
if (dot > -1) {
packageName = prefix.substring(0, dot);
sourceStart = "package " + packageName + ";\n" + sourceStart;
}
String source = sourceStart + CLASS_SOURCE_END;
setContents(unit, source);
BeansJavaCompletionProposalCollector collector = new BeansJavaCompletionProposalCollector(unit, flags);
unit.codeComplete(sourceStart.length(), collector, DefaultWorkingCopyOwner.PRIMARY);
IJavaCompletionProposal[] props = collector.getJavaCompletionProposals();
ICompletionProposal[] proposals = order(props);
for (ICompletionProposal comProposal : proposals) {
processJavaCompletionProposal(recorder, comProposal, packageName, enclosingChar);
}
} catch (Exception e) {
// do nothing
}
}
use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project che by eclipse.
the class JavaTypeCompletionProposalComputer method createTypeProposal.
private IJavaCompletionProposal createTypeProposal(int relevance, String fullyQualifiedType, JavaContentAssistInvocationContext context) throws JavaModelException {
IType type = context.getCompilationUnit().getJavaProject().findType(fullyQualifiedType);
if (type == null)
return null;
CompletionProposal proposal = CompletionProposal.create(CompletionProposal.TYPE_REF, context.getInvocationOffset());
proposal.setCompletion(fullyQualifiedType.toCharArray());
proposal.setDeclarationSignature(type.getPackageFragment().getElementName().toCharArray());
proposal.setFlags(type.getFlags());
proposal.setRelevance(relevance);
proposal.setReplaceRange(context.getInvocationOffset(), context.getInvocationOffset());
proposal.setSignature(Signature.createTypeSignature(fullyQualifiedType, true).toCharArray());
if (shouldProposeGenerics(context.getProject()))
return new LazyGenericTypeProposal(proposal, context);
else
return new LazyJavaTypeCompletionProposal(proposal, context);
}
Aggregations