Example usage for org.eclipse.jdt.core IJavaElement CLASS_FILE

List of usage examples for org.eclipse.jdt.core IJavaElement CLASS_FILE

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaElement CLASS_FILE.

Prototype

int CLASS_FILE

To view the source code for org.eclipse.jdt.core IJavaElement CLASS_FILE.

Click Source Link

Document

Constant representing a class file.

Usage

From source file:edu.buffalo.cse.green.editor.model.RootModel.java

License:Open Source License

/**
 * @return The list of <code>IClassFile</code>s contained in the root.
 *//*from www .  j  av  a 2 s.c o m*/
public List<IClassFile> getClassFiles() {
    List<IClassFile> classFiles = new ArrayList<IClassFile>();

    for (AbstractModel model : getModels(this, TypeModel.class)) {
        TypeModel typeModel = (TypeModel) model;

        if (typeModel.getType().isBinary()) {
            classFiles.add((IClassFile) typeModel.getType().getAncestor(IJavaElement.CLASS_FILE));
        }
    }

    return classFiles;
}

From source file:edu.buffalo.cse.green.relationships.RelationshipVisitor.java

License:Open Source License

/**
 * @param element - The member element./*from   w w w . j a  v a 2s. com*/
 * @return A <code>CompilationUnit</code> representing the structure of the
 * source code of the element.
 */
public static CompilationUnit getCompilationUnit(IMember element) {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setResolveBindings(true);

    if (element.isBinary()) {
        parser.setSource((IClassFile) element.getAncestor(IJavaElement.CLASS_FILE));
    } else {
        parser.setSource((ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT));
    }

    return (CompilationUnit) parser.createAST(null);
}

From source file:edu.buffalo.cse.green.relationships.RelationshipVisitor.java

License:Open Source License

/**
 * @param element - The element.//from   w  w w.j  ava 2s.c o  m
 * @return The <code>CompilationUnit</code> representing the given element.
 */
public CompilationUnit getCompilationUnit(IType element) {
    if (element.isBinary()) {
        return getCompilationUnit((IClassFile) element.getAncestor(IJavaElement.CLASS_FILE));
    } else {
        return getCompilationUnit((ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT));
    }
}

From source file:iot.jcypher.eclipse.JCypherCompletionProposalComputer.java

License:Apache License

private List<ICompletionProposal> buildJCypherProposals(List<ICompletionProposal> proposals) {
    List<ICompletionProposal> ret = new ArrayList<>(proposals.size());
    List<String> classNames = new ArrayList<String>();
    List<String> classNames_ext = new ArrayList<String>();
    for (ICompletionProposal prop : proposals) {
        if (prop instanceof IJavaCompletionProposal) {
            if (prop instanceof JavaMethodCompletionProposal) {
                JavaMethodCompletionProposal jmcp = (JavaMethodCompletionProposal) prop;
                IJavaElement elem = jmcp.getJavaElement();
                IJavaElement classfile = elem.getParent().getParent();
                if (classfile.getElementType() == IJavaElement.CLASS_FILE
                        || classfile.getElementType() == IJavaElement.COMPILATION_UNIT) {
                    IJavaElement pkg = classfile.getParent();
                    if (JCypherPackages.addsToProposal(pkg.getElementName())) {
                        IJavaCompletionProposal delegate = (IJavaCompletionProposal) prop;
                        IJavaElement mthd = ((AbstractJavaCompletionProposal) delegate).getJavaElement();
                        IJavaElement clsfile = elem.getParent().getParent();
                        String className = clsfile.getElementName();
                        if (!classNames_ext.contains(className)) {
                            classNames_ext.add(className);
                            // trim className extension which can either be .class or .java
                            classNames.add(className.substring(0, className.indexOf('.')));
                        }/*from   w  w w .  jav a2s .  c  o m*/
                        // classNames always contains (class, superClass, superSuperClass, ..)
                        int relevance = ProposalOrderConfig.INSTANCE.getRelevance(classNames.get(0),
                                mthd.getElementName(), JCypherConstants.DEFAULT_RELEVANCE);
                        ret.add(new JCypherCompletionProposal((IJavaCompletionProposal) prop, relevance));
                    }
                }
            }
        }
    }
    if (ret.size() > 0) {
        ProposalOrderConfig.INSTANCE.addSeparators(classNames.get(0), ret, JCypherConstants.DEFAULT_RELEVANCE);
        ret.add(CompletionSeparator.INSTANCE);
    }
    return ret;
}

From source file:jp.littleforest.pathtools.handlers.CopyQualifiedNameHandler.java

License:Open Source License

protected String getQualifiedName(IJavaElement e) {
    String qn = "";
    switch (e.getElementType()) {
    case IJavaElement.ANNOTATION:
        break;/*from  www .  j  a v a2s  . c o  m*/
    case IJavaElement.CLASS_FILE:
        qn = getQualifiedClassName((IClassFile) e);
        break;
    case IJavaElement.COMPILATION_UNIT:
        qn = getQualifiedClassName((ICompilationUnit) e);
        break;
    case IJavaElement.FIELD:
        qn = getQualifiedFieldName((IField) e);
        break;
    case IJavaElement.IMPORT_CONTAINER:
        break;
    case IJavaElement.IMPORT_DECLARATION:
        break;
    case IJavaElement.INITIALIZER:
        break;
    case IJavaElement.JAVA_MODEL:
        break;
    case IJavaElement.JAVA_PROJECT:
        break;
    case IJavaElement.LOCAL_VARIABLE:
        break;
    case IJavaElement.METHOD:
        qn = getQualifiedMethodName((IMethod) e);
        break;
    case IJavaElement.PACKAGE_DECLARATION:
        break;
    case IJavaElement.PACKAGE_FRAGMENT:
        qn = getQualifiedPackageName(e);
        break;
    case IJavaElement.TYPE:
        qn = getQualifiedClassName((IType) e);
        break;
    case IJavaElement.TYPE_PARAMETER:
        break;
    default:
        break;
    }
    return qn;
}

From source file:jp.littleforest.pathtools.handlers.CopyQualifiedNameHandler.java

License:Open Source License

protected String getQualifiedClassName(IType type) {
    String fqcn = type.getElementName();
    IJavaElement parent = type.getParent();
    if (parent == null) {
        return fqcn;
    }//from   ww w  .ja v a 2 s .c o  m
    int parentType = parent.getElementType();
    if (parentType == IJavaElement.TYPE) {
        // ??
        String enclosingQn = getQualifiedName(parent);
        fqcn = enclosingQn + "$" + fqcn;
    } else if (parentType == IJavaElement.COMPILATION_UNIT) {
        // ??
        fqcn = getQualifiedClassName((ICompilationUnit) parent);
    } else if (parentType == IJavaElement.CLASS_FILE) {
        // Jar???
        fqcn = getQualifiedClassName((IClassFile) parent);
    } else if (parentType == IJavaElement.PACKAGE_FRAGMENT) {
        fqcn = getQualifiedPackageName(parent) + "." + fqcn;
    }
    return fqcn;
}

From source file:jp.littleforest.pathtools.handlers.CopyQualifiedNameHandler.java

License:Open Source License

protected String getQualifiedFieldName(IField e) {
    IJavaElement parent = e.getParent();
    int parentType = parent.getElementType();
    String parentQn = "";
    if (parentType == IJavaElement.TYPE) {
        parentQn = getQualifiedClassName((IType) parent);
    } else if (parentType == IJavaElement.CLASS_FILE) {
        parentQn = getQualifiedClassName((IClassFile) parent);
    }/*from   w  w  w. j  a v a  2s  .c  o  m*/
    return parentQn + "#" + e.getElementName();
}

From source file:net.harawata.mybatipse.wizard.NewXmlMapperWizardPage.java

License:Open Source License

public NewXmlMapperWizardPage(IStructuredSelection selection) {
    super("NewXmlMapperWizardPage", selection);
    setTitle("New MyBatis XML Mapper");
    setDescription("Create a new MyBatis XML Mapper file.");
    setFileExtension(EXT);//from ww w . j av a  2  s . co m
    // Propose file name
    Object elem = selection.getFirstElement();
    if (elem != null) {
        if (elem instanceof IJavaElement) {
            int javaElemType = ((IJavaElement) elem).getElementType();
            if (javaElemType == IJavaElement.COMPILATION_UNIT) {
                setFileNameWithExtension(((ICompilationUnit) elem).getElementName());
            } else if (javaElemType == IJavaElement.CLASS_FILE) {
                setFileNameWithExtension(((IClassFile) elem).getElementName());
            } else if (javaElemType == IJavaElement.TYPE) {
                setFileNameWithExtension(((IType) elem).getElementName());
            }
        } else if (elem instanceof IFile) {
            setFileNameWithExtension(((IFile) elem).getFullPath().removeFileExtension().lastSegment());
        } else {
            // Leave empty.
        }
    }
}

From source file:net.sourceforge.c4jplugin.internal.ui.contracthierarchy.ContractHierarchyLifeCycle.java

License:Open Source License

private void processDelta(IJavaElementDelta delta, ArrayList<IType> changedTypes) {
    IJavaElement element = delta.getElement();
    switch (element.getElementType()) {
    case IJavaElement.TYPE:
        processTypeDelta((IType) element, changedTypes);
        processChildrenDelta(delta, changedTypes); // (inner types)
        break;/*from w  w w.  j  a  v a 2s.com*/
    case IJavaElement.JAVA_MODEL:
    case IJavaElement.JAVA_PROJECT:
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
    case IJavaElement.PACKAGE_FRAGMENT:
        processChildrenDelta(delta, changedTypes);
        break;
    case IJavaElement.COMPILATION_UNIT:
        ICompilationUnit cu = (ICompilationUnit) element;
        if (cu.getOwner() != null) {
            return;
        }

        if (delta.getKind() == IJavaElementDelta.CHANGED && isPossibleStructuralChange(delta.getFlags())) {
            try {
                if (cu.exists()) {
                    IType[] types = cu.getAllTypes();
                    for (int i = 0; i < types.length; i++) {
                        processTypeDelta(types[i], changedTypes);
                    }
                }
            } catch (JavaModelException e) {
                C4JActivator.log(e);
            }
        } else {
            processChildrenDelta(delta, changedTypes);
        }
        break;
    case IJavaElement.CLASS_FILE:
        if (delta.getKind() == IJavaElementDelta.CHANGED) {
            try {
                IType type = ((IClassFile) element).getType();
                processTypeDelta(type, changedTypes);
            } catch (JavaModelException e) {
                C4JActivator.log(e);
            }
        } else {
            processChildrenDelta(delta, changedTypes);
        }
        break;
    }
}

From source file:net.sourceforge.metrics.ui.layeredpackagegraph.LayeredPackageTableView.java

License:Open Source License

/**
 * @param type//from   w w  w . j a va2 s.  c o m
 * @return true if acceptable type for metrics calculation
 */
private boolean canDoMetrics(IJavaElement element) {
    int type = element.getElementType();
    if (type == IJavaElement.CLASS_FILE) {
        return false;
    }
    if (type == IJavaElement.FIELD) {
        return false;
    }
    if (type == IJavaElement.IMPORT_CONTAINER) {
        return false;
    }
    if (type == IJavaElement.IMPORT_DECLARATION) {
        return false;
    }
    if (type == IJavaElement.INITIALIZER) {
        return false;
    }
    if (type == IJavaElement.PACKAGE_DECLARATION) {
        return false;
    }
    return true;
}