本文整理匯總了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);
}
}
示例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;
}
示例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();
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}