List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding signature
public char[] signature()
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.impl.Engine.java
License:Open Source License
public static char[] getTypeSignature(TypeBinding typeBinding) { char[] result = typeBinding.signature(); if (result != null) { result = CharOperation.replaceOnCopy(result, '/', '.'); }/*w w w . j a v a2s. com*/ return result; }
From source file:com.google.gwt.dev.javac.JdtUtil.java
License:Apache License
/** * Get a readable method description from {@code methodBinding} conforming with JSNI formatting. * <p>/*from www. j a v a 2 s . com*/ * See examples: * <ul> * <li>a constructor of class A with a java.lang.String parameter will be formatted as * "new(Ljava/lang/String;).</li> * <li>a method with name m with an parameter of class java.lang.Object and return type boolean * will be formatted as "m(Ljava/lang/Object;</li> * </ul>, */ public static String formatMethodSignature(MethodBinding methodBinding) { ReferenceBinding declaringClassBinding = methodBinding.declaringClass; StringBuilder methodNameWithSignature = new StringBuilder(); String methodName = String.valueOf(methodBinding.selector); List<TypeBinding> parameterTypeBindings = Lists.newArrayList(); if (methodName.equals("<init>")) { // It is a constructor. // (1) use the JSNI methodName instead of <init>. methodName = "new"; // (2) add the implicit constructor parameters types for non static inner classes. if (isInnerClass(declaringClassBinding)) { NestedTypeBinding nestedBinding = (NestedTypeBinding) declaringClassBinding; if (nestedBinding.enclosingInstances != null) { for (SyntheticArgumentBinding argumentBinding : nestedBinding.enclosingInstances) { parameterTypeBindings.add(argumentBinding.type); } } } } parameterTypeBindings.addAll(Arrays.asList(methodBinding.parameters)); methodNameWithSignature.append(methodName); methodNameWithSignature.append("("); for (TypeBinding parameterTypeBinding : parameterTypeBindings) { methodNameWithSignature.append(parameterTypeBinding.signature()); } methodNameWithSignature.append(")"); return methodNameWithSignature.toString(); }
From source file:com.google.gwt.dev.javac.JdtUtil.java
License:Apache License
public static String signature(MethodBinding binding) { StringBuilder sb = new StringBuilder(); sb.append(binding.declaringClass.constantPoolName()); sb.append('.'); sb.append(binding.selector);//w w w. ja va 2 s . c o m sb.append('('); for (TypeBinding paramType : binding.parameters) { sb.append(paramType.signature()); } sb.append(')'); sb.append(binding.returnType.signature()); return sb.toString(); }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.JDTAnnotationNode.java
License:Open Source License
private Expression createExpressionFor(TypeBinding b, Object value) { if (b.isArrayType()) { ListExpression listExpression = new ListExpression(); // FIXASC is it a groovy optimization that if the value is expected to be an array you don't have to // write it as such if (value.getClass().isArray()) { Object[] values = (Object[]) value; for (Object v : values) { listExpression.addExpression(createExpressionFor(((ArrayBinding) b).leafComponentType, v)); }//from w w w . j a v a2 s .co m } else { listExpression.addExpression(createExpressionFor(((ArrayBinding) b).leafComponentType, value)); } return listExpression; } else if (b.isEnum()) { ClassExpression classExpression = new ClassExpression(resolver.convertToClassNode(b)); Expression valueExpression = new PropertyExpression(classExpression, new String(((FieldBinding) value).name)); return valueExpression; } else if (CharOperation.equals(b.signature(), jlString)) { String v = ((StringConstant) value).stringValue(); return new ConstantExpression(v); } else if (b.isBaseType()) { char[] sig = b.signature(); if (CharOperation.equals(sig, baseInt)) { return new ConstantExpression(((IntConstant) value).intValue()); } else { throw new GroovyEclipseBug("NYI for signature " + new String(sig)); } } else if (b.isClass()) { ClassExpression classExpression = new ClassExpression(resolver.convertToClassNode((TypeBinding) value)); return classExpression; } throw new GroovyEclipseBug( "Problem in JDTAnnotatioNode.createExpressionFor(binding=" + b + " value=" + value + ")"); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.MethodSpec.java
License:Open Source License
/** * This method is used by /* w w w. j a v a2s . c om*/ * {@link org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.CallinMethodMappingsAttribute CallinMethodMappingsAttribute} * for decoding a mapping from its bytecode attribute. * @param method * @return the bytecode level signature of the given method (yet retrenched) */ public static char[] signature(MethodBinding method, WeavingScheme weavingScheme) { StringBuffer buffer = new StringBuffer(); buffer.append('('); // synthetic args for static role method? MethodBinding orig = method.copyInheritanceSrc != null ? method.copyInheritanceSrc : method; // normalize to copyInhSrc so reading a callin-attr. from bytes can more easily find the method if (weavingScheme == WeavingScheme.OTDRE && orig.declaringClass.isRole() && orig.isStatic()) { buffer.append('I'); buffer.append(String.valueOf(orig.declaringClass.enclosingType().signature())); } // manual retrenching? boolean shouldRetrench = weavingScheme == WeavingScheme.OTRE && method.isCallin(); int offset = shouldRetrench ? MethodSignatureEnhancer.getEnhancingArgLen(weavingScheme) : 0; int paramLen = method.parameters.length; for (int i = offset; i < paramLen; i++) { // 'weaken' to that erasure that was used in the tsuper version: TypeBinding targetParameter = method.getCodeGenType(i); buffer.append(targetParameter.signature()); } buffer.append(')'); TypeBinding sourceReturnType = shouldRetrench ? MethodModel.getReturnType(method) : method.returnType; // 'weaken' to that erasure that was used in the tsuper version: MethodBinding tsuperOriginal = (method.tagBits & TagBits.IsCopyOfParameterized) != 0 ? method.copyInheritanceSrc.original() : null; TypeBinding returnType = (tsuperOriginal != null && tsuperOriginal.returnType.isTypeVariable() && !sourceReturnType.isTypeVariable()) ? tsuperOriginal.returnType : sourceReturnType; if (returnType.isTypeVariable() && method instanceof ParameterizedGenericMethodBinding) returnType = ((ParameterizedGenericMethodBinding) method) .reverseSubstitute((TypeVariableBinding) returnType); buffer.append(returnType.erasure().signature()); int nameLength = buffer.length(); char[] signature = new char[nameLength]; buffer.getChars(0, nameLength, signature, 0); return signature; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.CalloutMappingsAttribute.java
License:Open Source License
private boolean typeMatchesSignature(TypeBinding type, char[] signature) { char[] bindingType; char[] signatureType = signature; if (!type.isValidBinding()) { signatureType = getSignatureSimpleName(signatureType); bindingType = type.internalName(); } else {// www. ja v a 2s . c o m bindingType = type.signature(); } return CharOperation.equals(bindingType, signatureType); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectMapper.java
License:Open Source License
/** * Map a type binding and convert it to a UTF8-Object. * @param typeBinding/*ww w. j a v a 2s . c o m*/ * @param useGenerics should type parameters be respected (else use erasure) * @return ConstantPoolObject of type Utf8Tag */ public ConstantPoolObject mapTypeUtf8(TypeBinding typeBinding, boolean useGenerics) { //System.out.println("Sign of "+typeBinding+"="+new String(typeBinding.signature())); char[] prefix = null; if (typeBinding.isArrayType()) { // need to disassemble arrays, because we want to analyze the element type: ArrayBinding array = (ArrayBinding) typeBinding; prefix = new char[array.dimensions()]; Arrays.fill(prefix, '['); typeBinding = array.leafComponentType; } if (typeBinding.isClass() || typeBinding.isInterface()) { ConstantPoolObject clazzCPO = new ConstantPoolObject(ClassTag, mapClass(this._srcMethod, typeBinding, getTeam(this._dstMethod))); typeBinding = clazzCPO.getClassObject(); } char[] signature = useGenerics ? typeBinding.genericTypeSignature() : typeBinding.signature(); if (prefix != null) signature = CharOperation.concat(prefix, signature); return new ConstantPoolObject(Utf8Tag, signature); }
From source file:org.eclipse.recommenders.completion.rcp.RecommendersCompletionContext.java
License:Open Source License
@Override public Optional<String> getReceiverTypeSignature() { TypeBinding b = get(RECEIVER_TYPEBINDING, null); if (b == null) { return absent(); }//from ww w . j ava2s.c o m final String res = new String(b.signature()); return of(res); }
From source file:org.eclipse.recommenders.internal.chain.rcp.TypeBindingAnalyzer.java
License:Open Source License
public static boolean isAssignable(final ChainElement edge, final TypeBinding expectedType, final int expectedDimension) { if (expectedDimension <= edge.getReturnTypeDimension()) { final TypeBinding base = removeArrayWrapper(edge.getReturnType()); if (base instanceof BaseTypeBinding) { return false; }/*from w ww . java 2 s. c om*/ if (base.isCompatibleWith(expectedType)) { return true; } final LinkedList<ReferenceBinding> supertypes = Lists.newLinkedList(); supertypes.add((ReferenceBinding) base); final String expectedSignature = String.valueOf(expectedType.signature()); while (!supertypes.isEmpty()) { final ReferenceBinding type = supertypes.poll(); if (String.valueOf(type.signature()).equals(expectedSignature)) { return true; } final ReferenceBinding superclass = type.superclass(); if (superclass != null) { supertypes.add(superclass); } for (final ReferenceBinding intf : type.superInterfaces()) { supertypes.add(intf); } } } return false; }
From source file:org.eclipse.recommenders.rcp.utils.CompilerBindings.java
License:Open Source License
/** * TODO nested anonymous types are not resolved correctly. JDT uses line numbers for inner types instead of $1,..,$n *///from w ww .ja v a 2 s . c o m public static Optional<ITypeName> toTypeName(@Nullable TypeBinding binding) { if (binding == null) { return absent(); } try { binding = binding.original(); char[] signature = binding.signature(); if (signature == null) { return absent(); } final ITypeName result; if (isPrimitiveBaseType(binding)) { result = VmTypeName.get(String.valueOf(signature)); } else { // Strip of semicolon. result = VmTypeName.get(String.valueOf(signature, 0, signature.length - 1)); } return Optional.of(result); } catch (final RuntimeException e) { return absent(); } }