org.eclipse.jdt.ui.text.java.IJavaCompletionProposal Java Examples

The following examples show how to use org.eclipse.jdt.ui.text.java.IJavaCompletionProposal. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContractInputProposalsCodeVisitorSupport.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private List<ICompletionProposal> getMethodProposals(final ContentAssistContext contentAssistContext, final JavaContentAssistInvocationContext javaContext,
        final List<ContractInput> inputs, final CharSequence prefix, final String inputName, final String fullyQualifiedType) {
    final List<ICompletionProposal> result = new ArrayList<ICompletionProposal>();
    //COMPLEX input
    if (Map.class.getName().equals(fullyQualifiedType)) {
        final ContractInput complexInput = getInputWithName(inputName, inputs);
        result.addAll(getInputProposals(javaContext, complexInput.getInputs(), prefix));
    }

    methodProposalCreator.setCurrentScope(new VariableScope(null, moduleNode, false));
    final List<IGroovyProposal> allProposals = methodProposalCreator.findAllProposals(new ClassNode(getClassForQualifiedName(fullyQualifiedType)),
            Collections.<ClassNode> emptySet(), prefix.toString(),
            false, false);
    for (final IGroovyProposal p : allProposals) {
        try {
            final IJavaCompletionProposal javaProposal = p.createJavaProposal(contentAssistContext, javaContext);
            result.add(javaProposal);
        }catch (NullPointerException  e) {
            // No CompletionEngine available ?
        }
    }
    return result;
}
 
Example #2
Source File: PatchExtensionMethodCompletionProposal.java    From EasyMPermission with MIT License 6 votes vote down vote up
public static IJavaCompletionProposal[] getJavaCompletionProposals(IJavaCompletionProposal[] javaCompletionProposals,
		CompletionProposalCollector completionProposalCollector) {
	
	List<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>(Arrays.asList(javaCompletionProposals));
	if (canExtendCodeAssist(proposals)) {
		IJavaCompletionProposal firstProposal = proposals.get(0);
		int replacementOffset = getReplacementOffset(firstProposal);
		for (Extension extension : getExtensionMethods(completionProposalCollector)) {
			for (MethodBinding method : extension.extensionMethods) {
				ExtensionMethodCompletionProposal newProposal = new ExtensionMethodCompletionProposal(replacementOffset);
				copyNameLookupAndCompletionEngine(completionProposalCollector, firstProposal, newProposal);
				ASTNode node = getAssistNode(completionProposalCollector);
				newProposal.setMethodBinding(method, node);
				createAndAddJavaCompletionProposal(completionProposalCollector, newProposal, proposals);
			}
		}
	}
	return proposals.toArray(new IJavaCompletionProposal[proposals.size()]);
}
 
Example #3
Source File: DeleteMethodProposal.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static List<IJavaCompletionProposal> createProposalsForProblemOnAsyncType(
    ASTNode problemNode, String extraSyncMethodBindingKey) {
  TypeDeclaration asyncTypeDecl = (TypeDeclaration) ASTResolving.findAncestor(
      problemNode, ASTNode.TYPE_DECLARATION);
  assert (asyncTypeDecl != null);

  IType syncType = RemoteServiceUtilities.findSyncType(asyncTypeDecl);
  if (syncType == null) {
    return null;
  }

  MethodDeclaration extraSyncMethodDecl = JavaASTUtils.findMethodDeclaration(
      syncType.getCompilationUnit(), extraSyncMethodBindingKey);
  if (extraSyncMethodDecl == null) {
    return null;
  }

  return Collections.<IJavaCompletionProposal> singletonList(new DeleteMethodProposal(
      syncType.getCompilationUnit(), extraSyncMethodDecl));
}
 
Example #4
Source File: DeleteMethodProposal.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static List<IJavaCompletionProposal> createProposalsForProblemOnSyncType(
    ASTNode problemNode, String extraAsyncMethodBindingKey) {
  TypeDeclaration syncTypeDecl = (TypeDeclaration) ASTResolving.findAncestor(
      problemNode, ASTNode.TYPE_DECLARATION);
  assert (syncTypeDecl != null);

  IType asyncType = RemoteServiceUtilities.findAsyncType(syncTypeDecl);
  if (asyncType == null) {
    return null;
  }

  MethodDeclaration extraAsyncMethodDecl = JavaASTUtils.findMethodDeclaration(
      asyncType.getCompilationUnit(), extraAsyncMethodBindingKey);
  if (extraAsyncMethodDecl == null) {
    return null;
  }

  return Collections.<IJavaCompletionProposal> singletonList(new DeleteMethodProposal(
      asyncType.getCompilationUnit(), extraAsyncMethodDecl));
}
 
Example #5
Source File: CreateAsyncMethodProposal.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static List<IJavaCompletionProposal> createProposalsForProblemOnAsyncType(
    ICompilationUnit asyncCompilationUnit, ASTNode problemNode,
    String syncMethodBindingKey) {
  TypeDeclaration asyncTypeDecl = (TypeDeclaration) ASTResolving.findAncestor(
      problemNode, ASTNode.TYPE_DECLARATION);
  assert (asyncTypeDecl != null);
  String asyncQualifiedTypeName = asyncTypeDecl.resolveBinding().getQualifiedName();

  // Lookup the sync version of the interface
  IType syncType = RemoteServiceUtilities.findSyncType(asyncTypeDecl);
  if (syncType == null) {
    return Collections.emptyList();
  }

  MethodDeclaration syncMethodDecl = JavaASTUtils.findMethodDeclaration(
      syncType.getCompilationUnit(), syncMethodBindingKey);
  if (syncMethodDecl == null) {
    return Collections.emptyList();
  }

  return Collections.<IJavaCompletionProposal> singletonList(new CreateAsyncMethodProposal(
      asyncCompilationUnit, asyncQualifiedTypeName, syncMethodDecl));
}
 
Example #6
Source File: CreateAsyncMethodProposal.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static List<IJavaCompletionProposal> createProposalsForProblemOnSyncMethod(
    ASTNode problemNode) {
  // Find the problematic sync method declaration and its declaring type
  MethodDeclaration syncMethodDecl = ASTResolving.findParentMethodDeclaration(problemNode);
  TypeDeclaration syncTypeDecl = (TypeDeclaration) ASTResolving.findAncestor(
      syncMethodDecl, ASTNode.TYPE_DECLARATION);
  assert (syncTypeDecl != null);

  // Lookup the async version of the interface
  IType asyncType = RemoteServiceUtilities.findAsyncType(syncTypeDecl);
  if (asyncType == null) {
    return Collections.emptyList();
  }

  return Collections.<IJavaCompletionProposal> singletonList(new CreateAsyncMethodProposal(
      asyncType.getCompilationUnit(), asyncType.getFullyQualifiedName('.'),
      syncMethodDecl));
}
 
Example #7
Source File: AbstractUpdateSignatureProposal.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
protected static List<IJavaCompletionProposal> createProposal(
    RpcPair rpcPair, UpdateSignatureProposalBuilder builder) {

  if (rpcPair == null) {
    return Collections.emptyList();
  }

  // We cannot determine the best method candidate from a static context,
  // so that action is deferred to the non-static getRewrite(). For now we
  // just count the candidates to decide whether we should create a proposal.
  int candidates = candidateCount(rpcPair.dstType,
      rpcPair.srcMethod.getName().getIdentifier());
  if (candidates == 0) {
    return Collections.emptyList();
  }

  // If there's only one candidate method, chances are pretty good that the
  // signature update is the preferred quick-fix. Prioritize this proposal
  // accordingly.
  int relevance = (candidates == 1) ? UNIQUE_RELEVANCE : DEFAULT_RELEVANCE;

  return Collections.<IJavaCompletionProposal> singletonList(builder.createProposal(
      rpcPair, relevance));
}
 
Example #8
Source File: CreateSyncMethodProposal.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static List<IJavaCompletionProposal> createProposalsForProblemOnAsyncMethod(
    ASTNode problemNode) {
  // Find the problematic async method declaration and its declaring type
  MethodDeclaration asyncMethodDecl = ASTResolving.findParentMethodDeclaration(problemNode);
  TypeDeclaration asyncTypeDecl = (TypeDeclaration) ASTResolving.findAncestor(
      asyncMethodDecl, ASTNode.TYPE_DECLARATION);
  assert (asyncTypeDecl != null);

  // Lookup the sync version of the interface
  IType syncType = RemoteServiceUtilities.findSyncType(asyncTypeDecl);
  if (syncType == null) {
    return Collections.emptyList();
  }

  return Collections.<IJavaCompletionProposal> singletonList(new CreateSyncMethodProposal(
      syncType.getCompilationUnit(), syncType.getFullyQualifiedName('.'),
      asyncMethodDecl));
}
 
Example #9
Source File: JsniCompletionProposalCollector.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected IJavaCompletionProposal createJavaCompletionProposal(
    CompletionProposal proposal) {
  IJavaCompletionProposal defaultProposal = super.createJavaCompletionProposal(proposal);

  // For members of inner classes, there's a bug in the JDT which results in
  // the declaration signature of the proposal missing the outer classes, so
  // we have to manually set the signature instead.
  if (proposal.getKind() == CompletionProposal.METHOD_REF
      || proposal.getKind() == CompletionProposal.FIELD_REF) {
    char[] typeSignature = Signature.createTypeSignature(qualifiedTypeName,
        true).toCharArray();
    proposal.setDeclarationSignature(typeSignature);
  }

  return JsniCompletionProposal.create(defaultProposal, proposal,
      getCompilationUnit().getJavaProject(), refOffset, refLength);
}
 
Example #10
Source File: JsniCompletionProcessor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Collects the proposals generated at the end of the specified snippet of
 * Java code, scoped to the specific type.
 */
private IJavaCompletionProposal[] codeComplete(String qualifiedTypeName,
    String snippet, CompletionProposalCollector requestor)
    throws JavaModelException {
  IJavaCompletionProposal[] proposals = new IJavaCompletionProposal[0];

  IType type = cu.getJavaProject().findType(qualifiedTypeName);
  if (type != null) {
    // This can always be false, since the set of available completions
    // (static vs. instance) depends on the JSNI ref itself, not the modifiers
    // on the method in which it is defined.
    boolean isStatic = false;

    // Have the JDT generate completions in the context of the type, but at
    // an unspecified location (source offset -1), since the real position
    // is inside a Java comment block, which is not allowed by codeComplete.
    type.codeComplete(snippet.toCharArray(), -1, snippet.length(),
        new char[0][0], new char[0][0], new int[0], isStatic, requestor);
    proposals = requestor.getJavaCompletionProposals();
  }

  return proposals;
}
 
Example #11
Source File: JsniCompletionProcessor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private IJavaCompletionProposal[] computePackageAndTypeProposals(String js,
    int lineStartOffset, int cursorOffset) throws JavaModelException {
  Matcher matcher = PACKAGE_OR_TYPE_REF_START.matcher(js);
  if (!matcher.find()) {
    // Bail if we're not inside a JSNI Java package/type reference
    return null;
  }

  // Extract from the match the (maybe partial) package/type reference
  int refOffset = matcher.start(1) + lineStartOffset;
  int refLength = cursorOffset - refOffset;
  String partialRef = matcher.group(1);

  CompletionProposalCollector requestor = JsniCompletionProposalCollector.createPackageAndTypeProposalCollector(
      cu, refOffset, refLength);
  IEvaluationContext evalContext = createEvaluationContext();
  evalContext.codeComplete(partialRef, partialRef.length(), requestor);
  return requestor.getJavaCompletionProposals();
}
 
Example #12
Source File: FillArgumentNamesCompletionProposalCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
IJavaCompletionProposal createTypeProposal(CompletionProposal typeProposal) {
	final ICompilationUnit cu= getCompilationUnit();
	if (cu == null || getContext() != null && getContext().isInJavadoc())
		return super.createJavaCompletionProposal(typeProposal);

	IJavaProject project= cu.getJavaProject();
	if (!shouldProposeGenerics(project))
		return super.createJavaCompletionProposal(typeProposal);

	char[] completion= typeProposal.getCompletion();
	// don't add parameters for import-completions nor for proposals with an empty completion (e.g. inside the type argument list)
	if (completion.length > 0 && (completion[completion.length - 1] == ';' || completion[completion.length - 1] == '.'))
		return super.createJavaCompletionProposal(typeProposal);

	LazyJavaCompletionProposal newProposal= new LazyGenericTypeProposal(typeProposal, getInvocationContext());
	return newProposal;
}
 
Example #13
Source File: CreateSyncMethodProposal.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static List<IJavaCompletionProposal> createProposalsForProblemOnSyncType(
    ICompilationUnit syncCompilationUnit, ASTNode problemNode,
    String asyncMethodBindingKey) {
  TypeDeclaration syncTypeDecl = (TypeDeclaration) ASTResolving.findAncestor(
      problemNode, ASTNode.TYPE_DECLARATION);
  assert (syncTypeDecl != null);
  String syncQualifiedTypeName = syncTypeDecl.resolveBinding().getQualifiedName();

  // Lookup the async version of the interface
  IType asyncType = RemoteServiceUtilities.findAsyncType(syncTypeDecl);
  if (asyncType == null) {
    return Collections.emptyList();
  }

  MethodDeclaration asyncMethodDecl = JavaASTUtils.findMethodDeclaration(
      asyncType.getCompilationUnit(), asyncMethodBindingKey);
  if (asyncMethodDecl == null) {
    return Collections.emptyList();
  }

  return Collections.<IJavaCompletionProposal> singletonList(new CreateSyncMethodProposal(
      syncCompilationUnit, syncQualifiedTypeName, asyncMethodDecl));
}
 
Example #14
Source File: JavaTypeCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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);
}
 
Example #15
Source File: QuickFixProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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()]);
}
 
Example #16
Source File: SurroundWithTemplateMenuAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IAction[] getTemplateActions(JavaEditor editor) {
	ITextSelection textSelection= getTextSelection(editor);
	if (textSelection == null || textSelection.getLength() == 0)
		return null;

	ICompilationUnit cu= JavaUI.getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
	if (cu == null)
		return null;

	QuickTemplateProcessor quickTemplateProcessor= new QuickTemplateProcessor();
	IInvocationContext context= new AssistContext(cu, textSelection.getOffset(), textSelection.getLength());

	try {
		IJavaCompletionProposal[] proposals= quickTemplateProcessor.getAssists(context, null);
		if (proposals == null || proposals.length == 0)
			return null;

		return getActionsFromProposals(proposals, context.getSelectionOffset(), editor.getViewer());
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
	return null;
}
 
Example #17
Source File: MarkerResolutionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public Image getImage() {
	if (fResolution instanceof IMarkerResolution2) {
		return ((IMarkerResolution2) fResolution).getImage();
	}
	if (fResolution instanceof IJavaCompletionProposal) {
		return ((IJavaCompletionProposal) fResolution).getImage();
	}
	return JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
}
 
Example #18
Source File: MarkerResolutionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String getAdditionalProposalInfo() {
	if (fResolution instanceof IMarkerResolution2) {
		return ((IMarkerResolution2) fResolution).getDescription();
	}
	if (fResolution instanceof IJavaCompletionProposal) {
		return ((IJavaCompletionProposal) fResolution).getAdditionalProposalInfo();
	}
	try {
		String problemDesc= (String) fMarker.getAttribute(IMarker.MESSAGE);
		return Messages.format(CorrectionMessages.MarkerResolutionProposal_additionaldesc, problemDesc);
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
	return null;
}
 
Example #19
Source File: QuickAssistProcessor1.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IJavaCompletionProposal[] getAssists(IInvocationContext context, IProblemLocation[] locations)
		throws CoreException {
	return new IJavaCompletionProposal[] { new AbstractJavaCompletionProposal() {
		public org.eclipse.jface.viewers.StyledString getStyledDisplayString() {
			ICompilationUnit compilationUnit = context.getCompilationUnit();
			return new StyledString(
					"Generate Getter and setter for " + compilationUnit.findPrimaryType().getElementName());
		}
		
		protected int getPatternMatchRule(String pattern, String string) {
			// override the match rule since we do not work with a pattern, but just want to open the "Generate Getters and Setters..." dialog
			return -1;
		};
		
		public void apply(org.eclipse.jface.text.ITextViewer viewer, char trigger, int stateMask, int offset) {
			
			if(context instanceof AssistContext) {
				AssistContext assistContext = (AssistContext) context;
				AddGetterSetterAction addGetterSetterAction = new AddGetterSetterAction((CompilationUnitEditor)assistContext.getEditor());
				
				addGetterSetterAction.run();
			}
			
		}
	} };
}
 
Example #20
Source File: JavaCorrectionProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static void collectMarkerProposals(SimpleMarkerAnnotation annotation, Collection<IJavaCompletionProposal> proposals) {
	IMarker marker= annotation.getMarker();
	IMarkerResolution[] res= IDE.getMarkerHelpRegistry().getResolutions(marker);
	if (res.length > 0) {
		for (int i= 0; i < res.length; i++) {
			proposals.add(new MarkerResolutionProposal(res[i], marker));
		}
	}
}
 
Example #21
Source File: JavaCorrectionProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext quickAssistContext) {
	ISourceViewer viewer= quickAssistContext.getSourceViewer();
	int documentOffset= quickAssistContext.getOffset();

	IEditorPart part= fAssistant.getEditor();

	ICompilationUnit cu= JavaUI.getWorkingCopyManager().getWorkingCopy(part.getEditorInput());
	IAnnotationModel model= JavaUI.getDocumentProvider().getAnnotationModel(part.getEditorInput());

	AssistContext context= null;
	if (cu != null) {
		int length= viewer != null ? viewer.getSelectedRange().y : 0;
		context= new AssistContext(cu, viewer, part, documentOffset, length);
	}
	
	Annotation[] annotations= fAssistant.getAnnotationsAtOffset();

	fErrorMessage= null;

	ICompletionProposal[] res= null;
	if (model != null && context != null && annotations != null) {
		ArrayList<IJavaCompletionProposal> proposals= new ArrayList<IJavaCompletionProposal>(10);
		IStatus status= collectProposals(context, model, annotations, true, !fAssistant.isUpdatedOffset(), proposals);
		res= proposals.toArray(new ICompletionProposal[proposals.size()]);
		if (!status.isOK()) {
			fErrorMessage= status.getMessage();
			JavaPlugin.log(status);
		}
	}

	if (res == null || res.length == 0) {
		return new ICompletionProposal[] { new ChangeCorrectionProposal(CorrectionMessages.NoCorrectionProposal_description, new NullChange(""), IProposalRelevance.NO_SUGGESSTIONS_AVAILABLE, null) }; //$NON-NLS-1$
	}
	if (res.length > 1) {
		Arrays.sort(res, new CompletionProposalComparator());
	}
	return res;
}
 
Example #22
Source File: PatchExtensionMethodCompletionProposal.java    From EasyMPermission with MIT License 5 votes vote down vote up
private static void copyNameLookupAndCompletionEngine(CompletionProposalCollector completionProposalCollector, IJavaCompletionProposal proposal,
		InternalCompletionProposal newProposal) {
	
	try {
		InternalCompletionContext context = (InternalCompletionContext) Reflection.contextField.get(completionProposalCollector);
		InternalExtendedCompletionContext extendedContext = (InternalExtendedCompletionContext) Reflection.extendedContextField.get(context);
		LookupEnvironment lookupEnvironment = (LookupEnvironment) Reflection.lookupEnvironmentField.get(extendedContext);
		Reflection.nameLookupField.set(newProposal, ((SearchableEnvironment) lookupEnvironment.nameEnvironment).nameLookup);
		Reflection.completionEngineField.set(newProposal, lookupEnvironment.typeRequestor);
	} catch (IllegalAccessException ignore) {
		// ignore
	}
}
 
Example #23
Source File: CorrectionCommandHandler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ICompletionProposal findCorrection(String id, boolean isAssist, ITextSelection selection, ICompilationUnit cu, IAnnotationModel model) {
	AssistContext context= new AssistContext(cu, fEditor.getViewer(), fEditor, selection.getOffset(), selection.getLength());
	Collection<IJavaCompletionProposal> proposals= new ArrayList<IJavaCompletionProposal>(10);
	if (isAssist) {
		if (id.equals(LinkedNamesAssistProposal.ASSIST_ID)) {
			return getLocalRenameProposal(context); // shortcut for local rename
		}
		JavaCorrectionProcessor.collectAssists(context, new ProblemLocation[0], proposals);
	} else {
		try {
			boolean goToClosest= selection.getLength() == 0;
			Annotation[] annotations= getAnnotations(selection.getOffset(), goToClosest);
			JavaCorrectionProcessor.collectProposals(context, model, annotations, true, false, proposals);
		} catch (BadLocationException e) {
			return null;
		}
	}
	for (Iterator<IJavaCompletionProposal> iter= proposals.iterator(); iter.hasNext();) {
		Object curr= iter.next();
		if (curr instanceof ICommandAccess) {
			if (id.equals(((ICommandAccess) curr).getCommandId())) {
				return (ICompletionProposal) curr;
			}
		}
	}
	return null;
}
 
Example #24
Source File: LegacyJavadocCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
	if (context instanceof JavadocContentAssistInvocationContext) {
		JavadocContentAssistInvocationContext javaContext= (JavadocContentAssistInvocationContext) context;

		ICompilationUnit cu= javaContext.getCompilationUnit();
		int offset= javaContext.getInvocationOffset();
		int length= javaContext.getSelectionLength();
		Point selection= javaContext.getViewer().getSelectedRange();
		if (selection.y > 0) {
			offset= selection.x;
			length= selection.y;
		}

		ArrayList<ICompletionProposal> result= new ArrayList<ICompletionProposal>();

		IJavadocCompletionProcessor[] processors= getContributedProcessors();
		for (int i= 0; i < processors.length; i++) {
			IJavadocCompletionProcessor curr= processors[i];
			IJavaCompletionProposal[] proposals= curr.computeCompletionProposals(cu, offset, length, javaContext.getFlags());
			if (proposals != null) {
				for (int k= 0; k < proposals.length; k++) {
					result.add(proposals[k]);
				}
			}
		}
		return result;
	}
	return Collections.emptyList();
}
 
Example #25
Source File: PatchExtensionMethodCompletionProposal.java    From EasyMPermission with MIT License 5 votes vote down vote up
private static void createAndAddJavaCompletionProposal(CompletionProposalCollector completionProposalCollector, CompletionProposal newProposal,
		List<IJavaCompletionProposal> proposals) {
	
	try {
		proposals.add((IJavaCompletionProposal) Reflection.createJavaCompletionProposalMethod.invoke(completionProposalCollector, newProposal));
	} catch (Exception ignore) {
		// ignore
	}
}
 
Example #26
Source File: GetterSetterCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static void evaluateProposals(IType type, String prefix, int offset, int length, int relevance, Set<String> suggestedMethods, Collection<IJavaCompletionProposal> result) throws CoreException {
	if (prefix.length() == 0) {
		relevance--;
	}

	IField[] fields= type.getFields();
	IMethod[] methods= type.getMethods();
	for (int i= 0; i < fields.length; i++) {
		IField curr= fields[i];
		if (!JdtFlags.isEnum(curr)) {
			String getterName= GetterSetterUtil.getGetterName(curr, null);
			if (Strings.startsWithIgnoreCase(getterName, prefix) && !hasMethod(methods, getterName)) {
				suggestedMethods.add(getterName);
				int getterRelevance= relevance;
				if (JdtFlags.isStatic(curr) && JdtFlags.isFinal(curr))
					getterRelevance= relevance - 1;
				result.add(new GetterSetterCompletionProposal(curr, offset, length, true, getterRelevance));
			}

			if (!JdtFlags.isFinal(curr)) {
				String setterName= GetterSetterUtil.getSetterName(curr, null);
				if (Strings.startsWithIgnoreCase(setterName, prefix) && !hasMethod(methods, setterName)) {
					suggestedMethods.add(setterName);
					result.add(new GetterSetterCompletionProposal(curr, offset, length, false, relevance));
				}
			}
		}
	}
}
 
Example #27
Source File: FillArgumentNamesCompletionProposalCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IJavaCompletionProposal createMethodReferenceProposal(CompletionProposal methodProposal) {
	String completion= String.valueOf(methodProposal.getCompletion());
	// super class' behavior if this is not a normal completion or has no
	// parameters
	if ((completion.length() == 0) || ((completion.length() == 1) && completion.charAt(0) == ')') || Signature.getParameterCount(methodProposal.getSignature()) == 0 || getContext().isInJavadoc())
		return super.createJavaCompletionProposal(methodProposal);

	LazyJavaCompletionProposal proposal= null;
	proposal= ParameterGuessingProposal.createProposal(methodProposal, getInvocationContext(), fIsGuessArguments);
	if (proposal == null) {
		proposal= new FilledArgumentNamesMethodProposal(methodProposal, getInvocationContext());
	}
	return proposal;
}
 
Example #28
Source File: FillArgumentNamesCompletionProposalCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected IJavaCompletionProposal createJavaCompletionProposal(CompletionProposal proposal) {
	switch (proposal.getKind()) {
		case CompletionProposal.METHOD_REF:
		case CompletionProposal.CONSTRUCTOR_INVOCATION:
		case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER:
			return createMethodReferenceProposal(proposal);
		case CompletionProposal.TYPE_REF:
			return createTypeProposal(proposal);
		default:
			return super.createJavaCompletionProposal(proposal);
	}
}
 
Example #29
Source File: DeleteMethodProposal.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public static List<IJavaCompletionProposal> createProposalsForProblemOnExtraMethod(
    ASTNode problemNode) {
  MethodDeclaration methodDecl = ASTResolving.findParentMethodDeclaration(problemNode);

  return Collections.<IJavaCompletionProposal> singletonList(new DeleteMethodProposal(
      JavaASTUtils.getCompilationUnit(methodDecl), methodDecl));
}
 
Example #30
Source File: MethodDeclarationCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static void evaluateProposals(IType type, String prefix, int offset, int length, int relevance, Set<String> suggestedMethods, Collection<IJavaCompletionProposal> result) throws CoreException {
	IMethod[] methods= type.getMethods();
	if (!type.isInterface()) {
		String constructorName= type.getElementName();
		if (constructorName.length() > 0 && constructorName.startsWith(prefix) && !hasMethod(methods, constructorName) && suggestedMethods.add(constructorName)) {
			result.add(new MethodDeclarationCompletionProposal(type, constructorName, null, offset, length, relevance + 500));
		}
	}

	if (prefix.length() > 0 && !"main".equals(prefix) && !hasMethod(methods, prefix) && suggestedMethods.add(prefix)) { //$NON-NLS-1$
		if (!JavaConventionsUtil.validateMethodName(prefix, type).matches(IStatus.ERROR))
			result.add(new MethodDeclarationCompletionProposal(type, prefix, Signature.SIG_VOID, offset, length, relevance));
	}
}