List of usage examples for org.eclipse.jdt.core CompletionContext isExtended
public boolean isExtended()
From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.FXBeanJavaCompletionProposalComputer.java
License:Open Source License
@Override public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {// w w w .jav a 2s .c o m if (context instanceof JavaContentAssistInvocationContext && false) { JavaContentAssistInvocationContext javaContext = (JavaContentAssistInvocationContext) context; CompletionContext completionContext = javaContext.getCoreContext(); IJavaElement enclosingElement = null; if (completionContext.isExtended()) { enclosingElement = completionContext.getEnclosingElement(); } else { try { enclosingElement = javaContext.getCompilationUnit() .getElementAt(context.getInvocationOffset() + 1); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } List<ICompletionProposal> l = new ArrayList<ICompletionProposal>(); if (enclosingElement != null) { IType type = (IType) enclosingElement.getAncestor(IJavaElement.TYPE); if (type == null) { return l; } try { IField[] fields = type.getFields(); IMethod[] methods = type.getMethods(); int offset = context.getInvocationOffset() - 3; if (offset > 0) { String prefix = context.getDocument().get(offset, 3); IType propType = type.getJavaProject().findType("javafx.beans.property.Property"); IType writableType = type.getJavaProject().findType("javafx.beans.value.WritableValue"); // Primitives IType booleanType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyBooleanProperty"); IType doubleType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyDoubleProperty"); IType floatType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyFloatProperty"); IType intType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyIntegerProperty"); IType longType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyLongProperty"); IType stringType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyStringProperty"); for (int i = 0; i < fields.length; i++) { IField curr = fields[i]; if (!Flags.isEnum(curr.getFlags())) { IType fieldType = toType(type, curr.getTypeSignature()); if (fieldType != null) { if (assignable(fieldType, propType)) { if ("set".equals(prefix)) { if (assignable(fieldType, writableType)) { String setterName = NamingConventions.suggestSetterName( type.getJavaProject(), curr.getElementName(), curr.getFlags(), false, null); if (!hasMethod(methods, setterName)) { StyledString s = new StyledString(setterName + "(" + toValue(fieldType, booleanType, doubleType, floatType, intType, longType, stringType) + ") : void"); s.append(" - Setter for '" + curr.getElementName() + "'", StyledString.QUALIFIER_STYLER); l.add(new CompletionProposalImpl(setterName, s)); } } } else if (Character.isWhitespace(prefix.charAt(0)) && prefix.endsWith("is")) { if (assignable(fieldType, booleanType)) { String getterName = NamingConventions.suggestGetterName( type.getJavaProject(), curr.getElementName(), curr.getFlags(), false, null); getterName = "is" + getterName.substring(3); if (!hasMethod(methods, getterName)) { StyledString s = new StyledString(getterName + "() : boolean"); s.append(" - Getter for '" + curr.getElementName() + "'", StyledString.QUALIFIER_STYLER); l.add(new CompletionProposalImpl(getterName, s)); } } } else if ("get".equals(prefix)) { if (!assignable(fieldType, booleanType)) { String getterName = NamingConventions.suggestGetterName( type.getJavaProject(), curr.getElementName(), curr.getFlags(), false, null); if (!hasMethod(methods, getterName)) { StyledString s = new StyledString(getterName + "() : " + toValue(fieldType, booleanType, doubleType, floatType, intType, longType, stringType)); s.append(" - Getter for '" + curr.getElementName() + "'", StyledString.QUALIFIER_STYLER); l.add(new CompletionProposalImpl(getterName, s)); } } } else if (Character.isWhitespace(prefix.charAt(2))) { String propertyName = curr.getElementName() + "Property"; if (!hasMethod(methods, propertyName)) { StyledString s = new StyledString(propertyName); l.add(new CompletionProposalImpl(propertyName, s)); } } } } } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (BadLocationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return l; } return Collections.emptyList(); }
From source file:org.codehaus.groovy.eclipse.codeassist.completions.GroovyJavaGuessingCompletionProposal.java
License:Open Source License
/** * Creates a {@link ParameterGuessingProposal} or <code>null</code> if the * core context isn't available or extended. * * @param proposal the original completion proposal * @param context the currrent context// ww w . j a v a 2 s. c om * @param fillBestGuess if set, the best guess will be filled in * * @return a proposal or <code>null</code> */ public static GroovyJavaGuessingCompletionProposal createProposal(CompletionProposal proposal, JavaContentAssistInvocationContext context, boolean fillBestGuess, String contributor, ProposalFormattingOptions options) { CompletionContext coreContext = context.getCoreContext(); if (coreContext != null && coreContext.isExtended()) { return new GroovyJavaGuessingCompletionProposal(proposal, context, coreContext, fillBestGuess, contributor, options); } return null; }
From source file:org.codehaus.groovy.eclipse.codeassist.processors.StatementAndExpressionCompletionProcessor.java
License:Apache License
/** * @param requestor// w ww . jav a 2 s. c o m */ private void fillInExtendedContext(ExpressionCompletionRequestor requestor) { JavaContentAssistInvocationContext javaContext = getJavaContext(); CompletionContext coreContext = javaContext.getCoreContext(); if (coreContext != null && !coreContext.isExtended()) { // must use reflection to set the fields ReflectionUtils.setPrivateField(InternalCompletionContext.class, "isExtended", coreContext, true); ReflectionUtils.setPrivateField(InternalCompletionContext.class, "extendedContext", coreContext, new GroovyExtendedCompletionContext(getContext(), requestor.currentScope)); } }
From source file:org.eclipse.fx.ide.jdt.ui.internal.FXBeanJavaCompletionProposalComputer.java
License:Open Source License
@Override public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {/*from www .j a v a2 s .c om*/ if (context instanceof JavaContentAssistInvocationContext && Boolean.FALSE == true) { JavaContentAssistInvocationContext javaContext = (JavaContentAssistInvocationContext) context; CompletionContext completionContext = javaContext.getCoreContext(); IJavaElement enclosingElement = null; if (completionContext.isExtended()) { enclosingElement = completionContext.getEnclosingElement(); } else { try { enclosingElement = javaContext.getCompilationUnit() .getElementAt(context.getInvocationOffset() + 1); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } List<ICompletionProposal> l = new ArrayList<ICompletionProposal>(); if (enclosingElement != null) { IType type = (IType) enclosingElement.getAncestor(IJavaElement.TYPE); if (type == null) { return l; } try { IField[] fields = type.getFields(); IMethod[] methods = type.getMethods(); int offset = context.getInvocationOffset() - 3; if (offset > 0) { String prefix = context.getDocument().get(offset, 3); IType propType = type.getJavaProject().findType("javafx.beans.property.Property"); IType writableType = type.getJavaProject().findType("javafx.beans.value.WritableValue"); // Primitives IType booleanType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyBooleanProperty"); IType doubleType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyDoubleProperty"); IType floatType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyFloatProperty"); IType intType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyIntegerProperty"); IType longType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyLongProperty"); IType stringType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyStringProperty"); for (int i = 0; i < fields.length; i++) { IField curr = fields[i]; if (!Flags.isEnum(curr.getFlags())) { IType fieldType = toType(type, curr.getTypeSignature()); if (fieldType != null) { if (assignable(fieldType, propType)) { if ("set".equals(prefix)) { if (assignable(fieldType, writableType)) { String setterName = NamingConventions.suggestSetterName( type.getJavaProject(), curr.getElementName(), curr.getFlags(), false, null); if (!hasMethod(methods, setterName)) { StyledString s = new StyledString(setterName + "(" //$NON-NLS-1$ + toValue(fieldType, booleanType, doubleType, floatType, intType, longType, stringType) + ")" + " : void"); s.append(" - Setter for '" + curr.getElementName() + "'", //$NON-NLS-1$//$NON-NLS-2$ StyledString.QUALIFIER_STYLER); l.add(new CompletionProposalImpl(setterName, s, setterName + "(" + toValue(fieldType, booleanType, doubleType, floatType, intType, longType, stringType) + " " + curr.getElementName() + ")", curr, Type.SETTER, offset)); } } } else if (Character.isWhitespace(prefix.charAt(0)) && prefix.endsWith("is")) { if (assignable(fieldType, booleanType)) { String getterName = NamingConventions.suggestGetterName( type.getJavaProject(), curr.getElementName(), curr.getFlags(), false, null); getterName = "is" + getterName.substring(3); if (!hasMethod(methods, getterName)) { StyledString s = new StyledString(getterName + "() : boolean"); s.append(" - Getter for '" + curr.getElementName() + "'", StyledString.QUALIFIER_STYLER); l.add(new CompletionProposalImpl(getterName, s, getterName + "()", curr, Type.GETTER, offset)); } } } else if ("get".equals(prefix)) { if (!assignable(fieldType, booleanType)) { String getterName = NamingConventions.suggestGetterName( type.getJavaProject(), curr.getElementName(), curr.getFlags(), false, null); if (!hasMethod(methods, getterName)) { StyledString s = new StyledString(getterName + "() : " + toValue(fieldType, booleanType, doubleType, floatType, intType, longType, stringType)); s.append(" - Getter for '" + curr.getElementName() + "'", StyledString.QUALIFIER_STYLER); l.add(new CompletionProposalImpl(getterName, s, toValue(fieldType, booleanType, doubleType, floatType, intType, longType, stringType) + " " + getterName + "()", curr, Type.GETTER, offset)); } } } else if (Character.isWhitespace(prefix.charAt(2))) { String propertyName = curr.getElementName() + "Property() : " + fieldType.getElementName(); if (!hasMethod(methods, propertyName)) { StyledString s = new StyledString(propertyName); l.add(new CompletionProposalImpl( propertyName, s, fieldType.getElementName() + " " + curr.getElementName() + "Property()", curr, Type.ACCESSOR, offset)); } } } } } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (BadLocationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return l; } return Collections.emptyList(); }
From source file:org.eclipse.recommenders.completion.rcp.processable.ProcessableJavaMethodCompletionProposal.java
License:Open Source License
@Override protected LazyJavaCompletionProposal createRequiredTypeCompletionProposal(CompletionProposal completionProposal, JavaContentAssistInvocationContext invocationContext) { if (!anyIsNull(JAVA_CONTENT_ASSIST_INVOCATION_CONTEXT_F_CORE_CONTEXT, JAVA_CONTENT_ASSIST_INVOCATION_CONTEXT_F_COLLECTOR, COMPLETION_PROPOSAL_COLLECTOR_F_CONTEXT)) { try {//from ww w .j av a 2 s . c om CompletionContext oldCoreContext = (CompletionContext) JAVA_CONTENT_ASSIST_INVOCATION_CONTEXT_F_CORE_CONTEXT .get(invocationContext); if (!oldCoreContext.isExtended()) { CompletionProposalCollector collector = (CompletionProposalCollector) JAVA_CONTENT_ASSIST_INVOCATION_CONTEXT_F_COLLECTOR .get(invocationContext); CompletionContext newCoreContext = (CompletionContext) COMPLETION_PROPOSAL_COLLECTOR_F_CONTEXT .get(collector); JAVA_CONTENT_ASSIST_INVOCATION_CONTEXT_F_CORE_CONTEXT.set(invocationContext, newCoreContext); LazyJavaCompletionProposal proposal = super.createRequiredTypeCompletionProposal( completionProposal, invocationContext); JAVA_CONTENT_ASSIST_INVOCATION_CONTEXT_F_CORE_CONTEXT.set(invocationContext, oldCoreContext); return proposal; } else { return super.createRequiredTypeCompletionProposal(completionProposal, invocationContext); } } catch (IllegalArgumentException | IllegalAccessException e) { return super.createRequiredTypeCompletionProposal(completionProposal, invocationContext); } } else { return super.createRequiredTypeCompletionProposal(completionProposal, invocationContext); } }
From source file:org.eclipse.recommenders.internal.completion.rcp.JavaCompletionProposals.java
License:Open Source License
public static JavaMethodCompletionProposal newMethodRef(AccessibleCompletionProposal methodRef, JavaContentAssistInvocationContext context) { CompletionContext coreContext = context.getCoreContext(); JavaMethodCompletionProposal res;//from www. ja va 2 s . c o m if (coreContext != null && coreContext.isExtended()) { res = new ParameterGuessingProposal(methodRef, context, coreContext, true); } else { res = new JavaMethodCompletionProposal(methodRef, context); } IJavaProject project = methodRef.getData(IJavaProject.class).orNull(); if (project != null) { res.setProposalInfo(new MethodProposalInfo(project, methodRef)); } return res; }