Author: scabanovich
Date: 2010-03-02 09:21:14 -0500 (Tue, 02 Mar 2010)
New Revision: 20564
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMember.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ParametedType.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/TypeDeclaration.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractTypeDefinition.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParametedTypeFactory.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5973
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMember.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMember.java 2010-03-02
14:19:54 UTC (rev 20563)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMember.java 2010-03-02
14:21:14 UTC (rev 20564)
@@ -14,16 +14,12 @@
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.ISourceRange;
-import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.IBeanMember;
import org.jboss.tools.cdi.core.IClassBean;
import org.jboss.tools.cdi.core.IParametedType;
-import org.jboss.tools.cdi.core.ITypeDeclaration;
import org.jboss.tools.cdi.internal.core.impl.definition.BeanMemberDefinition;
-import org.jboss.tools.cdi.internal.core.impl.definition.ParametedTypeFactory;
-import org.jboss.tools.common.model.util.EclipseJavaUtil;
/**
*
@@ -47,7 +43,34 @@
if(returnType != null) {
ParametedType p =
getCDIProject().getNature().getTypeFactory().getParametedType(member.getDeclaringType(),
returnType);
if(p != null) {
- typeDeclaration = new TypeDeclaration(p, -1, 0);
+
+ int offset = -1;
+ int length = 0;
+ String content = getDefinition().getTypeDefinition().getContent();
+ if(content != null) {
+ ISourceRange sr = member.getSourceRange();
+ ISourceRange nr = member.getNameRange();
+ if(sr != null && nr != null && sr.getOffset() < nr.getOffset()
&& nr.getOffset() < content.length()) {
+ String start = content.substring(sr.getOffset(), nr.getOffset());
+ int off = -1;
+ int off0 = -1;
+ for (int i = start.length() - 1; i >= 0; i--) {
+ char ch = start.charAt(i);
+ if(Character.isWhitespace(ch)) {
+ if(off >= 0) break;
+ } else if(Character.isJavaIdentifierPart(ch) || ch == '.' || ch ==
'$' || ch == '<' || ch == '>') {
+ off = i;
+ if(off0 < 0) off0 = i + 1;
+ }
+ }
+ if(off >= 0) {
+ offset = sr.getOffset() + off;
+ length = off0 - off;
+ }
+ }
+ }
+
+ typeDeclaration = new TypeDeclaration(p, offset, length);
}
}
} catch (JavaModelException e) {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java 2010-03-02
14:19:54 UTC (rev 20563)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java 2010-03-02
14:21:14 UTC (rev 20564)
@@ -198,8 +198,16 @@
Set<IParametedType> ps = getDefinition().getInheritedTypes();
Set<ITypeDeclaration> result = new HashSet<ITypeDeclaration>();
for (IParametedType p: ps) {
- result.add(new TypeDeclaration((ParametedType)p, -1, 0));
+ if(p instanceof TypeDeclaration) {
+ result.add((TypeDeclaration)p);
+ }
}
+ IParametedType p = getDefinition().getParametedType();
+ if(p != null) {
+ if(p instanceof TypeDeclaration) {
+ result.add((TypeDeclaration)p);
+ }
+ }
return result;
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ParametedType.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ParametedType.java 2010-03-02
14:19:54 UTC (rev 20563)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ParametedType.java 2010-03-02
14:21:14 UTC (rev 20564)
@@ -16,6 +16,7 @@
import java.util.Set;
import java.util.StringTokenizer;
+import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeParameter;
import org.eclipse.jdt.core.JavaModelException;
@@ -31,6 +32,7 @@
public class ParametedType implements IParametedType {
protected ParametedTypeFactory typeFactory = null;
protected IType type;
+ protected String arrayPrefix = "";
protected String signature;
protected List<ParametedType> parameterTypes = new
ArrayList<ParametedType>();
@@ -39,6 +41,12 @@
protected Set<IParametedType> inheritedTypes = new
HashSet<IParametedType>();
Set<IParametedType> allInheritedTypes = null;
+ public static interface PositionProvider {
+ ISourceRange getRange(String superTypeName);
+ }
+
+ PositionProvider provider = null;
+
public ParametedType() {}
public ParametedTypeFactory getFactory() {
@@ -53,6 +61,10 @@
return type;
}
+ public String getArrayPrefix() {
+ return arrayPrefix;
+ }
+
public String getSignature() {
return signature;
}
@@ -63,12 +75,21 @@
public void setSignature(String signature) {
this.signature = signature;
+ if(signature != null) {
+ for (int i = 0; i < signature.length(); i++) {
+ if(signature.charAt(i) == '[') arrayPrefix += "["; else break;
+ }
+ }
}
public void addParameter(ParametedType p) {
parameterTypes.add(p);
}
+ public void setPositionProvider(PositionProvider p) {
+ provider = p;
+ }
+
public boolean equals(Object object) {
if(!(object instanceof ParametedType)) return false;
ParametedType other = (ParametedType)object;
@@ -85,21 +106,46 @@
try {
if(!type.isInterface() && !type.isAnnotation()) {
String sc = type.getSuperclassTypeSignature();
+ boolean objectArray = false;
if(sc != null) {
sc = resolveParameters(sc);
} else if(!"java.lang.Object".equals(type.getFullyQualifiedName())) {
sc = "QObject;";
+ } else if("java.lang.Object".equals(type.getFullyQualifiedName())
&& arrayPrefix.length() > 0) {
+ objectArray = true;
+ sc = "QObject;";
}
+ if(!objectArray && arrayPrefix.length() > 0) {
+ sc = arrayPrefix + sc;
+ }
+
superType = getFactory().getParametedType(type, sc);
if(superType != null) {
+ if(provider != null) {
+ String scn = type.getSuperclassName();
+ if(scn != null && provider.getRange(scn) != null) {
+ ISourceRange r = provider.getRange(scn);
+ superType = new TypeDeclaration(superType, r.getOffset(), r.getLength());
+ }
+
+ }
inheritedTypes.add(superType);
}
}
String[] is = type.getSuperInterfaceTypeSignatures();
if(is != null) for (int i = 0; i < is.length; i++) {
String p = resolveParameters(is[i]);
+ if(arrayPrefix.length() > 0) p = arrayPrefix + p;
ParametedType t = getFactory().getParametedType(type, p);
if(t != null) {
+ if(provider != null) {
+ String scn = type.getSuperInterfaceNames()[i];
+ if(scn != null && provider.getRange(scn) != null) {
+ ISourceRange r = provider.getRange(scn);
+ t = new TypeDeclaration(t, r.getOffset(), r.getLength());
+ }
+
+ }
inheritedTypes.add(t);
}
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java 2010-03-02
14:19:54 UTC (rev 20563)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java 2010-03-02
14:21:14 UTC (rev 20564)
@@ -43,7 +43,7 @@
public Set<ITypeDeclaration> getAllTypeDeclarations() {
Set<ITypeDeclaration> result = new HashSet<ITypeDeclaration>();
- if(typeDeclaration != null) {
+ if(typeDeclaration != null && typeDeclaration.getStartPosition() > 0) {
result.add(typeDeclaration);
}
return result;
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java 2010-03-02
14:19:54 UTC (rev 20563)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java 2010-03-02
14:21:14 UTC (rev 20564)
@@ -52,7 +52,7 @@
public Set<ITypeDeclaration> getAllTypeDeclarations() {
Set<ITypeDeclaration> result = new HashSet<ITypeDeclaration>();
- if(typeDeclaration != null) {
+ if(typeDeclaration != null && typeDeclaration.getStartPosition() > 0) {
result.add(typeDeclaration);
}
return result;
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/TypeDeclaration.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/TypeDeclaration.java 2010-03-02
14:19:54 UTC (rev 20563)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/TypeDeclaration.java 2010-03-02
14:21:14 UTC (rev 20564)
@@ -10,7 +10,6 @@
******************************************************************************/
package org.jboss.tools.cdi.internal.core.impl;
-import org.eclipse.jdt.core.IType;
import org.jboss.tools.cdi.core.ITypeDeclaration;
/**
@@ -22,13 +21,20 @@
int length;
int startPosition;
- TypeDeclaration(ParametedType type, int startPosition, int length) {
+ public TypeDeclaration(ParametedType type, int startPosition, int length) {
this.setFactory(type.getFactory());
this.type = type.getType();
+ arrayPrefix = type.arrayPrefix;
this.length = length;
this.startPosition = startPosition;
- this.signature = type.signature;
- this.parameterTypes = type.parameterTypes;
+
+ signature = type.signature;
+ parameterTypes = type.parameterTypes;
+
+ allInheritedTypes = type.allInheritedTypes;
+ inheritanceIsBuilt = type.inheritanceIsBuilt;
+ inheritedTypes = type.inheritedTypes;
+ superType = type.superType;
}
public int getLength() {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractTypeDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractTypeDefinition.java 2010-03-02
14:19:54 UTC (rev 20563)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractTypeDefinition.java 2010-03-02
14:21:14 UTC (rev 20564)
@@ -10,15 +10,20 @@
******************************************************************************/
package org.jboss.tools.cdi.internal.core.impl.definition;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.internal.core.SourceRange;
import org.jboss.tools.cdi.core.IParametedType;
import org.jboss.tools.cdi.internal.core.impl.CDIProject;
import org.jboss.tools.cdi.internal.core.impl.ParametedType;
+import org.jboss.tools.cdi.internal.core.impl.TypeDeclaration;
import org.jboss.tools.common.util.FileUtil;
/**
@@ -57,11 +62,25 @@
super.init(contextType, context);
qualifiedName = getType().getFullyQualifiedName();
parametedType = new ParametedType();
+ if(type != null && !type.isBinary()) {
+ ISourceRange r = type.getNameRange();
+ if(r != null) {
+ parametedType = new TypeDeclaration(parametedType, r.getOffset(), r.getLength());
+ }
+ }
parametedType.setFactory(context.getProject().getDelegate().getNature().getTypeFactory());
parametedType.setType(this.type);
parametedType.setSignature("Q" + qualifiedName + ";");
+ if(type != null && !type.isBinary()) {
+ parametedType.setPositionProvider(new PositionProviderImpl());
+ parametedType.getInheritedTypes();
+ }
}
+ public IParametedType getParametedType() {
+ return parametedType;
+ }
+
public Set<IParametedType> getInheritedTypes() {
return parametedType == null ? new HashSet<IParametedType>() :
parametedType.getInheritedTypes();
}
@@ -77,5 +96,46 @@
}
return content;
}
+
+ class PositionProviderImpl implements ParametedType.PositionProvider {
+ Map<String, ISourceRange> map = null;
+ void init() throws CoreException {
+ map = new HashMap<String, ISourceRange>();
+ getContent();
+ if(content == null) return;
+
+ ISourceRange r = type.getNameRange();
+ if(r == null) return;
+ int b = r.getOffset() + r.getLength();
+ int e = content.indexOf('{', b);
+ if(e < 0) e = content.length();
+ String sup = content.substring(b, e);
+ String sc = type.getSuperclassName();
+ if(sc != null) checkRange(b, sup, sc);
+ String[] is = type.getSuperInterfaceNames();
+ if(is != null) for (int i = 0; i < is.length; i++) checkRange(b, sup, is[i]);
+ }
+
+ void checkRange(int offset, String sup, String sc) {
+ int k = sup.indexOf(sc);
+ if(k >= 0) {
+ map.put(sc, new SourceRange(offset + k, sc.length()));
+ }
+ }
+
+ public ISourceRange getRange(String superTypeName) {
+ if(map == null) {
+ try {
+ init();
+ } catch (CoreException e) {
+ //ignore
+ }
+ }
+
+ return map.get(superTypeName);
+ }
+
+ }
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParametedTypeFactory.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParametedTypeFactory.java 2010-03-02
14:19:54 UTC (rev 20563)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParametedTypeFactory.java 2010-03-02
14:21:14 UTC (rev 20564)
@@ -19,11 +19,16 @@
ParametedType result = new ParametedType();
result.setFactory(this);
result.setSignature(typeSignature);
+
+ typeSignature = typeSignature.substring(result.getArrayPrefix().length());
+
int startToken = typeSignature.indexOf('<');
if(startToken < 0) {
String resovedTypeName = EclipseJavaUtil.resolveTypeAsString(context, typeSignature);
if(resovedTypeName == null) return null;
- result.setSignature("Q" + resovedTypeName + ";");
+ if(!context.isBinary()) {
+ result.setSignature(result.getArrayPrefix() + "Q" + resovedTypeName +
";");
+ }
IType type = EclipseJavaUtil.findType(context.getJavaProject(), resovedTypeName);
if(type != null) {
result.setType(type);
@@ -53,7 +58,9 @@
if(newParams.length() > 0) newParams.append(',');
newParams.append(param.getSignature());
}
- result.setSignature("Q" + resovedTypeName + '<' + newParams +
'>' + ';');
+ if(!context.isBinary()) {
+ result.setSignature(result.getArrayPrefix() + "Q" + resovedTypeName +
'<' + newParams + '>' + ';');
+ }
cache.put(key, result);
return result;
}