当前位置: 首页>>代码示例>>Java>>正文


Java JavaModelException类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.JavaModelException的典型用法代码示例。如果您正苦于以下问题:Java JavaModelException类的具体用法?Java JavaModelException怎么用?Java JavaModelException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JavaModelException类属于org.eclipse.jdt.core包,在下文中一共展示了JavaModelException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addJunit4Libraries

import org.eclipse.jdt.core.JavaModelException; //导入依赖的package包/类
/**
 * 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);
	}
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:26,代码来源:ClasspathManager.java

示例2: collectAllCompilationUnits

import org.eclipse.jdt.core.JavaModelException; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:liaoziyang,项目名称:ContentAssist,代码行数:34,代码来源:WorkspaceUtilities.java

示例3: setMethod

import org.eclipse.jdt.core.JavaModelException; //导入依赖的package包/类
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();
	}
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:20,代码来源:InvocationWidget.java

示例4: getInvocationExpression

import org.eclipse.jdt.core.JavaModelException; //导入依赖的package包/类
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;
	}
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:17,代码来源:StaticInvocationWidget.java

示例5: isHiddenGeneratedElement

import org.eclipse.jdt.core.JavaModelException; //导入依赖的package包/类
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;
}
 
开发者ID:angelozerr,项目名称:codelens-eclipse,代码行数:20,代码来源:JDTUtils.java

示例6: isSilencedGeneratedAnnotation

import org.eclipse.jdt.core.JavaModelException; //导入依赖的package包/类
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;
}
 
开发者ID:angelozerr,项目名称:codelens-eclipse,代码行数:20,代码来源:JDTUtils.java

示例7: removeFromProject

import org.eclipse.jdt.core.JavaModelException; //导入依赖的package包/类
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);
	}

}
 
开发者ID:equella,项目名称:Equella,代码行数:18,代码来源:JPFClasspathContainer.java

示例8: getDefaultClassExtension

import org.eclipse.jdt.core.JavaModelException; //导入依赖的package包/类
/**
 * @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);
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:30,代码来源:PreferenceManager.java

示例9: addGW4EClassPathContainer

import org.eclipse.jdt.core.JavaModelException; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:22,代码来源:ClasspathManager.java

示例10: resolveMethodSignature

import org.eclipse.jdt.core.JavaModelException; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:VisuFlow,项目名称:visuflow-plugin,代码行数:28,代码来源:BreakpointLocator.java

示例11: findPathInModelAnnotation

import org.eclipse.jdt.core.JavaModelException; //导入依赖的package包/类
/**
 * @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;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:31,代码来源:JDTManager.java

示例12: getSourceFileURI

import org.eclipse.jdt.core.JavaModelException; //导入依赖的package包/类
@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;
}
 
开发者ID:Microsoft,项目名称:java-debug,代码行数:22,代码来源:JdtSourceLookUpProvider.java

示例13: getClassesWithAnnotation

import org.eclipse.jdt.core.JavaModelException; //导入依赖的package包/类
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;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:24,代码来源:JDTManager.java

示例14: findClassesWithAnnotation

import org.eclipse.jdt.core.JavaModelException; //导入依赖的package包/类
/**
 * @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;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:23,代码来源:JDTManager.java

示例15: isGraphWalkerExecutionContextClass

import org.eclipse.jdt.core.JavaModelException; //导入依赖的package包/类
/**
 * @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;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:31,代码来源:JDTManager.java


注:本文中的org.eclipse.jdt.core.JavaModelException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。