Java 类org.eclipse.jdt.core.JavaModelException 实例源码

项目:ContentAssist    文件:WorkspaceUtilities.java   
/**
 * Collects all compilation units within the project.
 * @return the collection of the compilation units
 */
public static List<ICompilationUnit> collectAllCompilationUnits() {
    List<ICompilationUnit> units = new ArrayList<ICompilationUnit>();

    try {
        IProject[] projects =  getWorkspace().getRoot().getProjects();
        for (int i = 0; i < projects.length; i++) {
            IJavaProject project = (IJavaProject)JavaCore.create((IProject)projects[i]);

            IPackageFragment[] packages = project.getPackageFragments();
            for (int j = 0; j < packages.length; j++) {

                ICompilationUnit[] cus = packages[j].getCompilationUnits();
                for (int k = 0; k < cus.length; k++) {
                    IResource res = cus[k].getResource();
                    if (res.getType() == IResource.FILE) {
                        String name = cus[k].getPath().toString();
                        if (name.endsWith(".java")) { 
                            units.add(cus[k]);
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }

    return units;
}
项目:pandionj    文件:InvocationWidget.java   
public void setMethod(IMethod method, InvocationAction a) {
    String key = null;
    try {
        IType type = (IType) method.getParent();
        key = type.getFullyQualifiedName() + "|" + method.getElementName() + method.getSignature();
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
    if(key != null) {
        StaticInvocationWidget2 inv = invWidgetsMap.get(key);
        if(inv == null) {
            inv = new StaticInvocationWidget2(this, null, method, a);
            invWidgetsMap.put(key, inv);
        }
        inv.refreshItems();
        layout.topControl = inv;
        layout();
    }
}
项目:pandionj    文件:StaticInvocationWidget.java   
public String getInvocationExpression() {
    String[] values = getValues();
    String[] parameterTypes = method.getParameterTypes();

    for(int i = 0; i < values.length; i++) {
        String pType = Signature.getSignatureSimpleName(parameterTypes[i]);
        values[i] = convertForTypedInvocation(values[i], pType);
    }

    try {
        return (method.isConstructor() ? "new " + method.getElementName() : methodName) + "(" + String.join(", ", values) + ")";
    } catch (JavaModelException e) {
        e.printStackTrace();
        return null;
    }
}
项目:codelens-eclipse    文件:JDTUtils.java   
public static boolean isHiddenGeneratedElement(IJavaElement element) {
    // generated elements are tagged with javax.annotation.Generated and
    // they need to be filtered out
    if (element instanceof IAnnotatable) {
        try {
            IAnnotation[] annotations = ((IAnnotatable) element).getAnnotations();
            if (annotations.length != 0) {
                for (IAnnotation annotation : annotations) {
                    if (isSilencedGeneratedAnnotation(annotation)) {
                        return true;
                    }
                }
            }
        } catch (JavaModelException e) {
            // ignore
        }
    }
    return false;
}
项目:codelens-eclipse    文件:JDTUtils.java   
private static boolean isSilencedGeneratedAnnotation(IAnnotation annotation) throws JavaModelException {
    if ("javax.annotation.Generated".equals(annotation.getElementName())) {
        IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs();
        for (IMemberValuePair m : memberValuePairs) {
            if ("value".equals(m.getMemberName()) && IMemberValuePair.K_STRING == m.getValueKind()) {
                if (m.getValue() instanceof String) {
                    return SILENCED_CODEGENS.contains(m.getValue());
                } else if (m.getValue() instanceof Object[]) {
                    for (Object val : (Object[]) m.getValue()) {
                        if (SILENCED_CODEGENS.contains(val)) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
项目:Equella    文件:JPFClasspathContainer.java   
public static void removeFromProject(IJavaProject javaProject)
{
    try
    {
        Set<IClasspathEntry> entries = new LinkedHashSet<>();
        entries.addAll(Arrays.asList(javaProject.getRawClasspath()));
        if( entries.remove(JavaCore.newContainerEntry(JPFClasspathPlugin.CONTAINER_PATH)) )
        {
            javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);
        }
    }
    catch( JavaModelException e )
    {
        JPFClasspathLog.logError(e);
    }

}
项目:pandionj    文件:InvokeWidget.java   
public void setMethod(IMethod method, InvocationAction a) {
    String key = null;
    try {
        IType type = (IType) method.getParent();
        key = type.getFullyQualifiedName() + "|" + method.getElementName() + method.getSignature();
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
    if(key != null) {
        StaticInvocationWidget2 inv = invWidgetsMap.get(key);
        if(inv == null) {
            inv = new StaticInvocationWidget2(this, null, method, a);
            invWidgetsMap.put(key, inv);
        }
        inv.refreshItems();
        layout.topControl = inv;
        layout();
    }
}
项目:gw4e.project    文件:PreferenceManager.java   
/**
 * @return
 * @throws JavaModelException
 */
public static ClassExtension getDefaultClassExtension(IFile ifile) throws JavaModelException {
    boolean generateExecutionHook = false;
    boolean generatePerformance = false;
    boolean generateElementHook = false;
    boolean generateRunSmokeTest = false;
    boolean generateRunFunctionalTest = false;
    boolean generateRunStabilityTest = false;
    boolean generateModelBased = false;
    String startElement = null;
    String targetVertex = null;
    String startElementForJunitTest = null;
    List<IFile> additionalContexts = new ArrayList<IFile>();

    try {
        String f = ResourceManager.getAbsolutePath(ifile);
        startElement = GraphWalkerFacade.getNextElement(f);
    } catch (Exception e) {
        ResourceManager.logException(e);
    }

    return new ClassExtension(generateExecutionHook, generatePerformance, generateElementHook, generateRunSmokeTest,
            generateRunFunctionalTest, generateRunStabilityTest, targetVertex, startElementForJunitTest,
            additionalContexts, generateModelBased, getDefaultOptionForGraphWalkerAnnotationGeneration(),
            getDefaultPathGenerator(), startElement, getDefaultGroups(), ifile);
}
项目:gw4e.project    文件:ClasspathManager.java   
/**
 * Add GraphWalker libraries to the passed project
 * 
 * @param project
 * @throws JavaModelException
 */
public static void addGW4EClassPathContainer(IProject project) throws JavaModelException {
    if (hasGW4EClassPathContainer(project)) {
        return;
    }
    IJavaProject javaProject = JavaCore.create(project); 
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
    System.arraycopy(entries, 0, newEntries, 0, entries.length);
    Path lcp = new Path(GW4ELibrariesContainer.ID);
    IClasspathEntry libEntry = JavaCore.newContainerEntry(lcp, true);
    newEntries[entries.length] = JavaCore.newContainerEntry(libEntry.getPath(), true);
    javaProject.setRawClasspath(newEntries, null);

    addJunit4Libraries(project);
}
项目:gw4e.project    文件:ClasspathManager.java   
/**
 * Add JUnit libraries to the passed project
 * 
 * @param project
 * @throws JavaModelException
 */
private static void addJunit4Libraries(IProject project) throws JavaModelException {
    IClasspathEntry entry = JavaCore.newContainerEntry(JUnitCore.JUNIT4_CONTAINER_PATH);
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    boolean junitFound = false;
    String s = entry.getPath().toString();
    for (int i = 0; i < entries.length; i++) {
        if (entries[i].getPath().toString().indexOf(s) != -1) {
            junitFound = true;
            break;
        }
    }
    if (!junitFound) {
        IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
        System.arraycopy(entries, 0, newEntries, 0, entries.length);
        newEntries[entries.length] = entry;
        javaProject.setRawClasspath(newEntries, null);
    }
}
项目:visuflow-plugin    文件:BreakpointLocator.java   
/**
 * Copied from org.eclipse.jdt.internal.debug.ui.actions.ToggleBreakpointAdapter
 * TODO: is there a public API to do this?
 *
 * Returns the resolved signature of the given method
 * @param method method to resolve
 * @return the resolved method signature or <code>null</code> if none
 * @throws JavaModelException
 * @since 3.4
 */
public static String resolveMethodSignature(IMethod method) throws JavaModelException {
    String signature = method.getSignature();
    String[] parameterTypes = Signature.getParameterTypes(signature);
    int length = parameterTypes.length;
    String[] resolvedParameterTypes = new String[length];
    for (int i = 0; i < length; i++) {
        resolvedParameterTypes[i] = resolveTypeSignature(method, parameterTypes[i]);
        if (resolvedParameterTypes[i] == null) {
            return null;
        }
    }
    String resolvedReturnType = resolveTypeSignature(method, Signature.getReturnType(signature));
    if (resolvedReturnType == null) {
        return null;
    }
    return Signature.createMethodSignature(resolvedParameterTypes, resolvedReturnType);
}
项目:gw4e.project    文件:JDTManager.java   
/**
 * @param project
 * @param itype
 * @return
 * @throws JavaModelException
 */
public static IPath findPathInModelAnnotation(IProject project, IType itype) throws JavaModelException {
    ICompilationUnit cu = itype.getCompilationUnit();
    List<IAnnotationBinding> annotations = resolveAnnotation(cu, Model.class).getAnnotations();
    if ((annotations != null) && (annotations.size() > 0)) {
        IAnnotationBinding ab = annotations.get(0);
        IMemberValuePairBinding[] attributes = ab.getAllMemberValuePairs();
        for (int i = 0; i < attributes.length; i++) {
            IMemberValuePairBinding attribut = attributes[i];
            if (attribut.getName().equalsIgnoreCase("value")) {
                Object[] o = (Object[]) attribut.getValue();
                if (o != null && o.length > 0 && String.valueOf(o[0]).trim().length() > 0) {
                    try {
                        IPath p = ResourceManager.find(project, String.valueOf(o[0]).trim());
                        return p;
                    } catch (Exception e) {
                        ResourceManager.logException(e);
                        return null;
                    }
                }
            }
        }
    }
    return null;
}
项目:java-debug    文件:JdtSourceLookUpProvider.java   
@Override
public String getSourceFileURI(String fullyQualifiedName, String sourcePath) {
    if (sourcePath == null) {
        return null;
    }

    Object sourceElement = JdtUtils.findSourceElement(sourcePath, getSourceContainers());
    if (sourceElement instanceof IResource) {
        return getFileURI((IResource) sourceElement);
    } else if (sourceElement instanceof IClassFile) {
        try {
            IClassFile file = (IClassFile) sourceElement;
            if (file.getBuffer() != null) {
                return getFileURI(file);
            }
        } catch (JavaModelException e) {
            // do nothing.
        }
    }
    return null;
}
项目:gw4e.project    文件:JDTManager.java   
private static IType getClassesWithAnnotation(ICompilationUnit compilationUnit, Class annotationClass,
        String attributName, boolean valued) throws JavaModelException {
    List<IAnnotationBinding> annotations = resolveAnnotation(compilationUnit, annotationClass).getAnnotations();
    if ((annotations != null) && (annotations.size() > 0)) {
        IAnnotationBinding ab = annotations.get(0);
        IMemberValuePairBinding[] attributes = ab.getAllMemberValuePairs();
        for (int i = 0; i < attributes.length; i++) {
            IMemberValuePairBinding attribut = attributes[i];
            if (attribut.getName().equalsIgnoreCase(attributName)) {
                if (valued) {
                    if (String.valueOf(attribut.getValue()).trim().length() > 0) {
                        return compilationUnit.findPrimaryType();
                    }
                } else {
                    if (String.valueOf(attribut.getValue()).trim().length() == 0) {
                        return compilationUnit.findPrimaryType();
                    }
                }
            }
        }
    }
    return null;
}
项目:gw4e.project    文件:JDTManager.java   
/**
 * @param projectName
 * @return
 * @throws JavaModelException
 */
private static List<IType> findClassesWithAnnotation(String projectName, Class annotationClass, String attributName,
        boolean valued) throws JavaModelException {
    List<IType> classList = new ArrayList<IType>();
    IProject project = ResourceManager.getProject(projectName);
    IJavaProject javaProject = JavaCore.create(project);
    IPackageFragment[] packages = javaProject.getPackageFragments();
    for (IPackageFragment packageFragment : packages) {
        for (final ICompilationUnit compilationUnit : packageFragment.getCompilationUnits()) {
            if (compilationUnit.exists()) {
                IType type = getClassesWithAnnotation(compilationUnit, annotationClass, attributName, valued);
                if (type != null)
                    classList.add(type);
            }
        }
    }
    return classList;
}
项目:gw4e.project    文件:JDTManager.java   
/**
 * @param testInterface
 * @return
 * @throws JavaModelException
 */
public static boolean isGraphWalkerExecutionContextClass(ICompilationUnit unit) throws JavaModelException {
    IType[] types = unit.getAllTypes();

    if (types == null || types.length == 0) {
        ResourceManager.logInfo(unit.getJavaProject().getProject().getName(),
                "getAllTypes return null" + unit.getPath());
        return false;
    }
    IType execContextType = unit.getJavaProject().findType(ExecutionContext.class.getName());

    for (int i = 0; i < types.length; i++) {
        IType type = types[i];
        String typeNname = type.getFullyQualifiedName();
        String compilationUnitName = JDTManager.getJavaFullyQualifiedName(unit);
        if (typeNname.equals(compilationUnitName)) {
            try {
                ITypeHierarchy th = types[0].newTypeHierarchy(new NullProgressMonitor());
                return th.contains(execContextType);
            } catch (Exception e) {
                ResourceManager.logException(e);
            }
        }
    }
    return false;
}
项目:pandionj    文件:StaticInvocationWidget.java   
private void addRefCombovalues(Combo combo, String paramType) {
    if(!PrimitiveType.isPrimitiveSig(paramType)) {
        combo.add("null");
        IType owner = (IType) method.getParent();
        try {
            IField[] fields = owner.getFields();
            for(IField f : fields)
                if(Flags.isStatic(f.getFlags()) && f.getTypeSignature().equals(paramType))
                    combo.add(f.getElementName());


        } catch (JavaModelException e1) {
            e1.printStackTrace();
        }
    }
}
项目:gw4e.project    文件:GraphWalkerContextManager.java   
public static IJavaProject[] getGW4EProjects() {
    IJavaProject[] projects;
    try {
        projects = JavaCore.create(ResourceManager.getWorkspaceRoot()).getJavaProjects();
    } catch (JavaModelException e) {
        ResourceManager.logException(e);
        projects = new IJavaProject[0];
    }
    List<IJavaProject> gwps = new ArrayList<IJavaProject>();
    for (int i = 0; i < projects.length; i++) {
        if (GW4ENature.hasGW4ENature(projects[i].getProject())) {
            gwps.add(projects[i]);
        }
    }

    IJavaProject[] gwprojects = new IJavaProject[gwps.size()];
    gwps.toArray(gwprojects);
    return gwprojects;
}
项目:gw4e.project    文件:GraphWalkerFacade.java   
/**
 * @param filtered
 * @param main
 * @param candidates
 * @throws IOException
 * @throws JavaModelException
 */
private static void findSharedContexts(List<Context> filtered, Context main, List<Context> candidates)
        throws IOException, JavaModelException {
    List<Context> newCandidates = new ArrayList<Context>();
    Set<String> sharedStates = main.getModel().getSharedStates();
    for (String shared : sharedStates) {
        for (Context context : candidates) {
            if (context.equals(main))
                continue;
            List<RuntimeVertex> states = context.getModel().getSharedStates(shared);
            if (states != null) {
                if (!filtered.contains(context)) {
                    newCandidates.add(context);
                    filtered.add(context);
                }
            }
        }
    }
    for (Context c : newCandidates) {
        findSharedContexts(filtered, c, candidates);
    }
}
项目:gw4e.project    文件:ResourceManager.java   
/**
 * Return a path relative to its package fragment root
 * 
 * @param project
 * @param path
 * @return
 * @throws JavaModelException
 */
public static IPath getPathWithinPackageFragment(IResource ifile) throws JavaModelException {
    IProject project = ifile.getProject();
    IPath path = ifile.getFullPath();
    String[] segments = path.segments();
    IJavaProject jproject = JavaCore.create(project);
    IPackageFragment[] pkgs = jproject.getPackageFragments();
    IPath p = new Path("/");
    for (int i = 0; i < segments.length; i++) {
        for (int j = 0; j < pkgs.length; j++) {
            if (pkgs[j].getPath().equals(p)) {
                IPath ret = path.makeRelativeTo(pkgs[j].getPath());
                return ret;
            }
        }
        p = p.append(segments[i]);
    }
    return null;
}
项目:pandionj    文件:ObjectModel.java   
public List<IMethod> getInstanceMethods() {
    if(jType == null)
        return Collections.emptyList();

    try {
        List<IMethod> list = new ArrayList<>();
        IMethod[] methods = jType.getMethods();
        for(IMethod m : methods)

            if(!m.isConstructor() && !Flags.isStatic(m.getFlags()) && isMethodVisible(m))
                list.add(m);
        return list;
    } catch (JavaModelException e) {
        e.printStackTrace();
        return Collections.emptyList();
    }
    //      return info.getMethods(EnumSet.of(VisibilityInfo.PUBLIC));
}
项目:gw4e.project    文件:GW4EProject.java   
public void assertHasSourceFolders(String[] folders) throws JavaModelException {
    IProject project = getRoot().getProject(this.projectName);
    IJavaProject jproject = JavaCore.create(project);
    IPackageFragmentRoot[] pkgs = jproject.getPackageFragmentRoots();

    for (int i = 0; i < folders.length; i++) {
        String folder = folders[i];
        boolean found = false;
        for (int j = 0; j < pkgs.length; j++) {
            IPackageFragmentRoot pkg = pkgs[j];
            IPath path = new Path("/").append(this.projectName).append(folder);
            if (pkg.getPath().toString().equalsIgnoreCase(path.toString())) {
                found = true;
            }
            ;
        }
        assertTrue("Expected folder: " + folder, found);
    }
}
项目:java-debug    文件:JdtSourceLookUpProvider.java   
private String getContents(IClassFile cf) {
    String source = null;
    if (cf != null) {
        try {
            IBuffer buffer = cf.getBuffer();
            if (buffer != null) {
                source = buffer.getContents();
            }
        } catch (JavaModelException e) {
            logger.log(Level.SEVERE, String.format("Failed to parse the source contents of the class file: %s", e.toString()), e);
        }
        if (source == null) {
            source = "";
        }
    }
    return source;
}
项目:Hydrograph    文件:BuildExpressionEditorDataSturcture.java   
public void createClassRepo(String jarFileName, String Package) {
    ClassRepo.INSTANCE.flusRepo();
    try {
        IPackageFragmentRoot iPackageFragmentRoot = getIPackageFragment(jarFileName);
        if (iPackageFragmentRoot != null) {
            IPackageFragment fragment = iPackageFragmentRoot.getPackageFragment(Package);
            if (fragment != null) {
                for (IClassFile element : fragment.getClassFiles()) {
                    ClassRepo.INSTANCE.addClass(element,"","",false);
                }
            } else {
                new CustomMessageBox(SWT.ERROR, Package + " Package not found in jar "
                        + iPackageFragmentRoot.getElementName(), "ERROR").open();
            }
        }
    } catch (JavaModelException e) {
        LOGGER.error("Error occurred while loading class from jar {}", jarFileName, e);
    }
    loadClassesFromSettingsFolder();
}
项目:pandionj    文件:ObjectModel.java   
private boolean isMethodVisible(IMethod m) {
        try {
            int f = m.getFlags();
            return  extension.includeMethod(m.getElementName()) && !jType.isMember() && isVisibleMember(m);
//                  (
//                          !jType.isMember() && jType.getPackageFragment().isDefaultPackage() && 
//                          (Flags.isPackageDefault(f) || Flags.isProtected(f) || Flags.isPublic(f))
//                          ||
//                          Flags.isPublic(f)
//                          );
        }
        catch (JavaModelException e) {
            e.printStackTrace();
            return false;
        }
    }
项目:Hydrograph    文件:ExpressionEditorUtil.java   
/**
 * This method validates the given expression and updates the expression-editor's datasturcture accordingly
 * 
 * @param expressionText
 * @param inputFields
 * @param expressionEditorData
 */
public static void validateExpression(String expressionText,Map<String, Class<?>> inputFields,ExpressionEditorData expressionEditorData ) {
    if(BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject()!=null){
    DiagnosticCollector<JavaFileObject> diagnosticCollector = null;
    try {
        inputFields.putAll(expressionEditorData.getExtraFieldDatatypeMap());
        diagnosticCollector = ValidateExpressionToolButton
                .compileExpresion(expressionText,inputFields,expressionEditorData.getComponentName());
        if (diagnosticCollector != null && !diagnosticCollector.getDiagnostics().isEmpty()) {
            for (Diagnostic<?> diagnostic : diagnosticCollector.getDiagnostics()) {
                if (StringUtils.equals(diagnostic.getKind().name(), Diagnostic.Kind.ERROR.name())) {
                    expressionEditorData.setValid(false);
                    return;
                }
            }
        }
    } catch (JavaModelException | InvocationTargetException | ClassNotFoundException | MalformedURLException
            | IllegalAccessException | IllegalArgumentException e) {
        expressionEditorData.setValid(false);
        return;
    }
    expressionEditorData.setValid(true);
    }
}
项目:Hydrograph    文件:ClassDetails.java   
public ClassDetails(IClassFile classFile, String jarFileName, String packageName, boolean isUserDefined) {
    LOGGER.debug("Extracting methods from "+classFile.getElementName());

    try {
        this.javaDoc=getJavaDoc(classFile); 
        intialize(classFile,jarFileName,packageName, isUserDefined);
        for (IJavaElement iJavaElement : classFile.getChildren()) {
            if (iJavaElement instanceof IType) {
                IType iType = (IType) iJavaElement;
                for (IMethod iMethod : iType.getMethods()) {
                    addMethodsToClass(iMethod);
                }
            }
        }
    } catch (JavaModelException e) {
        LOGGER.error("Error occurred while fetching methods from class"+cName);
    }
}
项目:Hydrograph    文件:ClassDetails.java   
public ClassDetails(SourceType javaClassFile, String jarFileName, String packageName, boolean isUserDefined) {
    Logger LOGGER = LogFactory.INSTANCE.getLogger(ClassDetails.class);
    LOGGER.debug("Extracting methods from " + cName);

    try {
        this.javaDoc=getJavaDoc(javaClassFile);         
        intialize(javaClassFile, jarFileName, packageName, isUserDefined);
        for (IJavaElement iJavaElement : javaClassFile.getChildren()) {
            if (iJavaElement instanceof SourceMethod) {
                addMethodsToClass((IMethod) iJavaElement);
            }
        }
    } catch (JavaModelException e) {
        LOGGER.error("Error occurred while fetching methods from class" + cName);
    }
}
项目:Hydrograph    文件:ELTOpenFileEditorListener.java   
private void openInbuiltOperationClass(String operationName, PropertyDialogButtonBar propertyDialogButtonBar) {
    String operationClassName = null;
    Operations operations = XMLConfigUtil.INSTANCE.getComponent(FilterOperationClassUtility.INSTANCE.getComponentName())
            .getOperations();
    List<TypeInfo> typeInfos = operations.getStdOperation();
    for (int i = 0; i < typeInfos.size(); i++) {
        if (typeInfos.get(i).getName().equalsIgnoreCase(operationName)) {
            operationClassName = typeInfos.get(i).getClazz();
            break;
        }
    }
    propertyDialogButtonBar.enableApplyButton(true);
    javaProject = FilterOperationClassUtility.getIJavaProject();
    if (javaProject != null) {
        try {
            IType findType = javaProject.findType(operationClassName);
            JavaUI.openInEditor(findType);
        } catch (JavaModelException | PartInitException e) {
            Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,Messages.CLASS_NOT_EXIST,null);
            StatusManager.getManager().handle(status, StatusManager.BLOCK);
            logger.error(e.getMessage(), e);
        }
    } else {
        WidgetUtility.errorMessage(Messages.SAVE_JOB_MESSAGE);
    }
}
项目:vertigo-chroma-kspplugin    文件:ServiceManager.java   
/**
 * Parse un fichier candidat de service métier.
 * 
 * @param document Document du service métier.
 * @param javaProject Projet Java du service.
 * @return Le service, <code>null</code> sinon.
 */
private ServiceFile createServiceFile(IFile file, IJavaProject javaProject) {
    /* Charge l'AST du fichier Java. */
    ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(file, javaProject);
    if (compilationUnit == null) {
        return null;
    }
    List<ServiceImplementation> serviceImplementations = new ArrayList<>();
    try {
        /* Parcourt les types du fichier Java. */
        for (IType type : compilationUnit.getAllTypes()) {
            handleType(type, file, serviceImplementations);
        }
    } catch (JavaModelException e) {
        ErrorUtils.handle(e);
    }

    /* Créé le fichier de service. */
    return new ServiceFile(serviceImplementations);
}
项目:vertigo-chroma-kspplugin    文件:WsRouteManager.java   
/**
 * Parse un fichier candidat de webservice.
 * 
 * @param file Fichier du webservice.
 * @param javaProject Projet Java du fichier.
 * @return Le webservice, <code>null</code> sinon.
 */
private WsFile createWsFile(IFile file, IJavaProject javaProject) {
    /* Charge l'AST du fichier Java. */
    ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(file, javaProject);
    if (compilationUnit == null) {
        return null;
    }
    List<WsRoute> wsRoutes = new ArrayList<>();
    try {
        /* Parcourt les types du fichier Java. */
        for (IType type : compilationUnit.getAllTypes()) {
            handleType(type, file, wsRoutes);
        }
    } catch (JavaModelException e) {
        ErrorUtils.handle(e);
    }

    /* Créé le fichier de webservice. */
    return new WsFile(file, wsRoutes);
}
项目:vertigo-chroma-kspplugin    文件:DaoManager.java   
/**
 * Parse un fichier candidat de DAO/PAO.
 * 
 * @param file Fichier.
 * @param javaProject Projet Java du fichier.
 * @return Le DAO, <code>null</code> sinon.
 */
private DaoFile createDaoFile(IFile file, IJavaProject javaProject) {
    /* Charge l'AST du fichier Java. */
    ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(file, javaProject);
    if (compilationUnit == null) {
        return null;
    }
    List<DaoImplementation> daoImplementations = new ArrayList<>();
    try {
        /* Parcourt les types du fichier Java. */
        for (IType type : compilationUnit.getAllTypes()) {
            handleType(type, file, daoImplementations);
        }
    } catch (JavaModelException e) {
        ErrorUtils.handle(e);
    }

    /* Créé le fichier de DAO/PAO. */
    String daoName = StringUtils.removeExtension(compilationUnit.getElementName());
    return new DaoFile(daoName, file, daoImplementations);
}
项目:vertigo-chroma-kspplugin    文件:DaoManager.java   
private void handleType(IType type, IFile file, List<DaoImplementation> daoImplementations) throws JavaModelException {
    /* Parcourt les méthodes. */
    for (IMethod method : type.getMethods()) {
        /* Filtre pour ne garder que les méthodes publiques d'instance */
        if (method.isConstructor() || Flags.isStatic(method.getFlags()) || Flags.isPrivate(method.getFlags())) {
            continue;
        }

        /* Créé le DaoImplementation. */
        String javaName = method.getElementName();
        ISourceRange nameRange = method.getNameRange();
        FileRegion fileRegion = new FileRegion(file, nameRange.getOffset(), nameRange.getLength());
        DaoImplementation daoImplementation = new DaoImplementation(fileRegion, javaName);
        daoImplementations.add(daoImplementation);
    }
}
项目:vertigo-chroma-kspplugin    文件:DtoUtils.java   
private static void parseVertigoDtoField(IMethod method, List<DtoField> fields) {
    try {
        if (method.isConstructor() || !Flags.isPublic(method.getFlags())) {
            return;
        }
        IAnnotation fieldAnnotation = JdtUtils.getAnnotation(method, FIELD_ANNOTATION_NAME);
        if (fieldAnnotation == null) {
            return;
        }
        String domain = (String) JdtUtils.getMemberValue(fieldAnnotation, DOMAIN_FIELD_NAME);

        /* Cas d'un champ de composition DTO/DTC : on filtre. */
        if (domain == null || domain.startsWith(DTO_DOMAIN_PREFIX)) {
            return;
        }

        String constantCaseName = StringUtils.toConstantCase(KspStringUtils.getFieldNameFromGetter(method.getElementName()));
        String label = (String) JdtUtils.getMemberValue(fieldAnnotation, LABEL_FIELD_NAME);
        Boolean persistent = (Boolean) JdtUtils.getMemberValue(fieldAnnotation, PERSISTENT_FIELD_NAME);

        DtoField field = new DtoField(constantCaseName, label, domain, persistent);
        fields.add(field);
    } catch (JavaModelException e) {
        ErrorUtils.handle(e);
    }
}
项目:pandionj    文件:StaticInvocationWidget.java   
public StaticInvocationWidget(Composite parent, InvokeDialog invokeDialog, IMethod method, InvocationAction action) {
    super(parent, SWT.NONE);
    this.invokeDialog = invokeDialog;

    this.method = method;

    setLayout(rowLayout);

    methodName = method.getElementName();
    parameterTypes = method.getParameterTypes();
    Label label = new Label(this, SWT.NONE);
    FontManager.setFont(label, PandionJConstants.VAR_FONT_SIZE);
    label.setText(method.getElementName() + " (");
    paramBoxes = new Combo[method.getNumberOfParameters()];
    String[] parameterNames = null;
    try {
        parameterNames = method.getParameterNames();
    } catch (JavaModelException e1) {
        e1.printStackTrace();
    }
    for(int i = 0; i < parameterTypes.length; i++) {
        if(i != 0) {
            Label comma = new Label(this, SWT.NONE);
            FontManager.setFont(comma, PandionJConstants.VAR_FONT_SIZE);
            comma.setText(", ");
        }
        paramBoxes[i] = createCombo(invokeDialog, parameterNames[i], parameterTypes[i]);
    }
    Label close = new Label(this, SWT.NONE);
    FontManager.setFont(close, PandionJConstants.VAR_FONT_SIZE);
    close.setText(")");

    addCacheValues(paramBoxes);
    checkValidity();
}
项目:bdf2    文件:ExportToJavaBeanWizardPage.java   
protected IPackageFragment choosePackage() {
    IPackageFragmentRoot froot = getPackageFragmentRoot();
    IJavaElement[] packages = null;
    try {
        if (froot != null && froot.exists()) {
            packages = froot.getChildren();
        }
    } catch (JavaModelException e) {
        JavaPlugin.log(e);
    }
    if (packages == null) {
        packages = new IJavaElement[0];
    }

    ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new JavaElementLabelProvider(
            JavaElementLabelProvider.SHOW_DEFAULT));
    dialog.setIgnoreCase(false);
    dialog.setTitle(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_title);
    dialog.setMessage(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_description);
    dialog.setEmptyListMessage(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_empty);
    dialog.setElements(packages);
    dialog.setHelpAvailable(false);
    if (dialog.open() == Window.OK) {
        return (IPackageFragment) dialog.getFirstResult();
    }
    return null;
}
项目:codelens-eclipse    文件:JavaCodeLensProvider.java   
private List<Location> findImplementations(IType type, IProgressMonitor monitor) throws JavaModelException {
    IType[] results = type.newTypeHierarchy(monitor).getAllSubtypes(type);
    final List<Location> result = new ArrayList<>();
    for (IType t : results) {
        ICompilationUnit compilationUnit = (ICompilationUnit) t.getAncestor(IJavaElement.COMPILATION_UNIT);
        if (compilationUnit == null) {
            continue;
        }
        Location location = null; // JDTUtils.toLocation(t);
        result.add(location);
    }
    return result;
}
项目:vertigo-chroma-kspplugin    文件:JdtUtils.java   
/**
 * Indique si le type donné est un DtObject Vertigo.
 * 
 * @param type Type JDT.
 * @return <code>true</code> si le type est un DtObject.
 */
public static boolean isVertigoDtoType(IType type) {
    try {
        /* Vérifie que c'est une classe publique final. */
        if (!type.isClass() || !Flags.isPublic(type.getFlags()) || !Flags.isFinal(type.getFlags())) {
            return false;
        }
        /* Vérifie les interfaces. */
        return hasVertigoDtoTypeInterface(type);
    } catch (JavaModelException e) {
        ErrorUtils.handle(e);
    }
    return false;
}
项目:codelens-eclipse    文件:JDTUtils.java   
public static Range toRange(IOpenable openable, int offset, int length) throws JavaModelException {
    if (offset > 0 || length > 0) {
        int[] loc = null;
        int[] endLoc = null;
        IBuffer buffer = openable.getBuffer();
        // if (buffer != null) {
        // loc = JsonRpcHelpers.toLine(buffer, offset);
        // endLoc = JsonRpcHelpers.toLine(buffer, offset + length);
        // }
        // if (loc == null) {
        // loc = new int[2];
        // }
        // if (endLoc == null) {
        // endLoc = new int[2];
        // }
        // setPosition(range.getStart(), loc);
        // setPosition(range.getEnd(), endLoc);
        IDocument document = toDocument(buffer);
        try {
            int line = document.getLineOfOffset(offset);
            int column = offset - document.getLineOffset(line);
            return new Range(line + 1, column + 1);
        } catch (BadLocationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    // TODO Auto-generated method stub
    return null;
}
项目:codelens-eclipse    文件:JDTUtils.java   
public static IJavaElement findElementAtSelection(ITypeRoot unit, int line, int column)
        throws JavaModelException, BadLocationException {
    IJavaElement[] elements = findElementsAtSelection(unit, line, column);
    if (elements != null && elements.length == 1) {
        return elements[0];
    }
    return null;
}