List of usage examples for org.eclipse.jdt.internal.compiler.env IBinaryMethod getAnnotations
IBinaryAnnotation[] getAnnotations();
From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryMethod.java
License:Open Source License
public IAnnotation[] getAnnotations() throws JavaModelException { IBinaryMethod info = (IBinaryMethod) getElementInfo(); IBinaryAnnotation[] binaryAnnotations = info.getAnnotations(); return getAnnotations(binaryAnnotations, info.getTagBits()); }
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. *///from w ww .j av a 2 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: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.jboss.tools.seam.internal.core.scanner.lib.TypeScanner.java
License:Open Source License
private void process(IBinaryMethod m, SeamJavaComponentDeclaration component, LoadedDeclarations ds) { Map<String, IBinaryAnnotation> map = getSeamAnnotations(m.getAnnotations()); if (map == null || map.isEmpty()) return;//from w w w .j a v a2 s . c om IBinaryAnnotation a = map.get(FACTORY_ANNOTATION_TYPE); if (a != null) { processFactory(m, a, component, ds); } processBijection(m, map, component, ds); processComponentMethod(m, map, component, ds); }
From source file:org.springframework.ide.eclipse.core.java.TypeStructureCache.java
License:Open Source License
private boolean hasStructuralChanges(ClassFileReader reader, TypeStructure existingType, int flags) { if (existingType == null) { return true; }//from www .j a v a 2s . co m // modifiers if (!modifiersEqual(reader.getModifiers(), existingType.modifiers)) { return true; } // generic signature if (!CharOperation.equals(reader.getGenericSignature(), existingType.genericSignature)) { return true; } // superclass name if (!CharOperation.equals(reader.getSuperclassName(), existingType.superclassName)) { return true; } // class level annotations if ((flags & FLAG_ANNOTATION) != 0) { IBinaryAnnotation[] existingAnnotations = existingType.getAnnotations(); IBinaryAnnotation[] newAnnotations = reader.getAnnotations(); if (!annotationsEqual(existingAnnotations, newAnnotations, flags)) { return true; } } // tag bits; standard annotations like @Deprecated if (reader.getTagBits() != existingType.getTagBits()) { return true; } // interfaces char[][] existingIfs = existingType.interfaces; char[][] newIfsAsChars = reader.getInterfaceNames(); if (newIfsAsChars == null) { newIfsAsChars = EMPTY_CHAR_ARRAY; } // damn I'm lazy... if (existingIfs == null) { existingIfs = EMPTY_CHAR_ARRAY; } if (existingIfs.length != newIfsAsChars.length) return true; new_interface_loop: for (int i = 0; i < newIfsAsChars.length; i++) { for (int j = 0; j < existingIfs.length; j++) { if (CharOperation.equals(existingIfs[j], newIfsAsChars[i])) { continue new_interface_loop; } } return true; } // fields IBinaryField[] newFields = reader.getFields(); if (newFields == null) { newFields = TypeStructure.NoField; } IBinaryField[] existingFs = existingType.binFields; if (newFields.length != existingFs.length) return true; new_field_loop: for (int i = 0; i < newFields.length; i++) { IBinaryField field = newFields[i]; char[] fieldName = field.getName(); for (int j = 0; j < existingFs.length; j++) { if (CharOperation.equals(existingFs[j].getName(), fieldName)) { if (!modifiersEqual(field.getModifiers(), existingFs[j].getModifiers())) { return true; } if (!CharOperation.equals(existingFs[j].getTypeName(), field.getTypeName())) { return true; } if ((flags & FLAG_ANNOTATION) != 0) { if (!annotationsEqual(field.getAnnotations(), existingFs[j].getAnnotations(), flags)) { return true; } } continue new_field_loop; } } return true; } // methods IBinaryMethod[] newMethods = reader.getMethods(); if (newMethods == null) { newMethods = TypeStructure.NoMethod; } IBinaryMethod[] existingMs = existingType.binMethods; if (newMethods.length != existingMs.length) return true; new_method_loop: for (int i = 0; i < newMethods.length; i++) { IBinaryMethod method = newMethods[i]; char[] methodName = method.getSelector(); for (int j = 0; j < existingMs.length; j++) { if (CharOperation.equals(existingMs[j].getSelector(), methodName)) { // candidate match if (!CharOperation.equals(method.getMethodDescriptor(), existingMs[j].getMethodDescriptor())) { continue; // might be overloading } else { // matching sigs if (!modifiersEqual(method.getModifiers(), existingMs[j].getModifiers())) { return true; } if ((flags & FLAG_ANNOTATION) != 0) { if (!annotationsEqual(method.getAnnotations(), existingMs[j].getAnnotations(), flags)) { return true; } if (!parameterAnnotationsEquals(method, existingMs[j], flags)) { return true; } } continue new_method_loop; } } } return true; // (no match found) } return false; }