import org.eclipse.jface.text.contentassist.CompletionProposal; import org.eclipse.swt.graphics.Image; import java.util.Comparator; aspect JastAddJCompletion { eq ClassDecl.completionComment() = javaDocComment(); eq MethodDecl.completionComment() = javaDocComment(); eq FieldDeclaration.completionComment() = javaDocComment(); eq ClassDecl.completionLabel() = name(); eq InterfaceDecl.completionLabel() = name(); eq FieldDeclaration.completionLabel() = name() + " : " + type().typeName(); eq MethodDecl.completionLabel() { StringBuffer res = new StringBuffer(); res.append(" " + name() + "("); for (int i = 0; i < getNumParameter(); i++) { res.append(getParameter(i).type().typeName() + " " + getParameter(i).name()); if (i != 0) { res.append(","); } } res.append(") : " + type().typeName()); return res.toString(); } eq ConstructorDecl.completionLabel() { StringBuffer res = new StringBuffer(); res.append(" " + name() + "("); for (int i = 0; i < getNumParameter(); i++) { res.append(getParameter(i).type().typeName() + " " + getParameter(i).name()); if (i != 0) { res.append(","); } } res.append(")"); return res.toString(); } eq ClassDecl.completionProposal() = name(); eq InterfaceDecl.completionProposal() = name(); eq FieldDeclaration.completionProposal() = name(); eq MethodDecl.completionProposal() { StringBuffer res = new StringBuffer(); res.append(name() + "("); res.append(")"); return res.toString(); } eq ConstructorDecl.completionProposal() { StringBuffer res = new StringBuffer(); res.append(name() + "("); res.append(")"); return res.toString(); } eq MethodDecl.completionProposalOffset() { if (getNumParameter() > 0) { return name().length() + 1; } return super.completionProposalOffset(); } eq ConstructorDecl.completionProposalOffset() { if (getNumParameter() > 0) { return name().length() + 1; } return super.completionProposalOffset(); } eq Access.completion(String filter) { ArrayList list = new ArrayList(); for(Iterator iter = visibleDecls().iterator(); iter.hasNext(); ) { ASTNode node = (ASTNode)iter.next(); if (node.completionProposal().startsWith(filter)) { list.add(node); } } java.util.Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { if (o1 instanceof ASTNode && o2 instanceof ASTNode) { ASTNode node1 = (ASTNode)o1; ASTNode node2 = (ASTNode)o2; if ((node1 instanceof FieldDeclaration && node2 instanceof FieldDeclaration) || (node1 instanceof MethodDecl && node2 instanceof MethodDecl) || (node1 instanceof TypeDecl && node2 instanceof TypeDecl)) { return node1.completionLabel().compareTo(node2.completionLabel()); } // FieldDeclaration < (MethodDecl || TypeDecl) -- Always smaller if (node1 instanceof FieldDeclaration) { return -1; } // TypeDecl > (MethodDecl || FieldDeclaration) -- Always bigger else if (node1 instanceof TypeDecl) { return 1; } // MethodDecl > FieldDeclaration -- Bigger else if (node1 instanceof MethodDecl && node2 instanceof FieldDeclaration) { return 1; } // MethodDecl < TypeDecl -- Smaller else { return -1; } } return 0; } }); return list; } eq AbstractDot.completion(String filter) = lastAccess().completion(filter); inh Collection Expr.visibleTypes(); inh Collection Expr.visibleMethods(); inh Collection TypeDecl.visibleMethods(); inh Collection Expr.visibleVariables(); eq Program.getChild().visibleTypes() = Collections.EMPTY_LIST; eq Program.getChild().visibleMethods() = Collections.EMPTY_LIST; eq Program.getChild().visibleVariables() = Collections.EMPTY_LIST; eq TypeDecl.getBodyDecl().visibleMethods() { Collection c = new ArrayList(); for(Iterator iter = methodsNameMap().values().iterator(); iter.hasNext(); ) { Collection methods = (Collection)iter.next(); for(Iterator i2 = methods.iterator(); i2.hasNext(); ) { MethodDecl m = (MethodDecl)i2.next(); if(!m.isSynthetic()) c.add(m); } } for(Iterator iter = visibleMethods().iterator(); iter.hasNext(); ) { MethodDecl m = (MethodDecl)iter.next(); if(!m.isSynthetic() && (!methodsNameMap().containsKey(m.name()) || ((Collection)methodsNameMap().get(m.name())).isEmpty())) c.add(m); } return c; } eq AbstractDot.getRight().visibleMethods() { Collection c = new ArrayList(); for(Iterator iter = getLeft().type().methodsNameMap().values().iterator(); iter.hasNext(); ) { Collection methods = (Collection)iter.next(); for(Iterator i2 = methods.iterator(); i2.hasNext(); ) { MethodDecl m = (MethodDecl)i2.next(); if(!m.isSynthetic()) c.add(m); } } return c; } eq AbstractDot.getRight().visibleVariables() = getLeft().type().fields(); eq AbstractDot.getRight().visibleTypes() = getLeft().type().types(); syn Collection TypeDecl.fields() { Collection c = new ArrayList(); for(Iterator iter = localFieldsMap().values().iterator(); iter.hasNext(); ) { SimpleSet set = (SimpleSet)iter.next(); for(Iterator i2 = set.iterator(); i2.hasNext(); ) { FieldDeclaration f = (FieldDeclaration)i2.next(); if(!f.isSynthetic()) c.add(f); } } return c; } eq ClassDecl.fields() { Collection c = super.fields(); if(hasSuperclass()) { for(Iterator iter = superclass().fields().iterator(); iter.hasNext(); ) { Variable v = (Variable)iter.next(); if(!memberFields(v.name()).contains(v) && !v.isSynthetic()) c.add(v); } } for(Iterator outerIter = interfacesIterator(); outerIter.hasNext(); ) { TypeDecl type = (TypeDecl)outerIter.next(); for(Iterator iter = type.fields().iterator(); iter.hasNext(); ) { Variable v = (Variable)iter.next(); if(!memberFields(v.name()).contains(v) && !v.isSynthetic()) c.add(v); } } return c; } eq InterfaceDecl.fields() { Collection c = super.fields(); for(Iterator outerIter = superinterfacesIterator(); outerIter.hasNext(); ) { TypeDecl type = (TypeDecl)outerIter.next(); for(Iterator iter = type.fields().iterator(); iter.hasNext(); ) { Variable v = (Variable)iter.next(); if(!memberFields(v.name()).contains(v) && !v.isSynthetic()) c.add(v); } } return c; } syn Collection TypeDecl.types() = Collections.EMPTY_SET; eq ClassDecl.types() { Collection c = new ArrayList(); for(int i = 0; i < getNumBodyDecl(); i++) { if(getBodyDecl(i) instanceof MemberTypeDecl) { TypeDecl typeDecl = ((MemberTypeDecl)getBodyDecl(i)).typeDecl(); if(!typeDecl.isSynthetic()) c.add(typeDecl); } } for(Iterator outerIter = interfacesIterator(); outerIter.hasNext(); ) { TypeDecl type = (TypeDecl)outerIter.next(); for(Iterator iter = type.types().iterator(); iter.hasNext(); ) { TypeDecl decl = (TypeDecl)iter.next(); if(memberTypes(decl.name()).contains(decl) && !decl.isSynthetic()) c.add(decl); } } if(hasSuperclass()) { for(Iterator iter = superclass().types().iterator(); iter.hasNext(); ) { TypeDecl decl = (TypeDecl)iter.next(); if(memberTypes(decl.name()).contains(decl) && !decl.isSynthetic()) c.add(decl); } } return c; } eq InterfaceDecl.types() { Collection c = new ArrayList(); for(int i = 0; i < getNumBodyDecl(); i++) { if(getBodyDecl(i) instanceof MemberTypeDecl) { TypeDecl typeDecl = ((MemberTypeDecl)getBodyDecl(i)).typeDecl(); if(!typeDecl.isSynthetic()) c.add(typeDecl); } } for(Iterator outerIter = superinterfacesIterator(); outerIter.hasNext(); ) { TypeDecl type = (TypeDecl)outerIter.next(); for(Iterator iter = type.types().iterator(); iter.hasNext(); ) { TypeDecl decl = (TypeDecl)iter.next(); if(memberTypes(decl.name()).contains(decl) && !decl.isSynthetic()) c.add(decl); } } return c; } //inh NameType Access.nameType(); syn boolean Access.showMethods() = nameType() != NameType.TYPE_NAME && nameType() != NameType.PACKAGE_NAME && nameType() != NameType.PACKAGE_OR_TYPE_NAME; syn boolean Access.showVariables() = nameType() != NameType.TYPE_NAME && nameType() != NameType.PACKAGE_NAME && nameType() != NameType.PACKAGE_OR_TYPE_NAME; syn boolean Access.showTypes() = !isQualified() ? nameType() != NameType.EXPRESSION_NAME : qualifier().isTypeAccess(); // methods, types, variables syn Collection Access.visibleDecls() { Collection c = new ArrayList(); if(showMethods()) for(Iterator iter = visibleMethods().iterator(); iter.hasNext(); ) { MethodDecl m = (MethodDecl)iter.next(); // protection boolean accessible = true; if(!m.accessibleFrom(hostType())) accessible = false; if(isQualified()) { if(!qualifier().type().accessibleFrom(hostType())) accessible = false; if(accessible && m.isProtected() && !m.hostPackage().equals(hostPackage()) && !m.isStatic() && !qualifier().isSuperAccess()) { TypeDecl C = m.hostType(); TypeDecl S = hostType().subclassWithinBody(C); TypeDecl Q = qualifier().type(); if(S == null || !Q.instanceOf(S)) accessible = false; } } // static context boolean staticContext = isQualified() ? qualifier().staticContextQualifier() : inStaticContext(); if(accessible && (!staticContext || m.isStatic())) { c.add(m); } } if(showVariables()) for(Iterator iter = visibleVariables().iterator(); iter.hasNext(); ) { Variable v = (Variable)iter.next(); if(v instanceof FieldDeclaration) { FieldDeclaration f = (FieldDeclaration)v; // protection if(f.accessibleFrom(hostType())) { // static context boolean staticContext = isQualified() ? qualifier().staticContextQualifier() : inStaticContext(); if(!staticContext || f.isStatic()) { c.add(f); } } } else c.add(v); } if(showTypes()) for(Iterator iter = visibleTypes().iterator(); iter.hasNext(); ) { TypeDecl t = (TypeDecl)iter.next(); if(t.accessibleFrom(hostType())) { c.add(t); } } return c; } }