Example usage for org.springframework.ide.eclipse.core.java JdtUtils getJavaType

List of usage examples for org.springframework.ide.eclipse.core.java JdtUtils getJavaType

Introduction

In this page you can find the example usage for org.springframework.ide.eclipse.core.java JdtUtils getJavaType.

Prototype

public static IType getJavaType(IProject project, String className) 

Source Link

Document

Returns the corresponding Java type for given full-qualified class name.

Usage

From source file:org.eclipse.virgo.ide.manifest.internal.core.validation.rules.BundleActivatorRule.java

@Override
protected void validateHeader(BundleManifestHeader header, BundleManifestValidationContext context) {
    String activatorClass = header.getValue();
    if (JdtUtils.getJavaType(context.getRootElement().getElementResource().getProject(),
            activatorClass) == null) {/*from www.  ja v  a2  s . c o m*/
        context.error("ILLEGAL_ACTIVATOR_CLASS",
                NLS.bind(BundleManifestCoreMessages.BundleErrorReporter_NoExist, activatorClass),
                header.getLineNumber() + 1);
    }
}

From source file:org.dozer.eclipse.plugin.sourcepage.hyperlink.DozerClassHyperlinkDetector.java

public IHyperlink createHyperlink(String attrName, String target, Node node, Node parentNode,
        IDocument document, ITextViewer textViewer, IRegion hyperlinkRegion, IRegion cursor) {
    String nodeName = parentNode.getNodeName();
    IFile file = BeansEditorUtils.getFile(document);
    IType type = JdtUtils.getJavaType(file.getProject(), target);

    if ("class-a".equals(nodeName) || "class-b".equals(nodeName) || "a-hint".equals(attrName)
            || "b-hint".equals(attrName) || "a-deep-index-hint".equals(attrName)
            || "b-deep-index-hint".equals(attrName)) {
        //make a simple hyperlink to the class
        if (type != null) {
            return new JavaElementHyperlink(hyperlinkRegion, type);
        }// w ww .j  a  v a  2  s.c o m
    } else if ("set-method".equals(attrName) || "get-method".equals(attrName)
            || "map-set-method".equals(attrName) || "map-get-method".equals(attrName)) {
        if ("field".equals(nodeName)) {
            String targetClassName = DozerPluginUtils.getMappingClassName(node);

            //get the first method that matches and make a hyperlink to that
            if (targetClassName != null) {
                IType targetClass = JdtUtils.getJavaType(file.getProject(), targetClassName);
                IMethod method = getMethodFromType(targetClass, target);
                if (method != null) {
                    return new JavaElementHyperlink(hyperlinkRegion, method);
                }
            }
        }
    } else if ("a-hint".equals(attrName) || "b-hint".equals(attrName)) {
        //make a simple hyperlink to the class
        if (parentNode.getParentNode() != null && "mapping".equals(parentNode.getParentNode().getNodeName())) {
            if (type != null) {
                return new JavaElementHyperlink(hyperlinkRegion, type);
            }
        }
    } else if ("custom-converter".equals(attrName)) {
        //make a simple hyperlink to the class
        if (type != null) {
            return new JavaElementHyperlink(hyperlinkRegion, type);
        }
    } else if ("custom-converter-id".equals(attrName)) {
        //search spring-bean that uses our mapping file and return the mapping
        //for the customconverter-id map-property
        ISourceModelElement modelElement = getModelElementForCustomConverter(BeansEditorUtils.getFile(document),
                target);

        if (modelElement != null) {
            return new SourceModelHyperlink(modelElement, hyperlinkRegion);
        }
    } else if ("a".equals(nodeName) || "b".equals(nodeName)) {
        String targetClassName = DozerPluginUtils.getMappingClassName(node.getParentNode());
        String property = node.getNodeValue();

        if (targetClassName != null) {
            IType targetClass = JdtUtils.getJavaType(file.getProject(), targetClassName);

            try {
                //if we are doing indexed property mapping, we remove the []
                property = property.replaceAll("\\[\\]", "");

                IMethod method = Introspector.getReadableProperty(targetClass, property);

                if (method != null)
                    return new JavaElementHyperlink(hyperlinkRegion, method);
            } catch (Throwable e) {
                Logger.logException(e);
            }
        }
    } else if ("bean-factory".equals(attrName)) {
        //make a simple hyperlink to the class
        if (type != null) {
            return new JavaElementHyperlink(hyperlinkRegion, type);
        }
    }

    return null;
}

From source file:org.dozer.eclipse.plugin.sourcepage.validation.Validator.java

@SuppressWarnings("restriction")
private void checkClassNodes(NodeList nodeList, IFile file, ValidationInfo validationReport)
        throws JavaModelException, DOMException {
    int len = nodeList.getLength();
    for (int i = 0; i < len; i++) {
        Node node = nodeList.item(i);
        Node textNode = node.getFirstChild();

        if (textNode.getNodeType() == Node.TEXT_NODE) {
            String className = textNode.getNodeValue();

            IType javaType = JdtUtils.getJavaType(file.getProject(), className);
            //class not found
            if (javaType == null) {
                Integer[] location = (Integer[]) node.getUserData("location");
                validationReport.addError("Class " + className + " not found.", location[0], location[1],
                        validationReport.getFileURI());
            }/*from  w w w  . j  a  va2 s .c o  m*/
        }

    }
}

From source file:org.dozer.eclipse.plugin.sourcepage.contentassist.DozerContentAssistProcessor.java

@SuppressWarnings("restriction")
protected ContentAssistRequest computeDozerPropertyContentProposals(int documentPosition, String matchString,
        ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) {
    int offset = nodeAtOffset.getStartOffset();
    int len = nodeAtOffset.getLength();

    ContentAssistRequest contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node,
            getStructuredDocumentRegion(documentPosition), completionRegion, offset, len, matchString);

    IFile file = BeansEditorUtils.getFile(contentAssistRequest);
    IProject project = file.getProject();
    String className = DozerPluginUtils.getMappingClassName(nodeAtOffset.getParentNode());
    IType type = JdtUtils.getJavaType(project, className);

    //by default immer this hinzu
    DozerJavaCompletionProposal newProposal = new DozerJavaCompletionProposal("\" this", offset, len, 2,
            JavaPluginImages.get(JavaPluginImages.IMG_OBJS_CLASS), "this", (IContextInformation) null, 0, true,
            null);/*from w  w w .ja va2s  . c  om*/
    contentAssistRequest.addProposal(newProposal);

    DozerPluginUtils.addPropertyNameAttributeValueProposals(contentAssistRequest, matchString, "", type);
    convertProposals(contentAssistRequest.getProposals());

    return contentAssistRequest;
}

From source file:org.dozer.eclipse.plugin.sourcepage.validation.Validator.java

private boolean checkClassImplementsCustomConverter(IProject project, String className)
        throws JavaModelException {
    IType javaType = JdtUtils.getJavaType(project, className);

    if (javaType == null)
        return false;

    ITypeHierarchy hierarchy = javaType.newSupertypeHierarchy(new NullProgressMonitor());
    IType[] interfaces = hierarchy.getAllSuperInterfaces(javaType);

    for (IType type : interfaces) {
        if (type.getElementName().equals("CustomConverter")) {
            return true;
        }//from  w w w. j  av a 2  s  .  c  om
    }

    return false;
}

From source file:org.dozer.eclipse.plugin.sourcepage.util.DozerPluginUtils.java

public static IType hasReadProperty(String property, String className, IProject project, boolean noGetter)
        throws JavaModelException {
    IType javaType = JdtUtils.getJavaType(project, className);
    String checkProperty = property;

    String[] propertySplitted = checkProperty.split("\\.");
    //we only check the first level, if there is some x.y.z property
    if (propertySplitted.length > 1) {
        checkProperty = propertySplitted[0];
    }//from  ww w . j a  v a  2 s  .  c o m
    //if we are doing indexed property mapping, we remove the []
    checkProperty = checkProperty.replaceAll("\\[\\]", "");

    if (noGetter) {
        IField[] fields = javaType.getFields();
        for (IField field : fields) {
            if (field.getElementName().equals(property)) {
                return field.getDeclaringType();
            }
        }
        return null;
    }

    Collection<IMethod> methods = Introspector.findReadableProperties(javaType, checkProperty, true);

    boolean retVal = methods.size() > 0;
    if (!retVal)
        return null;
    else {
        try {
            //className = JdtUtils.resolveClassName(className, javaType);
            if (!Class.forName(className).isPrimitive())
                className = null;
        } catch (Throwable t) {
            //className = null;
        }

        Iterator<?> iterator = methods.iterator();
        while (iterator.hasNext()) {
            IMethod method = (IMethod) iterator.next();
            IType returnType = JdtUtils.getJavaTypeForMethodReturnType(method, javaType);

            if (className == null) {
                if (returnType != null)
                    className = returnType.getFullyQualifiedName();
            }
            if (className != null) {
                if (propertySplitted.length > 1) {
                    List<String> l = new ArrayList<String>(Arrays.asList(propertySplitted));
                    l.remove(0);
                    property = StringUtils.collectionToDelimitedString(l, ".");

                    return hasReadProperty(property, returnType.getFullyQualifiedName(), project, false);
                } else {
                    return returnType;
                }
            }
        }
    }

    return null;
}

From source file:org.dozer.eclipse.plugin.sourcepage.contentassist.DozerContentAssistProcessor.java

private void addGetterSetterMethodProposals(ContentAssistRequest contentAssistRequest, String prefix,
        final String className, boolean onlySetter) {
    if (BeansEditorUtils.getFile(contentAssistRequest) instanceof IFile) {
        final IFile file = BeansEditorUtils.getFile(contentAssistRequest);

        IMethodFilter filter = null;/* ww  w .  j a va 2  s .co m*/
        if (onlySetter) {
            filter = new FlagsMethodFilter(FlagsMethodFilter.NOT_INTERFACE | FlagsMethodFilter.NOT_CONSTRUCTOR
                    | FlagsMethodFilter.PUBLIC, 1);

        } else {
            filter = new FlagsMethodFilter(FlagsMethodFilter.NOT_VOID | FlagsMethodFilter.NOT_INTERFACE
                    | FlagsMethodFilter.NOT_CONSTRUCTOR | FlagsMethodFilter.PUBLIC);
        }

        IContentAssistCalculator calculator = new MethodContentAssistCalculator(filter) {

            @Override
            protected IType calculateType(IContentAssistContext context) {
                return JdtUtils.getJavaType(file.getProject(), className);
            }
        };

        IContentAssistProposalRecorder recorder = new DefaultContentAssistProposalRecorder(
                contentAssistRequest);
        IContentAssistContext context = new DefaultContentAssistContext(contentAssistRequest, "xyz", //FIXME
                prefix);

        calculator.computeProposals(context, recorder); //request, prefix, null, null, null);
    }
}

From source file:org.dozer.eclipse.plugin.sourcepage.util.DozerPluginUtils.java

public static IType hasWriteProperty(String property, String className, IProject project)
        throws JavaModelException {
    IType javaType = JdtUtils.getJavaType(project, className);
    String checkProperty = property;

    String[] propertySplitted = checkProperty.split("\\.");
    if (propertySplitted.length > 1) {
        List<String> l = new ArrayList(Arrays.asList(propertySplitted));
        checkProperty = l.get(l.size() - 1);
        l.remove(l.size() - 1);//from   w  w w. ja  va  2 s.co m
        property = StringUtils.collectionToDelimitedString(l, ".");

        javaType = DozerPluginUtils.hasReadProperty(property, className, project, false);
        if (javaType == null)
            return null;
    }
    //if we are doing indexed property mapping, we remove the []
    checkProperty = checkProperty.replaceAll("\\[\\]", "");

    Collection<?> methods = Introspector.findWritableProperties(javaType, checkProperty, true);

    boolean retVal = methods.size() > 0;
    if (!retVal)
        return null;
    else
        return javaType;
}