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

The following examples show how to use org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext. 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: JavaCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a new completion proposal. All fields are initialized based on the provided
 * information.
 *
 * @param replacementString the actual string to be inserted into the document
 * @param replacementOffset the offset of the text to be replaced
 * @param replacementLength the length of the text to be replaced
 * @param image the image to display for this proposal
 * @param displayString the string to be displayed for the proposal If set to <code>null</code>,
 *        the replacement string will be taken as display string.
 * @param relevance the relevance
 * @param inJavadoc <code>true</code> for a javadoc proposal
 * @param invocationContext the invocation context of this completion proposal or <code>null</code> not available
 */
public JavaCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, StyledString displayString, int relevance, boolean inJavadoc, JavaContentAssistInvocationContext invocationContext) {
	super(invocationContext);
	Assert.isNotNull(replacementString);
	Assert.isTrue(replacementOffset >= 0);
	Assert.isTrue(replacementLength >= 0);

	setReplacementString(replacementString);
	setReplacementOffset(replacementOffset);
	setReplacementLength(replacementLength);
	setImage(image);
	setStyledDisplayString(displayString == null ? new StyledString(replacementString) : displayString);
	setRelevance(relevance);
	setCursorPosition(replacementString.length());
	setInJavadoc(inJavadoc);
	setSortString(displayString == null ? replacementString : displayString.getString());
}
 
Example #2
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 #3
Source File: JavaCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private List<IContextInformation> addContextInformations(JavaContentAssistInvocationContext context, int offset) {
	List<ICompletionProposal> proposals= internalComputeCompletionProposals(offset, context);
	List<IContextInformation> result= new ArrayList<IContextInformation>(proposals.size());
	List<IContextInformation> anonymousResult= new ArrayList<IContextInformation>(proposals.size());

	for (Iterator<ICompletionProposal> it= proposals.iterator(); it.hasNext();) {
		ICompletionProposal proposal= it.next();
		IContextInformation contextInformation= proposal.getContextInformation();
		if (contextInformation != null) {
			ContextInformationWrapper wrapper= new ContextInformationWrapper(contextInformation);
			wrapper.setContextInformationPosition(offset);
			if (proposal instanceof AnonymousTypeCompletionProposal)
				anonymousResult.add(wrapper);
			else
				result.add(wrapper);
		}
	}

	if (result.size() == 0)
		return anonymousResult;
	return result;

}
 
Example #4
Source File: SWTTemplateCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected TemplateEngine computeCompletionEngine(JavaContentAssistInvocationContext context) {
	ICompilationUnit unit= context.getCompilationUnit();
	if (unit == null)
		return null;

	IJavaProject javaProject= unit.getJavaProject();
	if (javaProject == null)
		return null;

	if (isSWTOnClasspath(javaProject)) {
		CompletionContext coreContext= context.getCoreContext();
		if (coreContext != null) {
			int tokenLocation= coreContext.getTokenLocation();
			if ((tokenLocation & CompletionContext.TL_MEMBER_START) != 0) {
				return fSWTMembersTemplateEngine;
			}
			if ((tokenLocation & CompletionContext.TL_STATEMENT_START) != 0) {
				return fSWTStatementsTemplateEngine;
			}
		}
		return fSWTTemplateEngine;
	}

	return null;
}
 
Example #5
Source File: JavaAllCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected CompletionProposalCollector createCollector(JavaContentAssistInvocationContext context) {
	CompletionProposalCollector collector= super.createCollector(context);
	collector.setIgnored(CompletionProposal.ANNOTATION_ATTRIBUTE_REF, false);
	collector.setIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, false);
	collector.setIgnored(CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION, false);
	collector.setIgnored(CompletionProposal.FIELD_REF, false);
	collector.setIgnored(CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER, false);
	collector.setIgnored(CompletionProposal.KEYWORD, false);
	collector.setIgnored(CompletionProposal.LABEL_REF, false);
	collector.setIgnored(CompletionProposal.LOCAL_VARIABLE_REF, false);
	collector.setIgnored(CompletionProposal.METHOD_DECLARATION, false);
	collector.setIgnored(CompletionProposal.METHOD_NAME_REFERENCE, false);
	collector.setIgnored(CompletionProposal.METHOD_REF, false);
	collector.setIgnored(CompletionProposal.CONSTRUCTOR_INVOCATION, false);
	collector.setIgnored(CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER, false);
	collector.setIgnored(CompletionProposal.PACKAGE_REF, false);
	collector.setIgnored(CompletionProposal.POTENTIAL_METHOD_DECLARATION, false);
	collector.setIgnored(CompletionProposal.VARIABLE_DECLARATION, false);
	collector.setIgnored(CompletionProposal.TYPE_REF, false);
	return collector;
}
 
Example #6
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 #7
Source File: JavaNoTypeCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected CompletionProposalCollector createCollector(JavaContentAssistInvocationContext context) {
	CompletionProposalCollector collector= super.createCollector(context);
	collector.setIgnored(CompletionProposal.ANNOTATION_ATTRIBUTE_REF, false);
	collector.setIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, false);
	collector.setIgnored(CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION, false);
	collector.setIgnored(CompletionProposal.FIELD_REF, false);
	collector.setIgnored(CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER, false);
	collector.setIgnored(CompletionProposal.KEYWORD, false);
	collector.setIgnored(CompletionProposal.LABEL_REF, false);
	collector.setIgnored(CompletionProposal.LOCAL_VARIABLE_REF, false);
	collector.setIgnored(CompletionProposal.METHOD_DECLARATION, false);
	collector.setIgnored(CompletionProposal.METHOD_NAME_REFERENCE, false);
	collector.setIgnored(CompletionProposal.METHOD_REF, false);
	collector.setIgnored(CompletionProposal.CONSTRUCTOR_INVOCATION, false);
	collector.setIgnored(CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER, false);
	collector.setIgnored(CompletionProposal.PACKAGE_REF, false);
	collector.setIgnored(CompletionProposal.POTENTIAL_METHOD_DECLARATION, false);
	collector.setIgnored(CompletionProposal.VARIABLE_DECLARATION, false);
	return collector;
}
 
Example #8
Source File: TemplateCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected TemplateEngine computeCompletionEngine(JavaContentAssistInvocationContext context) {
	try {
		String partition= TextUtilities.getContentType(context.getDocument(), IJavaPartitions.JAVA_PARTITIONING, context.getInvocationOffset(), true);
		if (partition.equals(IJavaPartitions.JAVA_DOC))
			return fJavadocTemplateEngine;
		else {
			CompletionContext coreContext= context.getCoreContext();
			if (coreContext != null) {
				int tokenLocation= coreContext.getTokenLocation();
				if ((tokenLocation & CompletionContext.TL_MEMBER_START) != 0) {
					return fJavaMembersTemplateEngine;
				}
				if ((tokenLocation & CompletionContext.TL_STATEMENT_START) != 0) {
					return fJavaStatementsTemplateEngine;
				}
			}
			return fJavaTemplateEngine;
		}
	} catch (BadLocationException x) {
		return null;
	}
}
 
Example #9
Source File: JavaCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates the collector used to get proposals from core.
 *
 * @param context the context
 * @return the collector
 */
protected CompletionProposalCollector createCollector(JavaContentAssistInvocationContext context) {
	if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES))
		return new FillArgumentNamesCompletionProposalCollector(context);
	else
		return new CompletionProposalCollector(context.getCompilationUnit(), true);
}
 
Example #10
Source File: JsniMethodBodyCompletionProposalComputerTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 *  If length of line at 'lineNum' is 'len', then validate all proposals for invocation
 *  index varying from '(len - numCharsCompleted)' to 'len'.
 */
private static void validateExpectedProposals(IJavaProject javaProject,
    String fullyQualifiedClassName, String source, int lineNum, int numCharsCompleted,
    String... expectedProposals) throws CoreException, BadLocationException {
  IProgressMonitor monitor = new NullProgressMonitor();

  ICompilationUnit iCompilationUnit = JavaProjectUtilities.createCompilationUnit(
      javaProject, fullyQualifiedClassName, source);
  CompilationUnitEditor cuEditor = (CompilationUnitEditor) JavaUI.openInEditor(iCompilationUnit);

  ISourceViewer viewer = cuEditor.getViewer();
  IDocument document = viewer.getDocument();

  IRegion lineInformation = document.getLineInformation(lineNum);
  JsniMethodBodyCompletionProposalComputer jcpc = new JsniMethodBodyCompletionProposalComputer();

  for (int numCharsToOverwrite = 0; numCharsToOverwrite <= numCharsCompleted;
      numCharsToOverwrite++){
    int invocationOffset = lineInformation.getOffset()
        + lineInformation.getLength() - numCharsToOverwrite;
    JavaContentAssistInvocationContext context = new JavaContentAssistInvocationContext(
        viewer, invocationOffset, cuEditor);
    List<ICompletionProposal> completions = jcpc.computeCompletionProposals(
        context, monitor);

    int indentationUnits = JsniMethodBodyCompletionProposalComputer.measureIndentationUnits(
        document, lineNum, lineInformation.getOffset(), javaProject);
    List<String> expected = createJsniBlocks(javaProject, indentationUnits,
        expectedProposals);
    for (int i = 0; i < expected.size(); i++){
      String expectedBlock = expected.get(i).substring(numCharsCompleted - numCharsToOverwrite);
      expected.set(i, expectedBlock);
    }
    assertExpectedProposals(expected, completions, numCharsToOverwrite);
  }
}
 
Example #11
Source File: JavaMethodCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected LazyJavaCompletionProposal createRequiredTypeCompletionProposal(CompletionProposal completionProposal, JavaContentAssistInvocationContext invocationContext) {
	LazyJavaCompletionProposal requiredProposal= super.createRequiredTypeCompletionProposal(completionProposal, invocationContext);
	if (fProposal.getKind() == CompletionProposal.CONSTRUCTOR_INVOCATION && requiredProposal instanceof LazyGenericTypeProposal)
		((LazyGenericTypeProposal) requiredProposal).canUseDiamond(fProposal.canUseDiamond(fInvocationContext.getCoreContext()));
	return requiredProposal;
}
 
Example #12
Source File: FillArgumentNamesCompletionProposalCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public FillArgumentNamesCompletionProposalCollector(JavaContentAssistInvocationContext context) {
	super(context.getCompilationUnit(), true);
	setInvocationContext(context);
	IPreferenceStore preferenceStore= JavaPlugin.getDefault().getPreferenceStore();
	fIsGuessArguments= preferenceStore.getBoolean(PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS);
	if (preferenceStore.getBoolean(PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES)) {
		setRequireExtendedContext(true);
	}
}
 
Example #13
Source File: AnonymousTypeCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public AnonymousTypeCompletionProposal(IJavaProject jproject, ICompilationUnit cu, JavaContentAssistInvocationContext invocationContext, int start, int length, String constructorCompletion, StyledString displayName, String declarationSignature, IType superType, int relevance) {
	super(constructorCompletion, cu, start, length, null, displayName, relevance, null, invocationContext);
	Assert.isNotNull(declarationSignature);
	Assert.isNotNull(jproject);
	Assert.isNotNull(cu);
	Assert.isNotNull(superType);

	fDeclarationSignature= declarationSignature;
	fSuperType= superType;

	setImage(getImageForType(fSuperType));
	setCursorPosition(constructorCompletion.indexOf('(') + 1);
}
 
Example #14
Source File: AnonymousTypeCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected LazyJavaCompletionProposal createRequiredTypeCompletionProposal(CompletionProposal completionProposal, JavaContentAssistInvocationContext invocationContext) {
	LazyJavaCompletionProposal proposal= super.createRequiredTypeCompletionProposal(completionProposal, invocationContext);
	if (proposal instanceof LazyJavaTypeCompletionProposal)
		((LazyJavaTypeCompletionProposal)proposal).setImportRewrite(fImportRewrite);
	return proposal;
}
 
Example #15
Source File: LegacyJavadocCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
	if (context instanceof JavaContentAssistInvocationContext) {
		JavaContentAssistInvocationContext javaContext= (JavaContentAssistInvocationContext) context;

		ICompilationUnit cu= javaContext.getCompilationUnit();
		int offset= javaContext.getInvocationOffset();

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

		IJavadocCompletionProcessor[] processors= getContributedProcessors();
		String error= null;
		for (int i= 0; i < processors.length; i++) {
			IJavadocCompletionProcessor curr= processors[i];
			IContextInformation[] contextInfos= curr.computeContextInformation(cu, offset);
			if (contextInfos != null) {
				for (int k= 0; k < contextInfos.length; k++) {
					result.add(contextInfos[k]);
				}
			} else if (error == null) {
				error= curr.getErrorMessage();
			}
		}
		fErrorMessage= error;
		return result;
	}
	return Collections.emptyList();
}
 
Example #16
Source File: JavadocCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected CompletionProposalCollector createCollector(JavaContentAssistInvocationContext context) {
	CompletionProposalCollector collector= super.createCollector(context);
	collector.setIgnored(CompletionProposal.JAVADOC_TYPE_REF, false);
	collector.setIgnored(CompletionProposal.JAVADOC_FIELD_REF, false);
	collector.setIgnored(CompletionProposal.JAVADOC_METHOD_REF, false);
	collector.setIgnored(CompletionProposal.JAVADOC_PARAM_REF, false);
	collector.setIgnored(CompletionProposal.JAVADOC_VALUE_REF, false);
	collector.setIgnored(CompletionProposal.JAVADOC_BLOCK_TAG, false);
	collector.setIgnored(CompletionProposal.JAVADOC_INLINE_TAG, false);
	collector.setIgnored(CompletionProposal.TYPE_REF, false);
	collector.setIgnored(CompletionProposal.FIELD_REF, false);
	collector.setIgnored(CompletionProposal.METHOD_REF, false);
	return collector;
}
 
Example #17
Source File: JFaceCompletionProposalComputer.java    From saneclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected TemplateEngine computeCompletionEngine(JavaContentAssistInvocationContext context) {
	final ICompilationUnit unit = context.getCompilationUnit();
	if (unit == null) {
		return null;
	}

	final IJavaProject javaProject = unit.getJavaProject();
	if (javaProject == null) {
		return null;
	}

	if (isJFaceOnClasspath(javaProject)) {
		final CompletionContext coreContext = context.getCoreContext();
		if (coreContext != null) {
			final int tokenLocation = coreContext.getTokenLocation();
			if ((tokenLocation & CompletionContext.TL_MEMBER_START) != 0) {
				return jFaceMembersTemplateEngine;
			}
			if ((tokenLocation & CompletionContext.TL_STATEMENT_START) != 0) {
				return jFaceStatementsTemplateEngine;
			}
		}
		return jFaceTemplateEngine;
	}

	return null;
}
 
Example #18
Source File: GenericProposalFilter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<IGroovyProposal> filterProposals(List<IGroovyProposal> proposals, ContentAssistContext contentAssistContext,
        JavaContentAssistInvocationContext invovationContext) {
    if (invovationContext instanceof ExtendedJavaContentAssistInvocationContext) {
        filterProposals(proposals);
    }
    return proposals;
}
 
Example #19
Source File: CodeVisitorSupportContext.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public CodeVisitorSupportContext(final String prefix,
        final JavaContentAssistInvocationContext context,
        final ContentAssistContext contentAssistContext,
        final ClassLoader classLoader,
        final IJavaCompletionProposalComputer completionComputer,
        final MethodProposalCreator methodProposalCreator,
        final ModuleNode moduleNode) {
    this.prefix = prefix;
    this.context = context;
    this.contentAssistContext = contentAssistContext;
    this.classLoader = classLoader;
    this.completionComputer = completionComputer;
    this.methodProposalCreator = methodProposalCreator;
    this.moduleNode = moduleNode;
}
 
Example #20
Source File: JavaCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
	if (context instanceof JavaContentAssistInvocationContext) {
		JavaContentAssistInvocationContext javaContext= (JavaContentAssistInvocationContext) context;

		int contextInformationPosition= guessContextInformationPosition(javaContext);
		List<IContextInformation> result= addContextInformations(javaContext, contextInformationPosition);
		return result;
	}
	return Collections.emptyList();
}
 
Example #21
Source File: JavaCompletionProposalComputer.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 JavaContentAssistInvocationContext) {
		JavaContentAssistInvocationContext javaContext= (JavaContentAssistInvocationContext) context;
		return internalComputeCompletionProposals(context.getInvocationOffset(), javaContext);
	}
	return Collections.emptyList();
}
 
Example #22
Source File: JsniMethodBodyCompletionProposalComputerTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static void assertNoProposals(IProgressMonitor monitor,
    JsniMethodBodyCompletionProposalComputer jcpc,
    CompilationUnitEditor cuEditor, ISourceViewer viewer, int offset) {
  assertEquals(0, jcpc.computeCompletionProposals(
      new JavaContentAssistInvocationContext(viewer, offset, cuEditor),
      monitor).size());
}
 
Example #23
Source File: LazyJavaCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public LazyJavaCompletionProposal(CompletionProposal proposal, JavaContentAssistInvocationContext context) {
	super(context);
	Assert.isNotNull(proposal);
	Assert.isNotNull(context);
	Assert.isNotNull(context.getCoreContext());
	fProposal= proposal;
}
 
Example #24
Source File: CodeVisitorSupportContext.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public JavaContentAssistInvocationContext getContext() {
    return context;
}
 
Example #25
Source File: ContractInputCompletionProposalComputer.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public List<ICompletionProposal> computeCompletionProposals(final ContentAssistInvocationContext context,
        final IProgressMonitor monitor) {
    if (!(context instanceof JavaContentAssistInvocationContext)
            || context instanceof JavaContentAssistInvocationContext
                    && !(((JavaContentAssistInvocationContext) context)
                            .getCompilationUnit() instanceof GroovyCompilationUnit)) {
        return Collections.emptyList();
    }
    final List<ContractInput> inputs = getContractInputs(context);
    if (inputs.isEmpty()) {
        return Collections.emptyList();
    }
    final JavaContentAssistInvocationContext javaContext = (JavaContentAssistInvocationContext) context;
    GroovyCompilationUnit compilationUnit = (GroovyCompilationUnit) javaContext.getCompilationUnit();
    if (compilationUnit.getModuleNode() == null) {
        return Collections.emptyList();
    }
    final ContentAssistContext contentAssistContext = createContentAssistContext(
            compilationUnit,
            context.getInvocationOffset(), context.getDocument());
    if (contentAssistContext == null) {
        return Collections.emptyList();
    }
    CharSequence computeIdentifierPrefix = "";
    try {
        computeIdentifierPrefix = javaContext.computeIdentifierPrefix();
    } catch (final BadLocationException e) {
        BonitaStudioLog.error("Failed to compute identifier prefix in ContractConstraint expression editor", e,
                ContractPlugin.PLUGIN_ID);
        return Collections.emptyList();
    }
    final CodeVisitorSupportContext codeVisitorSupportContext = new CodeVisitorSupportContext(
            computeIdentifierPrefix.toString(),
            (JavaContentAssistInvocationContext) context,
            contentAssistContext,
            getProjectClassloader(compilationUnit),
            new GroovyCompletionProposalComputer(),
            createMethodProposalCreator(),
            compilationUnit.getModuleNode());
    final ContractInputProposalsCodeVisitorSupport codeVistor = new ContractInputProposalsCodeVisitorSupport(inputs,
            codeVisitorSupportContext,
            monitor);
    final ASTNode completionNode = contentAssistContext.getPerceivedCompletionNode();
    if (completionNode != null) {
        completionNode.visit(codeVistor);
    }
    final List<ICompletionProposal> proposals = codeVistor.getProposals();
    if (proposals == null || proposals.isEmpty()) {
        return super.computeCompletionProposals(context, monitor);
    }
    return proposals;
}
 
Example #26
Source File: AbstractTemplateCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
	if (!(context instanceof JavaContentAssistInvocationContext))
		return Collections.emptyList();

	JavaContentAssistInvocationContext javaContext= (JavaContentAssistInvocationContext) context;
	ICompilationUnit unit= javaContext.getCompilationUnit();
	if (unit == null)
		return Collections.emptyList();

	fEngine= computeCompletionEngine(javaContext);
	if (fEngine == null)
		return Collections.emptyList();

	fEngine.reset();
	fEngine.complete(javaContext.getViewer(), javaContext.getInvocationOffset(), unit);

	TemplateProposal[] templateProposals= fEngine.getResults();
	List<ICompletionProposal> result= new ArrayList<ICompletionProposal>(Arrays.asList(templateProposals));

	IJavaCompletionProposal[] keyWordResults= javaContext.getKeywordProposals();
	if (keyWordResults.length == 0)
		return result;

	/* Update relevance of template proposals that match with a keyword
	 * give those templates slightly more relevance than the keyword to
	 * sort them first.
	 */
	for (int k= 0; k < templateProposals.length; k++) {
		TemplateProposal curr= templateProposals[k];
		String name= curr.getTemplate().getPattern();
		for (int i= 0; i < keyWordResults.length; i++) {
			String keyword= keyWordResults[i].getDisplayString();
			if (name.startsWith(keyword)) {
				String content= curr.getTemplate().getPattern();
				if (content.startsWith(keyword)) {
					curr.setRelevance(keyWordResults[i].getRelevance() + 1);
					break;
				}
			}
		}
	}
	return result;
}
 
Example #27
Source File: PostfixCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected TemplateEngine computeCompletionEngine(JavaContentAssistInvocationContext context) {
	ICompilationUnit unit = context.getCompilationUnit();
	if (unit == null)
		return null;

	IJavaProject javaProject = unit.getJavaProject();
	if (javaProject == null)
		return null;

	CompletionContext coreContext = context.getCoreContext();
	if (coreContext != null) {
		int tokenLocation= coreContext.getTokenLocation();
		int tokenStart= coreContext.getTokenStart();
		int tokenKind= coreContext.getTokenKind();
		
		/*
		// XXX print out tokenlocation stuff (debugging)
		System.out.println("All Tokens: " + CompletionContext.TL_CONSTRUCTOR_START + " " + CompletionContext.TL_MEMBER_START + " " + CompletionContext.TL_STATEMENT_START);
		System.out.println("Token Start: " + coreContext.getTokenStart());
		System.out.println("Token End: " + coreContext.getTokenEnd());
		System.out.println("Token Kind: " + coreContext.getTokenKind());
		System.out.println("Token Location: " + coreContext.getTokenLocation());
		System.out.println("Enclosing Element: " + coreContext.getEnclosingElement());
		System.out.println("Offset: " + coreContext.getOffset());
		System.out.println("Token Array: " + Arrays.toString(coreContext.getToken()));
		System.out.println("Kind Tokens: " + CompletionContext.TOKEN_KIND_NAME + ", " + CompletionContext.TOKEN_KIND_STRING_LITERAL + ", " + CompletionContext.TOKEN_KIND_UNKNOWN);
		*/
		if (context.getViewer().getSelectedRange().y > 0) { // If there is an active selection we do not want to contribute to the CA
			return null;
		}
		
		if ((tokenLocation == 0 && tokenStart > -1)
				|| ((tokenLocation & CompletionContext.TL_MEMBER_START) != 0 && tokenKind == CompletionContext.TOKEN_KIND_NAME && tokenStart > -1)
				|| (tokenLocation == 0 && isAfterDot(context.getDocument(), context.getInvocationOffset()))) {
			
			analyzeCoreContext(context, coreContext);

			return postfixCompletionTemplateEngine;
		}
	}
	return null;
}
 
Example #28
Source File: LazyPackageCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public LazyPackageCompletionProposal(CompletionProposal proposal, JavaContentAssistInvocationContext context) {
	super(proposal, context);
	fCompilationUnit= context.getCompilationUnit();
}
 
Example #29
Source File: JavadocLinkTypeCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public JavadocLinkTypeCompletionProposal(CompletionProposal proposal, JavaContentAssistInvocationContext context) {
	super(proposal, context);
	Assert.isTrue(isInJavadoc());
}
 
Example #30
Source File: JavadocInlineTagCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public JavadocInlineTagCompletionProposal(CompletionProposal proposal, JavaContentAssistInvocationContext context) {
	super(proposal, context);
	Assert.isTrue(isInJavadoc());
}