public static void evaluateProposals( Type type, String prefix, int offset, int length, int relevance, Set<String> suggestedMethods, Collection<IDartCompletionProposal> result) throws CoreException { Method[] methods = type.getMethods(); 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 (!DartConventions.validateMethodName(prefix).matches(IStatus.ERROR)) { result.add( new MethodDeclarationCompletionProposal( type, prefix, Signature.SIG_VOID, offset, length, relevance)); } } }
public void test_CompilationUnitImpl_getSource_Clock() throws Exception { CompilationUnitImpl unit = getCompUnit("testsource/Clock.dart"); Type[] types = unit.getTypes(); assertEquals(7, types.length); Type type = unit.getType("Number"); assertNotNull(type); assertEquals(7, type.getFields().length); assertEquals(2, type.getMethods().length); assertEquals(9, type.getChildren().length); assertEquals(unit, type.getParent()); }
public MethodDeclarationCompletionProposal( Type type, String methodName, String returnTypeSig, int start, int length, int relevance) { super( "", type.getCompilationUnit(), start, length, null, getDisplayName(methodName, returnTypeSig), relevance); //$NON-NLS-1$ Assert.isNotNull(type); Assert.isNotNull(methodName); fType = type; fMethodName = methodName; fReturnTypeSig = returnTypeSig; if (returnTypeSig == null) { setProposalInfo(new ProposalInfo(type)); ImageDescriptor desc = new DartElementImageDescriptor( DartPluginImages.DESC_MISC_PUBLIC, DartElementImageDescriptor.CONSTRUCTOR, DartElementImageProvider.SMALL_SIZE); setImage(DartToolsPlugin.getImageDescriptorRegistry().get(desc)); } else { setImage(DartPluginImages.get(DartPluginImages.IMG_MISC_PRIVATE)); } }
private void processType(DartIdentifier node, InterfaceType binding) { CompilationUnitElement element = getDartElement(binding.asRawType()); if (element instanceof Type) { Type type = (Type) element; try { recordRelationship( peekTarget(new SourceRangeImpl(node)), new TypeLocation(type, type.getNameRange())); } catch (DartModelException exception) { DartCore.logInformation( "Could not get range for type " + type.getElementName() + " referenced from type " + peekTarget().getDartElement().getElementName(), exception); } } }
@Override protected boolean updateReplacementString( IDocument document, char trigger, int offset, ImportRewrite impRewrite) throws CoreException, BadLocationException { CodeGenerationSettings settings = JavaPreferencesSettings.getCodeGenerationSettings(fType.getDartProject()); boolean addComments = settings.createComments; String[] empty = new String[0]; String lineDelim = TextUtilities.getDefaultLineDelimiter(document); @SuppressWarnings("deprecation") String declTypeName = fType.getTypeQualifiedName('.'); boolean isInterface = fType.isInterface(); StringBuffer buf = new StringBuffer(); if (addComments) { String comment = CodeGeneration.getMethodComment( fType.getCompilationUnit(), declTypeName, fMethodName, empty, empty, fReturnTypeSig, lineDelim); if (comment != null) { buf.append(comment); buf.append(lineDelim); } } if (fReturnTypeSig != null) { buf.append(Signature.toString(fReturnTypeSig)); } buf.append(' '); buf.append(fMethodName); if (isInterface) { buf.append("();"); // $NON-NLS-1$ buf.append(lineDelim); } else { buf.append("() {"); // $NON-NLS-1$ buf.append(lineDelim); String body = CodeGeneration.getMethodBodyContent( fType.getCompilationUnit(), declTypeName, fMethodName, fReturnTypeSig == null, "", lineDelim); //$NON-NLS-1$ if (body != null) { buf.append(body); buf.append(lineDelim); } buf.append("}"); // $NON-NLS-1$ buf.append(lineDelim); } String stub = buf.toString(); // use the code formatter IRegion region = document.getLineInformationOfOffset(getReplacementOffset()); int lineStart = region.getOffset(); int indent = Strings.computeIndentUnits( document.get(lineStart, getReplacementOffset() - lineStart), settings.tabWidth, settings.indentWidth); String replacement = CodeFormatterUtil.format( CodeFormatter.K_CLASS_BODY_DECLARATIONS, stub, indent, null, lineDelim, fType.getDartProject()); if (replacement.endsWith(lineDelim)) { replacement = replacement.substring(0, replacement.length() - lineDelim.length()); } setReplacementString(Strings.trimLeadingTabsAndSpaces(replacement)); return true; }