List of usage examples for org.eclipse.jdt.core CompletionProposal TYPE_REF
int TYPE_REF
To view the source code for org.eclipse.jdt.core CompletionProposal TYPE_REF.
Click Source Link
From source file:at.bestsolution.javafx.ide.jdt.internal.JavaEditor.java
License:Open Source License
@Inject public JavaEditor(BorderPane pane, IEditorInput input) { editor = new SourceEditor(); pane.setCenter(editor);/*from w w w. ja v a 2s .c om*/ IResourceFileInput fsInput = (IResourceFileInput) input; try { unit = ((ICompilationUnit) JavaCore.create(fsInput.getFile())) .getWorkingCopy(new FXWorkingCopyOwner(new IProblemRequestor() { private List<ProblemMarker> l = new ArrayList<>(); @Override public boolean isActive() { // TODO Auto-generated method stub return true; } @Override public void endReporting() { setMarkers(l); } @Override public void beginReporting() { l.clear(); } @Override public void acceptProblem(IProblem problem) { int linenumber = problem.getSourceLineNumber(); int startCol = problem.getSourceStart(); int endCol = problem.getSourceEnd(); if (endCol == startCol) { endCol++; } String description = problem.getMessage(); ProblemMarker marker = new ProblemMarker( problem.isError() ? at.bestsolution.javafx.ide.editor.ProblemMarker.Type.ERROR : at.bestsolution.javafx.ide.editor.ProblemMarker.Type.WARNING, linenumber, startCol, endCol, description); l.add(marker); } }), new NullProgressMonitor()); } catch (JavaModelException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } final Document doc = createDocument(unit); editor.setDocument(doc); editor.setContentProposalComputer(new ContentProposalComputer() { @Override public List<Proposal> computeProposals(String line, String prefix, int offset) { final List<Proposal> l = new ArrayList<ContentProposalComputer.Proposal>(); try { unit.codeComplete(offset, new CompletionRequestor() { @Override public void accept(CompletionProposal proposal) { String completion = new String(proposal.getCompletion()); if (!Flags.isPublic(proposal.getFlags())) { return; } if (proposal.getKind() == CompletionProposal.METHOD_REF) { String sig = Signature.toString(new String(proposal.getSignature()), new String(proposal.getName()), null, false, false); StyledString s = new StyledString(sig + " : " + Signature.getSimpleName(Signature .toString(Signature.getReturnType(new String(proposal.getSignature()))))); s.appendString( " - " + Signature.getSignatureSimpleName( new String(proposal.getDeclarationSignature())), Style.colored("#AAAAAA")); l.add(new Proposal(Type.METHOD, completion, s)); } else if (proposal.getKind() == CompletionProposal.FIELD_REF) { StyledString s = new StyledString( completion + " : " + (proposal.getSignature() != null ? Signature.getSignatureSimpleName( new String(proposal.getSignature())) : "<unknown>")); s.appendString( " - " + (proposal.getDeclarationSignature() != null ? Signature.getSignatureSimpleName( new String(proposal.getDeclarationSignature())) : "<unknown>"), Style.colored("#AAAAAA")); l.add(new Proposal(Type.FIELD, completion, s)); } else if (proposal.getKind() == CompletionProposal.TYPE_REF) { if (proposal.getAccessibility() == IAccessRule.K_NON_ACCESSIBLE) { return; } StyledString s = new StyledString( Signature.getSignatureSimpleName(new String(proposal.getSignature()))); s.appendString(" - " + new String(proposal.getDeclarationSignature()), Style.colored("#AAAAAA")); l.add(new Proposal(Type.TYPE, new String(proposal.getCompletion()), s)); } else { System.err.println(proposal); } } }); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return l; } }); editor.setSaveCallback(new Runnable() { @Override public void run() { try { unit.commitWorkingCopy(true, null); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); try { unit.reconcile(ICompilationUnit.NO_AST, true, null, null); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.amashchenko.eclipse.strutsclipse.java.SimpleJavaProposalCollector.java
License:Apache License
@Override protected IJavaCompletionProposal createJavaCompletionProposal(CompletionProposal proposal) { if (collectMethods) { if (CompletionProposal.METHOD_REF == proposal.getKind() && Flags.isPublic(proposal.getFlags())) { char[] sig = proposal.getSignature(); char[] declSig = proposal.getDeclarationSignature(); // collect methods suitable for action methods ignoring Object // methods if (sig != null && declSig != null && ACTION_METHOD_SIGNATURE.equals(String.valueOf(sig)) && !OBJECT_SIGNATURE.equals(String.valueOf(declSig))) { return new SimpleJavaCompletionProposal(proposal, getInvocationContext(), getImage(getLabelProvider().createImageDescriptor(proposal))); }/*from w w w. ja v a2 s. com*/ } } else { // collect packages and classes suitable for actions if ((CompletionProposal.PACKAGE_REF == proposal.getKind() || CompletionProposal.TYPE_REF == proposal.getKind()) && !Flags.isAbstract(proposal.getFlags()) && !Flags.isInterface(proposal.getFlags()) && !Flags.isEnum(proposal.getFlags())) { return new SimpleJavaCompletionProposal(proposal, getInvocationContext(), getImage(getLabelProvider().createImageDescriptor(proposal))); } } return null; }
From source file:com.google.gwt.eclipse.core.editors.java.contentassist.JsniCompletionProposal.java
License:Open Source License
/** * Return proposals only for references to a package, type, field, method or * constructor (and nothing else).//from w w w. j a v a2s . co m */ public static IJavaCompletionProposal create(IJavaCompletionProposal jdtProposal, CompletionProposal wrappedProposal, IJavaProject javaProject, int replaceOffset, int replaceLength) { switch (wrappedProposal.getKind()) { case CompletionProposal.PACKAGE_REF: case CompletionProposal.TYPE_REF: case CompletionProposal.FIELD_REF: case CompletionProposal.METHOD_REF: return new JsniCompletionProposal(jdtProposal, wrappedProposal, javaProject, replaceOffset, replaceLength); default: return null; } }
From source file:com.google.gwt.eclipse.core.editors.java.contentassist.JsniCompletionProposal.java
License:Open Source License
private String createReplaceString() { switch (wrappedProposal.getKind()) { case CompletionProposal.PACKAGE_REF: return computePackageCompletion(); case CompletionProposal.TYPE_REF: return computeTypeCompletion(); case CompletionProposal.FIELD_REF: return computeFieldCompletion(); case CompletionProposal.METHOD_REF: if (wrappedProposal.isConstructor()) { return computeCtorCompletion(); } else {// w w w . jav a2 s . co m return computeMethodCompletion(); } default: return ""; } }
From source file:com.google.gwt.eclipse.core.editors.java.contentassist.JsniCompletionProposalCollector.java
License:Open Source License
public static CompletionProposalCollector createMemberProposalCollector(ICompilationUnit cu, int refOffset, int refLength, String refQualifiedTypeName) { JsniCompletionProposalCollector collector = new JsniCompletionProposalCollector(cu, refOffset, refLength); collector.setIgnored(CompletionProposal.PACKAGE_REF, true); collector.setIgnored(CompletionProposal.TYPE_REF, true); collector.setQualifiedTypeName(refQualifiedTypeName); return collector; }
From source file:com.google.gwt.eclipse.core.uibinder.contentassist.computers.ProposalComputerFactory.java
License:Open Source License
/** * Creates a proposal computer for autocompleting the java classes for the * <ui:import field="___" />// www . j av a 2s .c o m */ public static IProposalComputer newUiImportFieldProposalComputer(ContentAssistRequest contentAssistRequest, IJavaProject javaProject, String packageName) { IDOMAttr attribute = XmlContentAssistUtilities.getAttribute(contentAssistRequest); if (attribute == null || attribute.getOwnerElement() == null) { return null; } // Ensure we are autocompleting an 'ui:import' element attribute if (!UiBinderConstants.UI_BINDER_IMPORT_ELEMENT_NAME.equals(attribute.getOwnerElement().getLocalName())) { return null; } // Ensure we are autocompleting the 'field' attribute if (!attribute.equals(UiBinderXmlModelUtilities.getFieldAttribute(attribute.getOwnerElement()))) { return null; } String attrValue = XmlContentAssistUtilities.getAttributeValueUsingMatchString(contentAssistRequest); CodeCompleteProposalComputer ccpc = new CodeCompleteProposalComputer( new int[] { CompletionProposal.TYPE_REF, CompletionProposal.PACKAGE_REF, CompletionProposal.FIELD_IMPORT, CompletionProposal.FIELD_REF }, javaProject, attrValue, XmlContentAssistUtilities.getAttributeValueOffset(contentAssistRequest), attrValue.length(), packageName, true); return ccpc; }
From source file:com.google.gwt.eclipse.core.uibinder.contentassist.computers.ProposalComputerFactory.java
License:Open Source License
/** * Creates a proposal computer for autocompleting the java classes for the * <ui:with ui:type="___" />//from www.ja v a 2 s .c o m */ public static IProposalComputer newWithTypeProposalComputer(ContentAssistRequest contentAssistRequest, IJavaProject javaProject) { IDOMAttr attribute = XmlContentAssistUtilities.getAttribute(contentAssistRequest); if (attribute == null || attribute.getOwnerElement() == null) { return null; } // Ensure we are autocompleting the 'type' attribute if (!attribute.equals(UiBinderXmlModelUtilities.getTypeAttribute(attribute.getOwnerElement()))) { return null; } String attrValue = XmlContentAssistUtilities.getAttributeValueUsingMatchString(contentAssistRequest); /* * Even though only types are valid, we must also propose packages to get to * fully qualified types if the user has typed e.g. "com.". */ return new CodeCompleteProposalComputer( new int[] { CompletionProposal.TYPE_REF, CompletionProposal.PACKAGE_REF }, javaProject, attrValue, XmlContentAssistUtilities.getAttributeValueOffset(contentAssistRequest), attrValue.length(), null, false); }
From source file:com.google.gwt.eclipse.core.uibinder.contentassist.computers.ProposalGeneratingCompletionRequestor.java
License:Open Source License
protected ICompletionProposal createProposal(CompletionProposal javaProposal) { String completion = String.valueOf(javaProposal.getCompletion()); int kind = javaProposal.getKind(); if (kind == CompletionProposal.TYPE_REF) { // Make sure it is fully qualified completion = JavaContentAssistUtilities.getFullyQualifiedTypeName(javaProposal); }// w w w.j ava 2 s. c om if (forceFullyQualifiedFieldNames && (kind == CompletionProposal.FIELD_IMPORT || kind == CompletionProposal.FIELD_REF)) { char[] decSig = javaProposal.getDeclarationSignature(); if (decSig != null && decSig.length > 2) { // declaration signatures for objects are like Ljava.lang.String;, so lop off first // and last chars completion = new String(decSig, 1, decSig.length - 2) + "." + new String(javaProposal.getCompletion()); completion = completion.replace('$', '.'); } } ICompletionProposal jdtCompletionProposal = JavaContentAssistUtilities .getJavaCompletionProposal(javaProposal, context, javaProject); return ReplacementCompletionProposal.fromExistingCompletionProposal(completion, replaceOffset, replaceLength, jdtCompletionProposal); }
From source file:com.google.gwt.eclipse.core.uibinder.contentassist.computers.ProposalGeneratingCompletionRequestor.java
License:Open Source License
private void ignoreAll() { int[] ignoredKinds = new int[] { CompletionProposal.ANONYMOUS_CLASS_DECLARATION, CompletionProposal.FIELD_REF, CompletionProposal.KEYWORD, CompletionProposal.LABEL_REF, CompletionProposal.LOCAL_VARIABLE_REF, CompletionProposal.METHOD_REF, CompletionProposal.METHOD_DECLARATION, CompletionProposal.PACKAGE_REF, CompletionProposal.TYPE_REF, CompletionProposal.VARIABLE_DECLARATION, CompletionProposal.POTENTIAL_METHOD_DECLARATION, CompletionProposal.METHOD_NAME_REFERENCE, CompletionProposal.ANNOTATION_ATTRIBUTE_REF, CompletionProposal.JAVADOC_FIELD_REF, CompletionProposal.JAVADOC_METHOD_REF, CompletionProposal.JAVADOC_TYPE_REF, CompletionProposal.JAVADOC_VALUE_REF, CompletionProposal.JAVADOC_PARAM_REF, CompletionProposal.JAVADOC_BLOCK_TAG, CompletionProposal.JAVADOC_INLINE_TAG, CompletionProposal.FIELD_IMPORT, CompletionProposal.METHOD_IMPORT, CompletionProposal.TYPE_IMPORT }; for (int kind : ignoredKinds) { setIgnored(kind, true);//from w ww . ja v a 2 s .c om } }
From source file:com.siteview.mde.internal.ui.editor.contentassist.TypePackageCompletionProcessor.java
License:Open Source License
private void generateProposals(String currentContent, IProject project, final Collection c, final int startOffset, final int length, final int typeScope) { class TypePackageCompletionRequestor extends CompletionRequestor { public TypePackageCompletionRequestor() { super(true); setIgnored(CompletionProposal.PACKAGE_REF, false); setIgnored(CompletionProposal.TYPE_REF, false); }/* www. ja v a2s. c om*/ public void accept(CompletionProposal proposal) { if (proposal.getKind() == CompletionProposal.PACKAGE_REF) { String pkgName = new String(proposal.getCompletion()); addProposalToCollection(c, startOffset, length, pkgName, pkgName, MDEPluginImages.get(MDEPluginImages.OBJ_DESC_PACKAGE)); } else { boolean isInterface = Flags.isInterface(proposal.getFlags()); String completion = new String(proposal.getCompletion()); if (isInterface && typeScope == IJavaSearchConstants.CLASS || (!isInterface && typeScope == IJavaSearchConstants.INTERFACE) || completion.equals("Dummy2")) //$NON-NLS-1$ // don't want Dummy class showing up as option. return; int period = completion.lastIndexOf('.'); String cName = null, pName = null; if (period == -1) { cName = completion; } else { cName = completion.substring(period + 1); pName = completion.substring(0, period); } Image image = isInterface ? MDEPluginImages.get(MDEPluginImages.OBJ_DESC_GENERATE_INTERFACE) : MDEPluginImages.get(MDEPluginImages.OBJ_DESC_GENERATE_CLASS); addProposalToCollection(c, startOffset, length, cName + " - " + pName, //$NON-NLS-1$ completion, image); } } } try { ICompilationUnit unit = getWorkingCopy(project); if (unit == null) { generateTypeProposals(currentContent, project, c, startOffset, length, 1); return; } IBuffer buff = unit.getBuffer(); buff.setContents("class Dummy2 { " + currentContent); //$NON-NLS-1$ CompletionRequestor req = new TypePackageCompletionRequestor(); unit.codeComplete(15 + currentContent.length(), req); unit.discardWorkingCopy(); } catch (JavaModelException e) { } }