Example usage for org.eclipse.jdt.internal.compiler.env IBinaryAnnotation getTypeName

List of usage examples for org.eclipse.jdt.internal.compiler.env IBinaryAnnotation getTypeName

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.env IBinaryAnnotation getTypeName.

Prototype

char[] getTypeName();

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.ClassFileInfo.java

License:Open Source License

private void generateAnnotationInfo(JavaElement parent, char[] parameterName, HashMap newElements,
        IBinaryAnnotation annotationInfo, String memberValuePairName) {
    char[] typeName = org.eclipse.jdt.core.Signature
            .toCharArray(CharOperation.replaceOnCopy(annotationInfo.getTypeName(), '/', '.'));
    Annotation annotation = new Annotation(parent, parent.manager, new String(typeName), memberValuePairName);
    while (newElements.containsKey(annotation)) {
        annotation.occurrenceCount++;//from  w w  w  .j  ava 2s . com
    }
    newElements.put(annotation, annotationInfo);
    IBinaryElementValuePair[] pairs = annotationInfo.getElementValuePairs();
    for (int i = 0, length = pairs.length; i < length; i++) {
        Object value = pairs[i].getValue();
        if (value instanceof IBinaryAnnotation) {
            generateAnnotationInfo(annotation, newElements, (IBinaryAnnotation) value,
                    new String(pairs[i].getName()));
        } else if (value instanceof Object[]) {
            // if the value is an array, it can have no more than 1 dimension - no need to recurse
            Object[] valueArray = (Object[]) value;
            for (int j = 0, valueArrayLength = valueArray.length; j < valueArrayLength; j++) {
                Object nestedValue = valueArray[j];
                if (nestedValue instanceof IBinaryAnnotation) {
                    generateAnnotationInfo(annotation, newElements, (IBinaryAnnotation) nestedValue,
                            new String(pairs[i].getName()));
                }
            }
        }
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.BinaryIndexer.java

License:Open Source License

private void addBinaryAnnotation(IBinaryAnnotation annotation) {
    addAnnotationTypeReference(replace('/', '.', Signature.toCharArray(annotation.getTypeName())));
    IBinaryElementValuePair[] valuePairs = annotation.getElementValuePairs();
    if (valuePairs != null) {
        for (int j = 0, vpLength = valuePairs.length; j < vpLength; j++) {
            IBinaryElementValuePair valuePair = valuePairs[j];
            addMethodReference(valuePair.getName(), 0);
            Object pairValue = valuePair.getValue();
            addPairValue(pairValue);/*from  w  w w . jav  a2  s .c om*/
        }
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.ClassFileMatchLocator.java

License:Open Source License

private boolean checkAnnotation(IBinaryAnnotation annotation, TypeReferencePattern pattern) {
    if (checkTypeName(pattern.simpleName, pattern.qualification,
            convertClassFileFormat(Signature.toCharArray(annotation.getTypeName())), pattern.isCaseSensitive,
            pattern.isCamelCase)) {/*from   w  w w  . ja  va2s  .c  om*/
        return true;
    }
    IBinaryElementValuePair[] valuePairs = annotation.getElementValuePairs();
    if (valuePairs != null) {
        for (int j = 0, vpLength = valuePairs.length; j < vpLength; j++) {
            IBinaryElementValuePair valuePair = valuePairs[j];
            Object pairValue = valuePair.getValue();
            if (pairValue instanceof IBinaryAnnotation) {
                if (checkAnnotation((IBinaryAnnotation) pairValue, pattern)) {
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.util.Util.java

License:Open Source License

public static IAnnotation getAnnotation(JavaElement parent, JavaModelManager manager,
        IBinaryAnnotation binaryAnnotation, String memberValuePairName) {
    char[] typeName = org.eclipse.jdt.core.Signature
            .toCharArray(CharOperation.replaceOnCopy(binaryAnnotation.getTypeName(), '/', '.'));
    return new Annotation(parent, manager, new String(typeName), memberValuePairName);
}

From source file:io.takari.maven.plugins.compile.jdt.ClassfileDigester.java

License:Open Source License

private void updateAnnotation(IBinaryAnnotation annotation) {
    updateChars(annotation.getTypeName());
    IBinaryElementValuePair[] pairs = annotation.getElementValuePairs();
    for (int j = 0; j < pairs.length; j++) {
        updateChars(pairs[j].getName());
        final Object value = pairs[j].getValue();
        if (value instanceof Object[]) {
            Object[] values = (Object[]) value;
            for (int n = 0; n < values.length; n++) {
                updateAnnotationValue(values[n]);
            }/* ww w. ja v a2  s  . co  m*/
        } else {
            updateAnnotationValue(value);
        }
    }
}

From source file:org.eclipse.che.jdt.BinaryTypeConvector.java

License:Open Source License

private static JsonElement toJsonAnnotation(IBinaryAnnotation annotation) {
    JsonObject object = new JsonObject();
    object.add("typeName", annotation.getTypeName() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(annotation.getTypeName())));
    object.add("elementValuePairs", toJsonElementValuePairs(annotation.getElementValuePairs()));
    return object;
}

From source file:org.eclipse.wst.xml.core.internal.contentmodel.tapestry.travelpackage.TapestryClassLoader.java

License:Open Source License

public TapestryCoreComponents loadComponentAttributesFromClassFile(IPackageFragmentRoot fragmentRoot,
        String prefix, ClassFile packi) throws JavaModelException, ClassFormatException {
    ClassFileReader reader = new ClassFileReader(packi.getBytes(), null);
    TapestryCoreComponents component = new TapestryCoreComponents();
    component.setName(String.valueOf(reader.getSourceName()));
    component.setElementLabel(prefix + ":" + component.getName().toLowerCase());
    if (reader.getFields() != null)
        for (IBinaryField field : reader.getFields()) {
            boolean parameter = false;
            if (field.getAnnotations() == null)
                continue;
            for (IBinaryAnnotation anno : field.getAnnotations()) {
                if (String.valueOf(anno.getTypeName()).endsWith("/Parameter;")) {
                    parameter = true;/* ww w.j a va  2  s.co m*/
                    break;
                }
            }
            if (parameter) {
                component.addParameter(String.valueOf(field.getName()));
            }
        }

    String parentClassName = String.valueOf(reader.getSuperclassName());
    if (parentClassName != null && !parentClassName.isEmpty() && !parentClassName.equals("java/lang/Object")) {
        List<String> parameters = loadParametersFromParentClass(fragmentRoot, parentClassName);
        for (String parameter : parameters) {
            component.addParameter(parameter);
        }
    }

    return component;
}

From source file:org.eclipse.wst.xml.core.internal.contentmodel.tapestry.travelpackage.TapestryClassLoader.java

License:Open Source License

public List<String> loadParametersFromParentClass(IPackageFragmentRoot root, String classFileName) {
    List<String> list = new ArrayList<String>();
    if (classFileName.indexOf('/') < 0)
        return list;
    String packageName = classFileName.substring(0, classFileName.lastIndexOf('/')).replace('/', '.');
    String className = classFileName.substring(classFileName.lastIndexOf('/') + 1) + ".class";
    try {// w  ww. j av a2s.  c  o  m
        PackageFragment packInstance = (PackageFragment) root.getPackageFragment(packageName);
        for (Object packo : packInstance.getChildrenOfType(IJavaElement.CLASS_FILE)) {
            ClassFile packi = (ClassFile) packo;
            if (packi.getElementName().equals(className)) {
                ClassFileReader reader = null;
                try {
                    reader = new ClassFileReader(packi.getBytes(), null);
                } catch (ClassFormatException e) {
                    e.printStackTrace();
                }

                if (reader.getFields() != null)
                    for (IBinaryField field : reader.getFields()) {
                        boolean parameter = false;
                        if (field.getAnnotations() == null)
                            continue;
                        for (IBinaryAnnotation anno : field.getAnnotations()) {
                            if (String.valueOf(anno.getTypeName()).endsWith("/Parameter;")) {
                                parameter = true;
                                break;
                            }
                        }
                        if (parameter) {
                            list.add(String.valueOf(field.getName()));
                        }
                    }
                String parentClassName = String.valueOf(reader.getSuperclassName());
                if (parentClassName != null && !parentClassName.isEmpty()
                        && !parentClassName.equals("java/lang/Object")) {
                    list.addAll(loadParametersFromParentClass(root, parentClassName));
                }
                return list;
            }
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }

    return list;
}

From source file:org.jboss.tools.seam.internal.core.scanner.lib.TypeScanner.java

License:Open Source License

public static String getTypeName(IBinaryAnnotation a) {
    if (a.getTypeName() == null)
        return ""; //$NON-NLS-1$
    String t = new String(a.getTypeName());
    if (t.startsWith("L") && t.endsWith(";")) { //$NON-NLS-1$ //$NON-NLS-2$
        t = t.substring(1, t.length() - 1);
    }/*from  w  w w  .  j a v a2s.com*/
    t = t.replace('/', '.');

    return t;
}

From source file:org.springframework.ide.eclipse.maven.internal.core.DataNucleusEnhancerProjectBuilder.java

License:Open Source License

/**
 * {@inheritDoc}//ww w  .j  av a  2s .c  om
 */
public Set<IResource> getAffectedResources(IResource resource, int kind, int deltaKind) throws CoreException {
    if (IS_DATANUCLEUS_PRESENT) {

        if (kind == IncrementalProjectBuilder.FULL_BUILD) {
            return Collections.singleton((IResource) resource.getProject());
        } else if (resource instanceof IFile && resource.getName().endsWith(".class") && resource.isAccessible()
                && resource.isSynchronized(IResource.DEPTH_ZERO)) {
            // Check if the class has the @Entity annotation
            InputStream is = ((IFile) resource).getContents();
            try {
                ClassFileReader classFileReader = ClassFileReader.read(is, resource.getName());
                IBinaryAnnotation[] annotations = classFileReader.getAnnotations();
                if (annotations != null) {
                    for (IBinaryAnnotation annotation : annotations) {
                        if (CharOperation.equals(ENTITY_BINARY_CLASS_NAME, annotation.getTypeName())) {

                            if (classFileReader.getInterfaceNames() != null) {
                                for (char[] interfaceName : classFileReader.getInterfaceNames()) {
                                    for (char[] enhancedInterfaceName : ENHANCED_BINARY_CLASS_NAMES) {
                                        if (CharOperation.equals(interfaceName, enhancedInterfaceName)) {
                                            return Collections.emptySet();
                                        }
                                    }
                                }
                            }

                            return Collections.singleton(resource);
                        }
                    }
                }
            } catch (ClassFormatException e) {
                // TODO CD add error handling
            } catch (IOException e) {
                // TODO CD add error handling
            } finally {
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException e) {
                        // TODO CD add error handling
                    }
                }
            }
        }
    }
    return Collections.emptySet();
}