List of usage examples for org.eclipse.jdt.core Signature toString
public static String toString(String methodSignature, String methodName, String[] parameterNames, boolean fullyQualifyTypeNames, boolean includeReturnType)
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);/*w w w . j ava 2s .com*/ 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:ca.uvic.chisel.javasketch.ui.internal.presentation.TraceThreadLabelProvider.java
License:Open Source License
/** * @param element/*from ww w . j a v a2 s . c om*/ * @return */ private String uresolvedModelElement(ITraceModel element) { if (element instanceof ICall) { ICall call = (ICall) element; //try and get the method. if (call.getTarget() instanceof IArrival) { IActivation activation = call.getTarget().getActivation(); if (activation != null) { ITraceClassMethod method = activation.getMethod(); if (method != null) { return Signature.toString(method.getSignature(), method.getName(), null, false, false); } } } } else if (element instanceof ITraceClass) { ITraceClass clazz = (ITraceClass) element; String name = clazz.getName(); int dot = name.lastIndexOf('.'); if (dot > 0 && dot < name.length() - 1) { name = name.substring(dot + 1); } return name; } else if (element instanceof IReply) { IReply rep = (IReply) element; IActivation activation = rep.getActivation(); if (activation != null) { ITraceClassMethod method = activation.getMethod(); if (method != null) { return Signature.getSimpleName(Signature.getReturnType(method.getSignature())); } } } return ""; }
From source file:com.google.gdt.eclipse.appengine.rpc.util.CompilationUnitCreator.java
License:Open Source License
/** * Constructs the proxy body/*from w w w. ja va2 s . c o m*/ */ private void constructProxyBody(IType type, ImportsManager imports, IProgressMonitor monitor) throws JavaModelException { imports.addImport("com.google.web.bindery.requestfactory.shared.ProxyForName"); //$NON-NLS-N$ StringBuffer buf = new StringBuffer(); IImportDeclaration[] importDeclarations = current.getCompilationUnit().getImports(); // create list of entity names List<String> entityNameList = new ArrayList<String>(); for (IType entity : entityList) { entityNameList.add(entity.getElementName()); } // get list of all property methods List<IMethod> methods = new ArrayList<IMethod>(); for (IMethod method : current.getMethods()) { if (RequestFactoryUtils.isPropertyAccessor(method) && !method.getElementName().equals("setId")) { //$NON-NLS-N$ methods.add(method); } } boolean hasProxy; Set<String> typeNames; for (IMethod method : methods) { hasProxy = false; String methodName = method.getElementName(); String signature = Signature.toString(method.getSignature(), methodName, method.getParameterNames(), false, true); typeNames = new HashSet<String>(); typeNames.addAll(JavaUtils.getParamsAndReturnTypeNames(method)); hasProxy = addImport(typeNames, entityNameList, importDeclarations, imports); // check if to replace Task with TaskProxy if (hasProxy) { for (String entityName : entityNameList) { if (signature.contains(entityName)) { if (methodName.contains("get") || methodName.contains("is") || methodName.contains("has")) { //$NON-NLS-N$ signature = signature.replaceFirst(entityName, entityName + "Proxy"); //$NON-NLS-N$ } else if (methodName.contains("set")) { //$NON-NLS-N$ int index = signature.lastIndexOf(entityName); signature = signature.substring(0, index) + entityName + "Proxy" //$NON-NLS-N$ + signature.substring(index + entityName.length()); } } } } buf.append(signature); buf.append(";"); //$NON-NLS-N$ buf.append(lineDelimiter); } if (!methods.isEmpty()) { type.createMethod(buf.toString(), null, false, null); } if (monitor != null) { monitor.done(); } }
From source file:com.google.gdt.eclipse.appengine.rpc.util.RequestFactoryCodegenUtils.java
License:Open Source License
/** * Construct the signature for method added to service class, to be added to * the requestcontext/*from ww w .j a v a 2s . c o m*/ */ public static String constructMethodSignature(IMethod serviceMethod, List<IType> projectEntities) { StringBuffer buf = new StringBuffer(); try { buf.append("Request<"); String methodName = serviceMethod.getElementName(); String signature = Signature.toString(serviceMethod.getSignature(), methodName, serviceMethod.getParameterNames(), false, true); signature = signature.replace(methodName, ""); for (IType entity : projectEntities) { if (signature.contains(entity.getElementName())) { signature = signature.replace(entity.getElementName(), entity.getElementName() + "Proxy"); } } signature = signature.replace("void", "Void"); int index = signature.indexOf(" "); signature = signature.substring(0, index) + "> " + methodName + signature.substring(index) + ";"; buf.append(signature); } catch (JavaModelException e) { AppEngineRPCPlugin.log(e); } return buf.toString(); }
From source file:com.google.gdt.eclipse.appengine.rpc.wizards.helpers.RpcServiceLayerCreator.java
License:Open Source License
private void constructProxyBody(IType type, ImportsManager imports, IProgressMonitor monitor) throws JavaModelException { imports.addImport("com.google.web.bindery.requestfactory.shared.ProxyForName"); //$NON-NLS-N$ StringBuffer buf = new StringBuffer(); IImportDeclaration[] importDeclarations = current.getCompilationUnit().getImports(); // create list of entity names List<String> entityNameList = new ArrayList<String>(); for (IType entity : entityList) { entityNameList.add(entity.getElementName()); }/* ww w. j ava 2 s. c o m*/ // get list of all property methods List<IMethod> methods = new ArrayList<IMethod>(); for (IMethod method : current.getMethods()) { if (RequestFactoryUtils.isPropertyAccessor(method) && !method.getElementName().equals("setId")) { methods.add(method); } } boolean hasProxy; List<String> typeNames; for (IMethod method : methods) { hasProxy = false; String methodName = method.getElementName(); String signature = Signature.toString(method.getSignature(), methodName, method.getParameterNames(), false, true); typeNames = new ArrayList<String>(); String returnType[] = getElementSignatures(method.getReturnType()); for (String string : returnType) { typeNames.add(string); } String[] params = method.getParameterTypes(); // we are looking at only getters and setters, so there is only one param? if (params.length > 0) { String[] param = getElementSignatures(params[0]); for (String string : param) { typeNames.add(string); } } hasProxy = addImport(typeNames, entityNameList, importDeclarations, imports); // check if to replace Task with TaskProxy if (hasProxy) { for (String entityName : entityNameList) { if (signature.contains(entityName)) { if (methodName.contains("get") || methodName.contains("is") || methodName.contains("has")) { //$NON-NLS-N$ signature = signature.replaceFirst(entityName, entityName + "Proxy"); //$NON-NLS-N$ } else if (methodName.contains("set")) { //$NON-NLS-N$ int index = signature.lastIndexOf(entityName); signature = signature.substring(0, index) + entityName + "Proxy" //$NON-NLS-N$ + signature.substring(index + entityName.length()); } } } } buf.append(signature); buf.append(";"); //$NON-NLS-N$ buf.append(lineDelimiter); } if (!methods.isEmpty()) { type.createMethod(buf.toString(), null, false, null); } if (monitor != null) { monitor.done(); } }
From source file:com.google.gwt.eclipse.core.uibinder.contentassist.computers.SetterAttributeProposalComputer.java
License:Open Source License
private String getDescription(IType type, IMethod method) { try {//from www . j av a 2 s.c o m return MessageFormat.format(DESCRIPTION_FORMAT, type.getElementName(), Signature.toString( method.getSignature(), method.getElementName(), method.getParameterNames(), false, false)); } catch (JavaModelException e) { // if the above throws, we fall-back on a safer/simpler version return MessageFormat.format(DESCRIPTION_FORMAT, type.getElementName(), method.getElementName()); } }
From source file:com.ibm.safe.reporting.message.SignatureUtils.java
License:Open Source License
public static String getMethodSignature(final MethodLocation location, final boolean withReturnType) { String methodSignature = location.getLocationMethodSignature().replace('/', '.'); if (methodSignature.length() == 0) return methodSignature; final int signatureStartIndex = methodSignature.indexOf('('); if (signatureStartIndex < 0) { return methodSignature; }/*from ww w . j a v a 2 s .c o m*/ String methodName = methodSignature.substring(0, signatureStartIndex); methodName = methodName.substring(methodName.lastIndexOf('.') + 1); if (methodName.equals("<clinit>")) { //$NON-NLS-1$ return CLINIT_MSG; } boolean includeReturnType = withReturnType; if (methodName.equals("<init>")) { //$NON-NLS-1$ final String className = getClassName(location); methodName = className.substring(className.lastIndexOf('.') + 1); includeReturnType = false; } methodSignature = methodSignature.substring(signatureStartIndex); return Signature.toString(methodSignature, methodName, null /* parameterNames */, true /* fullyQualifiedName */, includeReturnType); }
From source file:fr.obeo.ariadne.ide.connector.java.internal.explorer.JavaExplorer.java
License:Open Source License
/** * Returns the qualified name of the given Java method. * /* ww w. j a va 2 s . c om*/ * @param iMethod * The Java method * @param isInInterface * Indicates if the Java method is located in an interface * @return The qualified name of the given Java method */ private String getQualifiedName(IMethod iMethod, boolean isInInterface) { try { String signatureBody = Signature.toString(iMethod.getSignature(), iMethod.getElementName(), iMethod.getParameterNames(), true, true); String signature = ""; //$NON-NLS-1$ int flags = iMethod.getFlags(); VisibilityKind visibility = this.getVisibility(iMethod, isInInterface); if (!visibility.equals(VisibilityKind.PACKAGE)) { signature = signature + visibility.getName().toLowerCase() + ' '; } if (Flags.isStatic(flags)) { signature = signature + IAriadneJavaConnectorConstants.STATIC + ' '; } if (Flags.isFinal(flags)) { signature = signature + IAriadneJavaConnectorConstants.FINAL + ' '; } signature = signature + signatureBody; return signature; } catch (JavaModelException e) { e.printStackTrace(); } return ""; //$NON-NLS-1$ }
From source file:net.sourceforge.tagsea.java.JavaWaypointUtils.java
License:Open Source License
/** * @param method//from w w w .jav a 2 s .co m * @return */ private static String getStringForMethod(IMethod method) { try { return Signature.toString(method.getSignature(), method.getElementName(), method.getParameterNames(), false, true); } catch (JavaModelException e) { return ""; } }
From source file:org.bonitasoft.studio.groovy.library.GroovyFunction.java
License:Open Source License
/** * Beware: This method is very time-consuming, avoid using it in loops and so on *//* w w w . j a v a2s. com*/ public String getSignature() { try { return Signature.toString(methodNode.getSignature(), methodNode.getElementName(), methodNode.getParameterNames(), false, true); } catch (JavaModelException e) { BonitaStudioLog.error(e); return ""; //$NON-NLS-1$ } }