List of usage examples for org.eclipse.jdt.core IMethod getType
IType getType(String name, int occurrenceCount);
From source file:org.eclipse.objectteams.otdt.tests.otmodel.anonymousinnerclass.rolelevel.internal.LocalClassTest.java
License:Open Source License
public void testExistenceOfAnonymousType() throws JavaModelException { assertNotNull(_roleJavaElem);/*w ww . j av a 2 s . c o m*/ assertTrue(_roleJavaElem.exists()); IMethod rolelevelMethod = _roleJavaElem.getMethod(METHOD_NAME, new String[0]); assertNotNull(rolelevelMethod); assertTrue(rolelevelMethod.exists()); IType anonymousType = rolelevelMethod.getType("", 1); assertNotNull(anonymousType); assertTrue(anonymousType.exists()); }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.anonymousinnerclass.rolelevel.internal.LocalClassTest.java
License:Open Source License
protected IType getAnonymousType() throws JavaModelException { IType methodOwner = _roleJavaElem;//from w w w .j ava 2s . c o m if ((methodOwner != null) && (methodOwner.exists())) { IMethod enclosingMethod = methodOwner.getMethod(METHOD_NAME, new String[0]); if ((enclosingMethod != null) && (enclosingMethod.exists())) { IType anonymousType = enclosingMethod.getType("", 1); if ((anonymousType != null) && (anonymousType.exists())) { return anonymousType; } } } return null; }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.anonymousinnerclass.teamlevel.Test2.java
License:Open Source License
public void testExistenceOfAnonymousType() throws JavaModelException { assertNotNull(_teamJavaElem);/*from www . ja v a 2 s . c o m*/ assertTrue(_teamJavaElem.exists()); IMethod teamlevelMethod = _teamJavaElem.getMethod("teamlevelMethod", new String[0]); assertNotNull(teamlevelMethod); assertTrue(teamlevelMethod.exists()); IType anonymousType = teamlevelMethod.getType("", 1); assertNotNull(anonymousType); assertTrue(anonymousType.exists()); }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.anonymousinnerclass.teamlevel.Test2.java
License:Open Source License
private IType getAnonymousType() throws JavaModelException { if ((_teamJavaElem != null) && (_teamJavaElem.exists())) { IMethod teamlevelMethod = _teamJavaElem.getMethod("teamlevelMethod", new String[0]); if ((teamlevelMethod != null) && (teamlevelMethod.exists())) { IType anonymousType = teamlevelMethod.getType("", 1); if ((anonymousType != null) && (anonymousType.exists())) { return anonymousType; }//from w w w. ja v a 2 s . c o m } } return null; }
From source file:org.eclipse.pde.api.tools.internal.builder.AbstractIllegalTypeReference.java
License:Open Source License
@Override protected Position getSourceRange(IType type, IDocument doc, IReference reference) throws CoreException, BadLocationException { IApiMember member = reference.getMember(); if (member.getType() == IApiElement.TYPE) { ApiType ltype = (ApiType) member; IMethod method = null; if (ltype.isAnonymous()) { // has a side-effect on // reference.getMember().setEnclosingMethodInfo(..) getEnclosingMethod(type, reference, doc); if (reference.getLineNumber() < 0) { return defaultSourcePosition(type, reference); }/*ww w . jav a 2 s .c o m*/ String name = getSimpleTypeName(reference.getResolvedReference()); Position pos = getMethodNameRange(true, name, doc, reference); if (pos == null) { return defaultSourcePosition(type, reference); } return pos; } if (ltype.isLocal()) { String name = ltype.getSimpleName(); ICompilationUnit cunit = type.getCompilationUnit(); if (cunit.isWorkingCopy()) { cunit.reconcile(AST.JLS8, false, null, null); } IType localtype = type; method = getEnclosingMethod(type, reference, doc); if (method != null) { localtype = method.getType(name, 1); } if (localtype.exists()) { ISourceRange range = localtype.getNameRange(); return new Position(range.getOffset(), range.getLength()); } return defaultSourcePosition(type, reference); } } ISourceRange range = type.getNameRange(); Position pos = null; if (range != null) { pos = new Position(range.getOffset(), range.getLength()); } if (pos == null) { return defaultSourcePosition(type, reference); } return pos; }
From source file:org.eclipse.pde.api.tools.internal.builder.AbstractProblemDetector.java
License:Open Source License
/** * Tries to find the given {@link IApiType} in the given {@link IType}. If * no match is found <code>null</code> is returned. * /*from ww w . j a va2 s . c o m*/ * @param type * @param apitype * @param reference * @param doc * @return the matching {@link IType} or <code>null</code> * @since 1.0.600 * @throws CoreException * @throws JavaModelException */ protected IType findTypeInType(IType type, IApiType apitype, IReference reference, IDocument doc) throws CoreException, JavaModelException { if (apitype.isLocal()) { String name = apitype.getSimpleName(); ICompilationUnit cunit = type.getCompilationUnit(); if (cunit.isWorkingCopy()) { cunit.reconcile(AST.JLS8, false, null, null); } IMethod method = getEnclosingMethod(type, reference, doc); if (method != null) { return method.getType(name, 1); } } String tname = type.getElementName(); if (tname.equals(apitype.getName()) || tname.equals(apitype.getSimpleName())) { return type; } IType match = null; IType[] types = type.getTypes(); for (int i = 0; i < types.length; i++) { if ((types[i].getElementName().equals(apitype.getName()))) { match = types[i]; break; } } return match; }
From source file:org.eclipse.pde.api.tools.internal.builder.IllegalExtendsProblemDetector.java
License:Open Source License
protected Position getSourceRange(IType type, IDocument doc, IReference reference) throws CoreException, BadLocationException { ApiType ltype = (ApiType) reference.getMember(); IMethod method = null; if (ltype.isAnonymous()) { // has a side-effect on reference.getMember().setEnclosingMethodInfo(..) getEnclosingMethod(type, reference, doc); if (reference.getLineNumber() < 0) { return defaultSourcePosition(type, reference); }/*from w w w . java 2s. co m*/ String name = getSimpleTypeName(reference.getResolvedReference()); Position pos = getMethodNameRange(true, name, doc, reference); if (pos == null) { return defaultSourcePosition(type, reference); } return pos; } if (ltype.isLocal()) { String name = ltype.getSimpleName(); ICompilationUnit cunit = type.getCompilationUnit(); if (cunit.isWorkingCopy()) { cunit.reconcile(AST.JLS4, false, null, null); } IType localtype = type; method = getEnclosingMethod(type, reference, doc); if (method != null) { localtype = method.getType(name, 1); } if (localtype.exists()) { ISourceRange range = localtype.getNameRange(); return new Position(range.getOffset(), range.getLength()); } return defaultSourcePosition(type, reference); } return super.getSourceRange(type, doc, reference); }