List of usage examples for org.eclipse.jdt.internal.compiler.env IBinaryMethod getSelector
char[] getSelector();
From source file:com.codenvy.ide.ext.java.server.internal.core.ClassFileInfo.java
License:Open Source License
/** * Creates the handles and infos for the methods of the given binary type. * Adds new handles to the given vector. */// w w w . ja v a2 s. co m private void generateMethodInfos(IType type, IBinaryType typeInfo, HashMap newElements, ArrayList childrenHandles, ArrayList typeParameterHandles) { IBinaryMethod[] methods = typeInfo.getMethods(); if (methods == null) { return; } for (int i = 0, methodCount = methods.length; i < methodCount; i++) { IBinaryMethod methodInfo = methods[i]; final boolean isConstructor = methodInfo.isConstructor(); boolean isEnum = false; try { isEnum = type.isEnum(); } catch (JavaModelException e) { // ignore } // TODO (jerome) filter out synthetic members // indexer should not index them as well // if ((methodInfo.getModifiers() & IConstants.AccSynthetic) != 0) continue; // skip synthetic boolean useGenericSignature = true; char[] signature = methodInfo.getGenericSignature(); String[] pNames = null; if (signature == null) { useGenericSignature = false; signature = methodInfo.getMethodDescriptor(); if (isEnum && isConstructor) { pNames = Signature.getParameterTypes(new String(signature)); int length = pNames.length - 2; if (length >= 0) // https://bugs.eclipse.org/bugs/show_bug.cgi?id=436347 System.arraycopy(pNames, 2, pNames = new String[length], 0, length); } } String selector = new String(methodInfo.getSelector()); if (isConstructor) { selector = type.getElementName(); } try { if (!(isEnum && isConstructor && !useGenericSignature)) { pNames = Signature.getParameterTypes(new String(signature)); } if (isConstructor && useGenericSignature && type.isMember() && !Flags.isStatic(type.getFlags())) { int length = pNames.length; System.arraycopy(pNames, 0, (pNames = new String[length + 1]), 1, length); char[] descriptor = methodInfo.getMethodDescriptor(); final String[] parameterTypes = Signature.getParameterTypes(new String(descriptor)); pNames[0] = parameterTypes[0]; } } catch (IllegalArgumentException e) { // protect against malformed .class file (e.g. com/sun/crypto/provider/SunJCE_b.class has a 'a' generic signature) signature = methodInfo.getMethodDescriptor(); pNames = Signature.getParameterTypes(new String(signature)); } catch (JavaModelException e) { // protect against malformed .class file (e.g. com/sun/crypto/provider/SunJCE_b.class has a 'a' generic signature) signature = methodInfo.getMethodDescriptor(); pNames = Signature.getParameterTypes(new String(signature)); } char[][] paramNames = new char[pNames.length][]; for (int j = 0; j < pNames.length; j++) { paramNames[j] = pNames[j].toCharArray(); } char[][] parameterTypes = ClassFile.translatedNames(paramNames); JavaModelManager manager = ((JavaElement) type).manager; selector = manager.intern(selector); for (int j = 0; j < pNames.length; j++) { pNames[j] = manager.intern(new String(parameterTypes[j])); } BinaryMethod method = new BinaryMethod((JavaElement) type, manager, selector, pNames); childrenHandles.add(method); // ensure that 2 binary methods with the same signature but with different return types have different occurrence counts. // (case of bridge methods in 1.5) while (newElements.containsKey(method)) method.occurrenceCount++; newElements.put(method, methodInfo); int max = pNames.length; char[][] argumentNames = methodInfo.getArgumentNames(); if (argumentNames == null || argumentNames.length < max) { argumentNames = new char[max][]; for (int j = 0; j < max; j++) { argumentNames[j] = ("arg" + j).toCharArray(); //$NON-NLS-1$ } } int startIndex = 0; try { if (isConstructor) { if (isEnum) { startIndex = 2; } else if (type.isMember() && !Flags.isStatic(type.getFlags())) { startIndex = 1; } } } catch (JavaModelException e) { // ignore } // for (int j = startIndex; j < max; j++) { // IBinaryAnnotation[] parameterAnnotations = methodInfo.getParameterAnnotations(j - startIndex); // if (parameterAnnotations != null) { // LocalVariable localVariable = new LocalVariable( // method, // new String(argumentNames[j]), // 0, // -1, // 0, // -1, // method.parameterTypes[j], // null, // -1, // true); // generateAnnotationsInfos(localVariable, argumentNames[j], parameterAnnotations, methodInfo.getTagBits(), newElements); // } // } generateTypeParameterInfos(method, signature, newElements, typeParameterHandles); generateAnnotationsInfos(method, methodInfo.getAnnotations(), methodInfo.getTagBits(), newElements); Object defaultValue = methodInfo.getDefaultValue(); if (defaultValue instanceof IBinaryAnnotation) { generateAnnotationInfo(method, newElements, (IBinaryAnnotation) defaultValue, new String(methodInfo.getSelector())); } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.ClassFileMatchLocator.java
License:Open Source License
boolean matchMethod(MethodPattern pattern, Object binaryInfo, IBinaryType enclosingBinaryType) { if (!pattern.findDeclarations) return false; // only relevant when finding declarations if (!(binaryInfo instanceof IBinaryMethod)) return false; IBinaryMethod method = (IBinaryMethod) binaryInfo; if (!pattern.matchesName(pattern.selector, method.getSelector())) return false; if (!checkDeclaringType(enclosingBinaryType, pattern.declaringSimpleName, pattern.declaringQualification, pattern.isCaseSensitive(), pattern.isCamelCase())) return false; // look at return type only if declaring type is not specified boolean checkReturnType = pattern.declaringSimpleName == null && (pattern.returnSimpleName != null || pattern.returnQualification != null); boolean checkParameters = pattern.parameterSimpleNames != null; if (checkReturnType || checkParameters) { char[] methodDescriptor = convertClassFileFormat(method.getMethodDescriptor()); if (checkReturnType) { char[] returnTypeSignature = Signature.toCharArray(Signature.getReturnType(methodDescriptor)); if (!checkTypeName(pattern.returnSimpleName, pattern.returnQualification, returnTypeSignature, pattern.isCaseSensitive(), pattern.isCamelCase())) return false; }/*from www . ja v a 2 s . c o m*/ if (checkParameters && !checkParameters(methodDescriptor, pattern.parameterSimpleNames, pattern.parameterQualifications, pattern.isCaseSensitive(), pattern.isCamelCase())) return false; } return true; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
IMethod createBinaryMethodHandle(IType type, char[] methodSelector, char[][] argumentTypeNames) { ClassFileReader reader = MatchLocator.classFileReader(type); if (reader != null) { IBinaryMethod[] methods = reader.getMethods(); if (methods != null) { int argCount = argumentTypeNames == null ? 0 : argumentTypeNames.length; nextMethod: for (int i = 0, methodsLength = methods.length; i < methodsLength; i++) { IBinaryMethod binaryMethod = methods[i]; char[] selector = binaryMethod.isConstructor() ? type.getElementName().toCharArray() : binaryMethod.getSelector(); if (CharOperation.equals(selector, methodSelector)) { char[] signature = binaryMethod.getGenericSignature(); if (signature == null) signature = binaryMethod.getMethodDescriptor(); char[][] parameterTypes = Signature.getParameterTypes(signature); if (argCount != parameterTypes.length) continue nextMethod; if (argumentTypeNames != null) { for (int j = 0; j < argCount; j++) { char[] parameterTypeName = ClassFileMatchLocator .convertClassFileFormat(parameterTypes[j]); if (!CharOperation.endsWith( Signature.toCharArray(Signature.getTypeErasure(parameterTypeName)), CharOperation.replaceOnCopy(argumentTypeNames[j], '$', '.'))) continue nextMethod; parameterTypes[j] = parameterTypeName; }// w w w. j a v a 2 s.co m } return (IMethod) createMethodHandle(type, new String(selector), CharOperation.toStrings(parameterTypes)); } } } } return null; }
From source file:org.eclipse.che.jdt.BinaryTypeConvector.java
License:Open Source License
private static JsonElement toJsonMethod(IBinaryMethod method) { JsonObject object = new JsonObject(); object.addProperty("modifiers", method.getModifiers()); object.addProperty("constructor", method.isConstructor()); object.add("argumentNames", toJsonArrayString(method.getArgumentNames())); object.add("annotations", toJsonAnnotations(method.getAnnotations())); object.add("defaultValue", toJsonDefaultValue(method.getDefaultValue())); object.add("exceptionTypeNames", toJsonArrayString(method.getExceptionTypeNames())); object.add("genericSignature", method.getGenericSignature() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(method.getGenericSignature()))); object.add("methodDescriptor", method.getMethodDescriptor() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(method.getMethodDescriptor()))); object.add("parameterAnnotations", toJsonParameterAnnotations(method)); object.add("selector", method.getSelector() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(method.getSelector()))); object.addProperty("tagBits", String.valueOf(method.getTagBits())); object.addProperty("clinit", method.isClinit()); return object; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel.java
License:Open Source License
/** * Ensure we have bytes and constantPoolOffsets ready to use. *///from w w w . j ava2s . co m private void setupByteCode(boolean bytesRequired) { if (this._bytes == null || this._constantPoolOffsets == null) { try { MethodBinding binding = (this._binding == null) ? this._decl.binding : this._binding; assert binding.declaringClass.isTeam(); ClassFileReader reader = null; if (this._bytes == null) { if (this._classFile == null && this._decl != null) { char[] className = binding.declaringClass.constantPoolName(); this._classFile = (ClassFile) this._decl.compilationResult.compiledTypes.get(className); if (this._classFile != null && !this._classFile.isForType(binding.declaringClass)) { this._classFile = null; // has been reset thus cannot be used for this type any more. } } // here we made the best attempt to obtain a classfile, use it if possible: if (this._classFile != null && this._classFile.isForType(this._binding.declaringClass)) { this._bytes = this._classFile.getBytes(); this._structOffset += this._classFile.headerOffset; // structOffset did not yet include the headerOffset int olen = this._classFile.constantPool.currentIndex; System.arraycopy(this._classFile.constantPool.offsets, 0, this._constantPoolOffsets = new int[olen], 0, olen); this._classFile = null; // don't use any more return; } } if (this._bytes != null) { // create a reader for in-memory bytes in order to recalculate constant pool offsets reader = new ClassFileReader(this._bytes, RoleModel.NO_SOURCE_FILE); // STATE_BYTECODE_PREPARED } else { // Currently only team-ctors use a MethodModel for byte code retrieval. // Use the stored file name for reading the byte code from disc: if (binding.declaringClass.isTeam()) reader = binding.declaringClass.getTeamModel().read(); if (reader == null) { if (bytesRequired) throw new InternalCompilerError( "No byte code available for " + new String(binding.readableName())); //$NON-NLS-1$ return; } this._bytes = reader.getBytes(); } this._classFile = null; // don't use any more // now we have both a reader and bytes this._constantPoolOffsets = reader.getConstantPoolOffsets(); // find bytecode offset of this method: char[] mySignature = this._binding.signature(); for (IBinaryMethod m : reader.getMethods()) { if (CharOperation.equals(m.getSelector(), this._binding.selector) && CharOperation.equals(m.getMethodDescriptor(), mySignature)) { this._structOffset = ((MethodInfo) m).getStructOffset(); return; } } if (bytesRequired) throw new InternalCompilerError("Method " + String.valueOf(this._binding.readableName()) //$NON-NLS-1$ + "not found in class file " + String.valueOf(reader.getFileName())); //$NON-NLS-1$ } catch (ClassFormatException ex) { throw new InternalCompilerError(ex.getMessage()); } catch (IOException ex) { throw new InternalCompilerError(ex.getMessage()); } } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.TeamMethodGenerator.java
License:Open Source License
/** When binary methods for o.o.Team are created record the relevant method bindings. */ public void registerTeamMethod(IBinaryMethod method, MethodBinding methodBinding) { String selector = String.valueOf(method.getSelector()); String descriptor = String.valueOf(method.getMethodDescriptor()); registerTeamMethod(methodBinding.declaringClass, methodBinding, selector, descriptor, -1/*structOffset not yet known*/); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.TeamMethodGenerator.java
License:Open Source License
/** When o.o.Team is read from .class file, record the byte code here. */ public synchronized void maybeRegisterTeamClassBytes(ClassFileReader teamClass, ReferenceBinding teamClassBinding) { if (this.classBytes != null) return;/* w w w . java 2 s. co m*/ this.classBytes = teamClass.getBytes(); this.constantPoolOffsets = teamClass.getConstantPoolOffsets(); for (IBinaryMethod method : teamClass.getMethods()) { if (this.classBytes == null && method instanceof MethodInfo) { // repair if class already nulled its byte reference: this.classBytes = ((MethodInfo) method).reference; this.constantPoolOffsets = ((MethodInfo) method).constantPoolOffsets; } String selector = String.valueOf(method.getSelector()); String descriptor = String.valueOf(method.getMethodDescriptor()); int structOffset = ((MethodInfo) method).getStructOffset(); // relevant new info is structOffset, everything has already been registered from registerTeamMethod(IBinaryMethod,MethodBinding) registerTeamMethod(teamClassBinding, null, selector, descriptor, structOffset); } }
From source file:org.jboss.tools.seam.internal.core.scanner.lib.TypeScanner.java
License:Open Source License
private void processFactory(IBinaryMethod m, IBinaryAnnotation a, SeamJavaComponentDeclaration component, LoadedDeclarations ds) {/* ww w . ja v a 2s .c om*/ if (a == null) return; String name = (String) getValue(a, "value"); //$NON-NLS-1$ if (name == null || name.length() == 0) { name = new String(m.getSelector()); } SeamAnnotatedFactory factory = ("org.jboss.seam.international.messages".equals(name) && new String(m.getSelector()).equals("getMessages")) ? new SeamMessages() : new SeamAnnotatedFactory(); factory.setParentDeclaration(component); factory.setSourcePath(component.getSourcePath()); ds.getFactories().add(factory); IMethod im = findIMethod(component, m); factory.setId(im); factory.setSourceMember(im); factory.setName(name); Object scope = getValue(a, "scope"); //$NON-NLS-1$ if (scope != null) factory.setScopeAsString(scope.toString()); Object autoCreate = getValue(a, "autoCreate"); //$NON-NLS-1$ if (autoCreate instanceof Boolean) { factory.setAutoCreate((Boolean) autoCreate); } }
From source file:org.jboss.tools.seam.internal.core.scanner.lib.TypeScanner.java
License:Open Source License
private void processBijection(IBinaryMethod m, Map<String, IBinaryAnnotation> map, SeamJavaComponentDeclaration component, LoadedDeclarations ds) { Map<BijectedAttributeType, IBinaryAnnotation> as = new HashMap<BijectedAttributeType, IBinaryAnnotation>(); List<BijectedAttributeType> types = new ArrayList<BijectedAttributeType>(); IBinaryAnnotation main = null;/*from w ww. j ava 2 s . c om*/ for (int i = 0; i < BijectedAttributeType.values().length; i++) { IBinaryAnnotation a = map.get(BijectedAttributeType.values()[i].getAnnotationType()); if (a != null) { as.put(BijectedAttributeType.values()[i], a); if (main == null) main = a; types.add(BijectedAttributeType.values()[i]); } } if (as.isEmpty()) return; boolean isDataModelSelectionType = !types.get(0).isUsingMemberName(); BijectedAttribute att = (!isDataModelSelectionType) ? new BijectedAttribute() : new DataModelSelectionAttribute(); component.addBijectedAttribute(att); att.setTypes(types.toArray(new BijectedAttributeType[0])); String name = (String) getValue(main, "value"); //$NON-NLS-1$ att.setValue(name); if (name == null || name.length() == 0 || isDataModelSelectionType) { name = new String(m.getSelector()); } att.setName(name); Object scope = getValue(main, "scope"); //$NON-NLS-1$ if (scope != null) att.setScopeAsString(scope.toString()); IMember im = findIMethod(component, m); att.setSourceMember(im); }
From source file:org.jboss.tools.seam.internal.core.scanner.lib.TypeScanner.java
License:Open Source License
private IMethod findIMethod(SeamJavaComponentDeclaration component, IBinaryMethod m) { String name = new String(m.getSelector()); IType type = (IType) component.getSourceMember(); String signature = new String(m.getMethodDescriptor()); IMethod im = null;//from ww w. j a v a 2 s . c o m IMethod[] ms = null; try { ms = type.getMethods(); } catch (JavaModelException e) { SeamCorePlugin.getDefault().logError(e); } if (ms != null) for (int i = 0; i < ms.length; i++) { if (!ms[i].getElementName().equals(name)) continue; //check parameters try { if (ms[i].getParameterNames().length != m.getArgumentNames().length) continue; } catch (JavaModelException e) { continue; } //compare return ms[i]; } return null; }